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