Proyectos de Subversion LeadersLinked - Backend

Rev

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