Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

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