Proyectos de Subversion LeadersLinked - Backend

Rev

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

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