Proyectos de Subversion LeadersLinked - Backend

Rev

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

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