Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
1 www 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/programs/add');
8
$routeDatatable = $this->url('microlearning/settings/programs');
9
$routeDashboard = $this->url('dashboard');
10
 
11
$allowAdd               = $acl->isAllowed($roleName, 'microlearning/settings/programs/add') ? 1 : 0;
12
$allowEdit              = $acl->isAllowed($roleName, 'microlearning/settings/programs/edit') ? 1 : 0;
13
$allowDelete            = $acl->isAllowed($roleName, 'microlearning/settings/programs/delete') ? 1 : 0;
14
 
15
 
16822 efrain 16
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-input-number/input-number-format.jquery.min.js'));
1 www 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'));
1 www 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'));
1 www 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'));
1 www 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'));
1 www 33
 
34
 
35
 
36
 
16822 efrain 37
 
38
 
1 www 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
 
1 www 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;';
1 www 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
 
1 www 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
 
1 www 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
 
278
 
279
        $('body').on('click', 'button.btn-cancel', function(e) {
280
            e.preventDefault();
281
            $('#modal').modal('hide');
282
        });
283
 
16822 efrain 284
    $('body').on('click', 'button.btn-delete', function(e) {
285
        e.preventDefault();
286
        var action = $(this).data('href');
1 www 287
 
16822 efrain 288
 
289
          swal.fire({
290
            title: 'LABEL_ARE_YOU_SURE',
291
            icon: 'question',
292
            cancelButtonText: 'LABEL_NO',
293
            showCancelButton: true,
294
            confirmButtonText: 'LABEL_YES'
295
          }).then((result) => {
296
            if (result.isConfirmed) {
297
 
298
                    NProgress.start();
299
                    $.ajax({
300
                        'dataType'  : 'json',
301
                        'accept'    : 'application/json',
302
                        'method'    : 'post',
303
                        'url'       :  action,
304
                    }).done(function(response) {
305
                        if(response['success']) {
306
                            $.fn.showSuccess(response['data']);
307
                            gridTable.api().ajax.reload(null, false);
308
                        } else {
309
                            $.fn.showError(response['data']);
310
                        }
311
                    }).fail(function( jqXHR, textStatus, errorThrown) {
312
                        $.fn.showError(textStatus);
313
                    }).always(function() {
314
                        NProgress.done();
315
                    });
316
                }
317
           });
318
        });
319
 
1 www 320
    });
321
JS;
322
$this->inlineScript()->captureEnd();
323
?>
324
 
16891 efrain 325
 
326
<div class="container">
327
	<div class="card" id="">
328
	 	<div class="card-header">
329
	 		<h6 class="card-title">LABEL_PROGRAMS</h6>
330
	 	</div>
331
	 	<div class="card-body">
332
	 		<div class="row">
333
	 	         <div class="col-12 mt-3">
334
 
335
	 	         <table id="gridTable" class="table   table-bordered">
1 www 336
                      		<thead>
337
        						<tr>
338
                                	<th>LABEL_NAME</th>
339
                                  	<th>LABEL_ACTIONS</th>
340
                                </tr>
341
                       		</thead>
342
                         	<tbody>
343
                         	</tbody>
344
                    	</table>
16891 efrain 345
 
346
	 	         </div>
347
	 	     </div>
348
	 	</div>
349
	 	<div class="card-footer text-right">
350
	 	     <?php if($allowAdd) : ?>
1 www 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
 
354
	 	</div>
355
	</div>
356
</div>
357
 
1 www 358
 
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_PROGRAMS</h6>
16822 efrain 367
        		<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
1 www 368
      		</div>
369
 
16891 efrain 370
 <?php
1 www 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
      		<div class="modal-body">
382
 
383
    					<div class="row">
384
    						<div class="col-12 mt-3">
1 www 385
        					<?php
386
                            $element = $form->get('name');
387
                            $element->setOptions(['label' => 'LABEL_NAME']);
388
                            $element->setAttributes(['class' => 'form-control']);
389
 
390
                            echo $this->formLabel($element);
391
                            echo $this->formText($element);
392
                            ?>
16891 efrain 393
                            </div>
1 www 394
						</div>
395
 
16891 efrain 396
 
397
 
1 www 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>
1 www 404
      		</div>
16891 efrain 405
      		<?php echo $this->form()->closeTag($form); ?>
1 www 406
 
407
    	</div>
408
	</div>
409
</div>
410
 
411
 
412
 
413
 
414
 
415