Proyectos de Subversion LeadersLinked - Backend

Rev

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