Proyectos de Subversion LeadersLinked - Backend

Rev

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

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