Completed
Push — master ( ef4035...1a8d3e )
by Arjay
13:24 queued 11s
created

Button::align()   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;
4
5
use Illuminate\Support\Fluent;
6
use Illuminate\Contracts\Support\Arrayable;
7
8
class Button extends Fluent implements Arrayable
9
{
10
    use HasAuthorizations;
11
12
    /**
13
     * Make a new button instance.
14
     *
15
     * @param string|array $options
16
     * @return static
17
     */
18 View Code Duplication
    public static function make($options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        if (is_string($options)) {
21
            return new static(['extend' => $options]);
22
        }
23
24
        return new static($options);
25
    }
26
27
    /**
28
     * Make a raw button that does not extend anything.
29
     *
30
     * @param array $options
31
     * @return static
32
     */
33 View Code Duplication
    public static function raw($options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        if (is_string($options)) {
36
            return new static(['text' => $options]);
37
        }
38
39
        return new static($options);
40
    }
41
42
    /**
43
     * Set extend option value.
44
     *
45
     * @param string $value
46
     * @return $this
47
     */
48
    public function extend($value)
49
    {
50
        $this->attributes['extend'] = $value;
51
52
        return $this;
53
    }
54
55
    /**
56
     * Set editor option value.
57
     *
58
     * @param string $value
59
     * @return $this
60
     */
61
    public function editor($value)
62
    {
63
        $this->attributes['editor'] = $value;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param array $buttons
70
     * @return $this
71
     */
72 View Code Duplication
    public function buttons(array $buttons)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        foreach ($buttons as $key => $button) {
75
            if ($button instanceof Arrayable) {
76
                $buttons[$key] = $button->toArray();
77
            }
78
        }
79
80
        $this->attributes['buttons'] = $buttons;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @param array $buttons
87
     * @return $this
88
     * @see https://editor.datatables.net/examples/api/cancelButton
89
     */
90 View Code Duplication
    public function formButtons(array $buttons)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        foreach ($buttons as $key => $button) {
93
            if ($button instanceof Arrayable) {
94
                $buttons[$key] = $button->toArray();
95
            }
96
        }
97
98
        $this->attributes['formButtons'] = $buttons;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @param mixed $message
105
     * @return $this
106
     * @see https://editor.datatables.net/examples/api/removeMessage
107
     * @see https://editor.datatables.net/reference/button/create
108
     * @see https://editor.datatables.net/reference/button/edit
109
     * @see https://editor.datatables.net/reference/button/remove
110
     */
111
    public function formMessage($message)
112
    {
113
        $this->attributes['formMessage'] = $message;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @param mixed $title
120
     * @return $this
121
     * @see https://editor.datatables.net/reference/button/create
122
     * @see https://editor.datatables.net/reference/button/edit
123
     * @see https://editor.datatables.net/reference/button/remove
124
     */
125
    public function formTitle($title)
126
    {
127
        $this->attributes['formTitle'] = $title;
128
129
        return $this;
130
    }
131
132
    /**
133
     * Set className option value.
134
     *
135
     * @param string $value
136
     * @return $this
137
     */
138
    public function className($value)
139
    {
140
        $this->attributes['className'] = $value;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Set customize option value.
147
     *
148
     * @param string $value
149
     * @return $this
150
     * @see https://datatables.net/reference/button/excelHtml5
151
     */
152
    public function customize($value)
153
    {
154
        $this->attributes['customize'] = $value;
155
156
        return $this;
157
    }
158
159
    /**
160
     * Append a class name to column.
161
     *
162
     * @param string $class
163
     * @return $this
164
     */
165 View Code Duplication
    public function addClass($class)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
    {
167
        if (! isset($this->attributes['className'])) {
168
            $this->attributes['className'] = $class;
169
        } else {
170
            $this->attributes['className'] .= " $class";
171
        }
172
173
        return $this;
174
    }
175
176
    /**
177
     * Set text option value.
178
     *
179
     * @param string $value
180
     * @return $this
181
     */
182
    public function text($value)
183
    {
184
        $this->attributes['text'] = $value;
185
186
        return $this;
187
    }
188
189
    /**
190
     * Set name option value.
191
     *
192
     * @param string $value
193
     * @return $this
194
     */
195
    public function name($value)
196
    {
197
        $this->attributes['name'] = $value;
198
199
        return $this;
200
    }
201
202
    /**
203
     * Set columns option value.
204
     *
205
     * @param mixed $value
206
     * @return $this
207
     */
208
    public function columns($value)
209
    {
210
        $this->attributes['columns'] = $value;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Set exportOptions option value.
217
     *
218
     * @param mixed $value
219
     * @return $this
220
     */
221
    public function exportOptions($value)
222
    {
223
        $this->attributes['exportOptions'] = $value;
224
225
        return $this;
226
    }
227
228
    /**
229
     * Set action to submit the form.
230
     *
231
     * @return \Yajra\DataTables\Html\Button
232
     */
233
    public function actionSubmit()
234
    {
235
        $this->attributes['action'] = 'function() { this.submit(); }';
236
237
        return $this;
238
    }
239
240
    /**
241
     * Set action option value.
242
     *
243
     * @param string $value
244
     * @return $this
245
     */
246
    public function action($value)
247
    {
248
        if (substr($value, 0, 8) == 'function') {
249
            $this->attributes['action'] = $value;
250
        } else {
251
            $this->attributes['action'] = "function(e, dt, node, config) { $value }";
252
        }
253
254
        return $this;
255
    }
256
257
    /**
258
     * Set editor class action handler.
259
     *
260
     * @param string $action
261
     * @return \Yajra\DataTables\Html\Button
262
     */
263
    public function actionHandler($action)
264
    {
265
        $this->attributes['action'] = "function() { this.submit(null, null, function(data) { data.action = '{$action}'; return data; }) }";
266
267
        return $this;
268
    }
269
270
    /**
271
     * Set action to close the form.
272
     *
273
     * @return \Yajra\DataTables\Html\Button
274
     */
275
    public function actionClose()
276
    {
277
        $this->attributes['action'] = 'function() { this.close(); }';
278
279
        return $this;
280
    }
281
282
    /**
283
     * Set button alignment.
284
     *
285
     * @param string $align
286
     * @return \Yajra\DataTables\Html\Button
287
     */
288
    public function align($align = 'button-left')
289
    {
290
        $this->attributes['align'] = $align;
291
292
        return $this;
293
    }
294
}
295