Completed
Push — master ( 7d5060...e81a80 )
by Arjay
01:43 queued 10s
created

File::dragDrop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html\Editor\Fields;
4
5
/**
6
 * @see https://editor.datatables.net/reference/field/upload
7
 * @see https://editor.datatables.net/examples/advanced/upload.html
8
 * @see https://editor.datatables.net/examples/advanced/upload-many.html
9
 */
10
class File extends Field
11
{
12
    protected $type = 'upload';
13
14
    /**
15
     * Editor instance.
16
     *
17
     * @var string
18
     */
19
    protected $editor = 'editor';
20
21
    /**
22
     * @param string $name
23
     * @param string $label
24
     * @return static|\Yajra\DataTables\Html\Editor\Fields\Field
25
     */
26
    public static function make($name, $label = '')
27
    {
28
        /** @var \Yajra\DataTables\Html\Editor\Fields\File $field */
29
        $field = parent::make($name, $label);
30
31
        return $field->displayFile()->clearText()->noImageText();
32
    }
33
34
    /**
35
     * @param string $value
36
     * @return $this
37
     */
38
    public function ajax($value)
39
    {
40
        $this->attributes['ajax'] = $value;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @param string $value
47
     * @return $this
48
     */
49
    public function ajaxData($value)
50
    {
51
        $this->attributes['ajaxData'] = $value;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @param bool $value
58
     * @return $this
59
     */
60
    public function dragDrop($value = true)
61
    {
62
        $this->attributes['dragDrop'] = $value;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param string $value
69
     * @return $this
70
     */
71
    public function dragDropText($value)
72
    {
73
        $this->attributes['dragDropText'] = $value;
74
75
        return $this;
76
    }
77
78
    /**
79
     * @param string $value
80
     * @return $this
81
     */
82
    public function fileReadText($value)
83
    {
84
        $this->attributes['fileReadText'] = $value;
85
86
        return $this;
87
    }
88
89
    /**
90
     * @param string $value
91
     * @return $this
92
     */
93
    public function noFileText($value)
94
    {
95
        $this->attributes['noFileText'] = $value;
96
97
        return $this;
98
    }
99
100
    /**
101
     * @param string $value
102
     * @return $this
103
     */
104
    public function processingText($value)
105
    {
106
        $this->attributes['processingText'] = $value;
107
108
        return $this;
109
    }
110
111
    /**
112
     * @param string $value
113
     * @return $this
114
     */
115
    public function uploadText($value)
116
    {
117
        $this->attributes['uploadText'] = $value;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Set editor instance for file upload.
124
     *
125
     * @param string $editor
126
     * @return $this
127
     */
128
    public function editor($editor)
129
    {
130
        $this->editor = $editor;
131
132
        return $this;
133
    }
134
135
    /**
136
     * Display image upon upload.
137
     *
138
     * @return $this
139
     */
140
    public function displayImage()
141
    {
142
        return $this->display("function (file_id) { return file_id ? '<img src=\"storage/' + file_id + '\"/>' : null; }");
143
    }
144
145
    /**
146
     * @param string $value
147
     * @return $this
148
     */
149
    public function display($value)
150
    {
151
        $this->attributes['display'] = $value;
152
153
        return $this;
154
    }
155
156
    /**
157
     * Display the file path.
158
     *
159
     * @return $this
160
     */
161
    public function displayFile()
162
    {
163
        return $this->display("function (file_id) { return file_id; }");
164
    }
165
166
    /**
167
     * @param string $value
168
     * @return $this
169
     */
170
    public function clearText($value = 'Clear')
171
    {
172
        $this->attributes['clearText'] = $value;
173
174
        return $this;
175
    }
176
177
    /**
178
     * @param string $value
179
     * @return $this
180
     */
181
    public function noImageText($value = 'No image')
182
    {
183
        $this->attributes['noImageText'] = $value;
184
185
        return $this;
186
    }
187
188
    /**
189
     * @param bool $state
190
     * @return $this
191
     */
192
    public function multiple($state = true)
193
    {
194
        if ($state) {
195
            $this->type('uploadMany');
196
        }
197
198
        return $this;
199
    }
200
}
201