Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17003 | Rev 17247 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
17003 efrain 1
<?php
2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
7
 
8
$routeAdd       = $this->url('media/categories/add');
9
$routeDatatable = $this->url('media/categories');
10
$routeDashboard = $this->url('dashboard');
11
 
12
$allowAdd               = $acl->isAllowed($roleName, 'media/categories/add') ? 1 : 0;
13
$allowEdit              = $acl->isAllowed($roleName, 'media/categories/edit') ? 1 : 0;
14
$allowDelete            = $acl->isAllowed($roleName, 'media/categories/delete') ? 1 : 0;
15
 
16
 
17
 
18
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
19
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
20
 
21
 
22
 
23
 
24
 
25
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
26
 
27
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
28
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));
29
 
30
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
31
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
32
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
33
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));
34
 
35
 
36
 
37
 
38
$this->inlineScript()->captureStart();
39
echo <<<JS
40
    jQuery( document ).ready(function( $ ) {
41
 
42
 
43
 
44
 
45
        var allowEdit   = $allowEdit;
46
        var allowDelete = $allowDelete;
47
 
48
        var gridTable = $('#gridTable').dataTable( {
49
            'processing': true,
50
            'serverSide': true,
51
            'searching': true,
52
            'order': [[ 0, 'asc' ]],
53
            'ordering':  true,
54
            'ordenable' : true,
55
            'responsive': true,
56
            'select' : false,
57
        	'paging': true,
58
            'pagingType': 'simple_numbers',
59
    		'ajax': {
60
    			'url' : '$routeDatatable',
61
    			'type' : 'get',
62
                'beforeSend': function (request) {
63
                  NProgress.start();
64
                },
65
                'dataFilter': function(response) {
17246 ariadna 66
                    var response = JSON.parse(response);
67
                    console.log(response);
17003 efrain 68
 
69
                    var json                = {};
70
                    json.recordsTotal       = 0;
71
                    json.recordsFiltered    = 0;
72
                    json.data               = [];
73
 
74
 
75
                    if(response.success) {
76
                        json.recordsTotal       = response.data.total;
77
                        json.recordsFiltered    = response.data.total;
78
                        json.data               = response.data.items;
79
                    } else {
80
                        $.fn.showError(response.data)
81
                    }
82
 
83
                    return JSON.stringify( json );
84
                }
85
    		},
86
            'language' : {
87
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
88
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
89
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
90
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
91
                'sInfo':           'LABEL_DATATABLE_SINFO',
92
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
93
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
94
                'sInfoPostFix':    '',
95
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
96
                'sUrl':            '',
97
                'sInfoThousands':  ',',
98
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
99
                'oPaginate': {
100
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
101
                    'sLast':     'LABEL_DATATABLE_SLAST',
102
                    'sNext':     'LABEL_DATATABLE_SNEXT',
103
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
104
                },
105
                'oAria': {
106
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
107
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
108
                },
109
            },
110
            'drawCallback': function( settings ) {
111
                NProgress.done();
112
 
113
            },
114
            'aoColumns': [
115
                { 'mDataProp': 'name' },
116
                { 'mDataProp': 'actions' },
117
    	    ],
118
            'columnDefs': [
119
                {
120
                    'targets': 0,
121
                    'className' : 'text-vertical-middle',
122
                },
123
 
124
                {
125
                    'targets': -1,
126
                    'orderable': false,
127
                    'render' : function ( data, type, row ) {
128
                        s = '';
129
 
130
                        if(allowEdit) {
131
                            s = s + '<button class="btn btn-primary btn-edit" data-href="' + data['link_edit']+ '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pen"></i> LABEL_EDIT </button>&nbsp;';
132
                        }
133
                        if(allowDelete) {
134
                            s = s + '<button class="btn btn-danger btn-delete" data-href="' + data['link_delete']+ '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
135
                        }
136
                        return s;
137
                    }
138
                }
139
              ],
140
        });
141
 
142
 
143
        var validator = $('#form').validate({
144
            debug: true,
145
            onclick: false,
146
            onkeyup: false,
147
            ignore: [],
148
            rules: {
149
                'name': {
150
                    required: true,
151
                    maxlength: 100,
152
                }
153
            },
154
            submitHandler: function(form)
155
            {
156
                $.ajax({
157
                    'dataType'  : 'json',
158
                    'accept'    : 'application/json',
159
                    'method'    : 'post',
160
                    'url'       :  $('#form').attr('action'),
161
                    'data'      :  $('#form').serialize()
162
                }).done(function(response) {
163
                    NProgress.start();
164
                    if(response['success']) {
165
                        $.fn.showSuccess(response['data']);
166
 
167
                        $('#modal').modal('hide');
168
 
169
 
170
                         gridTable.api().ajax.reload(null, false);
171
                    } else {
172
                        validator.resetForm();
173
                        if(jQuery.type(response['data']) == 'string') {
174
                            $.fn.showError(response['data']);
175
                        } else  {
176
                            $.each(response['data'], function( fieldname, errors ) {
177
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
178
                            });
179
                        }
180
                    }
181
                }).fail(function( jqXHR, textStatus, errorThrown) {
182
                   $.fn.showError(textStatus);
183
                }).always(function() {
184
                    NProgress.done();
185
                });
186
                return false;
187
            },
188
            invalidHandler: function(form, validator) {
189
 
190
            }
191
        });
192
 
193
        $('body').on('click', 'button.btn-add', function(e) {
194
            e.preventDefault();
195
 
196
 
197
            $('#form').attr('action', '$routeAdd');
198
            $('#form #name').val('');
199
 
200
 
201
            validator.resetForm();
202
            $('#modal').modal('show');
203
        });
204
 
205
        $('body').on('click', 'button.btn-edit', function(e) {
206
            e.preventDefault();
207
            NProgress.start();
208
            var action = $(this).data('href');
209
 
210
            $.ajax({
211
                'dataType'  : 'json',
212
                'accept'    : 'application/json',
213
                'method'    : 'get',
214
                'url'       :  action,
215
            }).done(function(response) {
216
                if(response['success']) {
217
 
218
 
219
                    $('#form').attr('action', action);
220
                    $('#form #name').val(response['data']['name']);
221
 
222
                    validator.resetForm();
223
 
224
                    $('#modal').modal('show');
225
                } else {
226
                    $.fn.showError(response['data']);
227
                }
228
            }).fail(function( jqXHR, textStatus, errorThrown) {
229
                $.fn.showError(textStatus);
230
            }).always(function() {
231
                NProgress.done();
232
            });
233
        });
234
 
235
    $('body').on('click', 'button.btn-delete', function(e) {
236
        e.preventDefault();
237
        var action = $(this).data('href');
238
 
239
 
240
          swal.fire({
241
            title: 'LABEL_ARE_YOU_SURE',
242
            icon: 'question',
243
            cancelButtonText: 'LABEL_NO',
244
            showCancelButton: true,
245
            confirmButtonText: 'LABEL_YES'
246
          }).then((result) => {
247
            if (result.isConfirmed) {
248
 
249
                    NProgress.start();
250
                    $.ajax({
251
                        'dataType'  : 'json',
252
                        'accept'    : 'application/json',
253
                        'method'    : 'post',
254
                        'url'       :  action,
255
                    }).done(function(response) {
256
                        if(response['success']) {
257
                            $.fn.showSuccess(response['data']);
258
                            gridTable.api().ajax.reload(null, false);
259
                        } else {
260
                            $.fn.showError(response['data']);
261
                        }
262
                    }).fail(function( jqXHR, textStatus, errorThrown) {
263
                        $.fn.showError(textStatus);
264
                    }).always(function() {
265
                        NProgress.done();
266
                    });
267
                }
268
           });
269
 
270
        });
271
 
272
        $('body').on('click', 'button.btn-refresh', function(e) {
273
            e.preventDefault();
274
            gridTable.api().ajax.reload(null, false);
275
        });
276
 
277
 
278
        $('body').on('click', 'button.btn-cancel', function(e) {
279
            e.preventDefault();
280
            $('#modal').modal('hide');
281
        });
282
 
283
 
284
    });
285
JS;
286
$this->inlineScript()->captureEnd();
287
?>
288
 
17246 ariadna 289
 
290
 
17003 efrain 291
<div class="container">
17246 ariadna 292
    <div class="row">
293
        <div class="col-12 mt-3">
294
            <div class="card">
295
 
296
                <div class="card-body">
297
                    <h6 class="card-title">LABEL_MEDIA_CATEGORIES</h6>
298
                    <div class="row">
299
                        <div class="col-12  mt-3">
300
                            <table id="gridTable" class="table   table-bordered">
301
                                <thead>
302
                                    <tr>
303
                                        <th>LABEL_NAME</th>
304
                                        <th>LABEL_ACTIONS</th>
305
                                    </tr>
306
                                </thead>
307
                                <tbody>
308
                                </tbody>
309
                            </table>
310
                        </div>
311
                    </div>
312
 
313
                </div>
314
                <div class="card-footer text-right">
315
 
316
                    <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH </button>
317
                    <?php if ($allowAdd) : ?>
318
                        <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
319
                    <?php endif; ?>
320
 
321
                </div>
322
            </div>
323
        </div>
324
    </div>
17003 efrain 325
</div>
326
 
327
<!-- The Modal -->
328
<div class="modal" id="modal">
17246 ariadna 329
    <div class="modal-dialog  modal-lg">
330
        <div class="modal-content">
17003 efrain 331
 
332
            <!-- Modal Header -->
17246 ariadna 333
            <div class="modal-header">
334
                <h6 class="modal-title">LABEL_CATEGORIES</h6>
335
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
336
            </div>
17003 efrain 337
 
17246 ariadna 338
            <?php
339
            $form = $this->form;
340
            $form->setAttributes([
341
                'method'    => 'post',
342
                'name'      => 'form',
343
                'id'        => 'form'
344
            ]);
345
 
346
            $form->prepare();
347
            echo $this->form()->openTag($form);
348
            ?>
349
 
17003 efrain 350
            <!-- Modal body -->
17246 ariadna 351
            <div class="modal-body">
17003 efrain 352
 
17246 ariadna 353
                <div class="row">
354
                    <div class="col  mt-3">
355
                        <?php
356
                        $element = $form->get('name');
357
                        $element->setOptions(['label' => 'LABEL_NAME']);
358
                        $element->setAttributes(['class' => 'form-control']);
17003 efrain 359
 
17246 ariadna 360
                        echo $this->formLabel($element);
361
                        echo $this->formText($element);
362
                        ?>
363
                    </div>
364
                </div>
17003 efrain 365
 
366
 
17246 ariadna 367
            </div>
17003 efrain 368
 
17246 ariadna 369
            <!-- Modal footer -->
370
            <div class="modal-footer text-right">
371
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
372
                <button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
373
            </div>
374
            <?php echo $this->form()->closeTag($form); ?>
17003 efrain 375
 
17246 ariadna 376
        </div>
377
    </div>
378
</div>