Code Duplication    Length = 51-55 lines in 2 locations

src/Grid/Tools/BatchDelete.php 1 location

@@ 15-65 (lines=51) @@
12
    /**
13
     * Script of batch delete action.
14
     */
15
    public function script()
16
    {
17
        $trans = [
18
            'delete_confirm' => trans('admin.delete_confirm'),
19
            'confirm'        => trans('admin.confirm'),
20
            'cancel'         => trans('admin.cancel'),
21
        ];
22
23
        return <<<EOT
24
25
$('{$this->getElementClass()}').on('click', function() {
26
27
    swal({
28
        title: "{$trans['delete_confirm']}",
29
        type: "warning",
30
        showCancelButton: true,
31
        confirmButtonColor: "#DD6B55",
32
        confirmButtonText: "{$trans['confirm']}",
33
        showLoaderOnConfirm: true,
34
        cancelButtonText: "{$trans['cancel']}",
35
        preConfirm: function() {
36
            return new Promise(function(resolve) {
37
                $.ajax({
38
                    method: 'post',
39
                    url: '{$this->resource}/' + $.admin.grid.selected().join(),
40
                    data: {
41
                        _method:'delete',
42
                        _token:'{$this->getToken()}'
43
                    },
44
                    success: function (data) {
45
                        $.pjax.reload('#pjax-container');
46
47
                        resolve(data);
48
                    }
49
                });
50
            });
51
        }
52
    }).then(function(result) {
53
        var data = result.value;
54
        if (typeof data === 'object') {
55
            if (data.status) {
56
                swal(data.message, '', 'success');
57
            } else {
58
                swal(data.message, '', 'error');
59
            }
60
        }
61
    });
62
});
63
64
EOT;
65
    }
66
}
67

src/Grid/Displayers/Actions.php 1 location

@@ 229-283 (lines=55) @@
226
EOT;
227
    }
228
229
    protected function setupDeleteScript()
230
    {
231
        $trans = [
232
            'delete_confirm' => trans('admin.delete_confirm'),
233
            'confirm'        => trans('admin.confirm'),
234
            'cancel'         => trans('admin.cancel'),
235
        ];
236
237
        $script = <<<SCRIPT
238
239
$('.{$this->grid->getGridRowName()}-delete').unbind('click').click(function() {
240
241
    var id = $(this).data('id');
242
243
    swal({
244
        title: "{$trans['delete_confirm']}",
245
        type: "warning",
246
        showCancelButton: true,
247
        confirmButtonColor: "#DD6B55",
248
        confirmButtonText: "{$trans['confirm']}",
249
        showLoaderOnConfirm: true,
250
        cancelButtonText: "{$trans['cancel']}",
251
        preConfirm: function() {
252
            return new Promise(function(resolve) {
253
                $.ajax({
254
                    method: 'post',
255
                    url: '{$this->getResource()}/' + id,
256
                    data: {
257
                        _method:'delete',
258
                        _token:LA.token,
259
                    },
260
                    success: function (data) {
261
                        $.pjax.reload('#pjax-container');
262
263
                        resolve(data);
264
                    }
265
                });
266
            });
267
        }
268
    }).then(function(result) {
269
        var data = result.value;
270
        if (typeof data === 'object') {
271
            if (data.status) {
272
                swal(data.message, '', 'success');
273
            } else {
274
                swal(data.message, '', 'error');
275
            }
276
        }
277
    });
278
});
279
280
SCRIPT;
281
282
        Admin::script($script);
283
    }
284
}
285