Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17252 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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