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
16822 efrain 1
<?php
1 www 2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
16822 efrain 7
 
1 www 8
$routeAdd       = $this->url('settings/degrees/add');
9
$routeDatatable = $this->url('settings/degrees');
10
$routeDashboard = $this->url('dashboard');
11
 
12
$allowAdd               = $acl->isAllowed($roleName, 'settings/degrees/add') ? 1 : 0;
13
$allowEdit              = $acl->isAllowed($roleName, 'settings/degrees/edit') ? 1 : 0;
14
$allowDelete            = $acl->isAllowed($roleName, 'settings/degrees/delete') ? 1 : 0;
15
 
16830 efrain 16
$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));
16822 efrain 17
 
1 www 18
 
16822 efrain 19
 
16829 efrain 20
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
21
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
16822 efrain 22
 
16829 efrain 23
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-maxlenght/bootstrap-maxlength.js'));
16822 efrain 24
 
16829 efrain 25
 
26
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/jquery.validate.js'));
27
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/additional-methods.js'));
28
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/localization/messages_es.js'));
29
 
16822 efrain 30
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
31
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));
32
 
33
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
34
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
35
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
36
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));
37
 
38
 
16829 efrain 39
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
40
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
16822 efrain 41
 
1 www 42
 
16822 efrain 43
 
44
 
45
 
46
$status_active = \LeadersLinked\Model\Degree::STATUS_ACTIVE;
47
 
48
$this->inlineScript()->captureStart();
49
echo <<<JS
50
    jQuery( document ).ready(function( $ ) {
51
 
52
        $.validator.setDefaults({
53
            debug: true,
54
            highlight: function(element) {
55
                $(element).addClass('is-invalid');
56
            },
57
            unhighlight: function(element) {
58
                $(element).removeClass('is-invalid');
59
            },
60
            errorElement: 'span',
61
            errorClass: 'error invalid-feedback',
62
            errorPlacement: function(error, element) {
63
                if(element.parent('.form-group').length) {
64
                    error.insertAfter(element);
65
                } else if(element.parent('.toggle').length) {
66
                    error.insertAfter(element.parent().parent());
67
                } else {
68
                    error.insertAfter(element.parent());
69
                }
70
            }
71
        });
72
 
73
 
74
        $.fn.showFormErrorValidator = function(fieldname, errors) {
75
            var field = $(fieldname);
76
            if(field) {
77
                $(field).addClass('is-invalid');
78
 
79
 
80
                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
81
                if(field.parent('.form-group').length) {
82
                    error.insertAfter(field);
83
                } else  if(field.parent('.toggle').length) {
84
                    error.insertAfter(field.parent().parent());
85
                } else {
86
                    error.insertAfter(field.parent());
87
                }
88
            }
89
        };
90
 
91
 
92
 
93
 
94
        var allowEdit   = $allowEdit;
95
        var allowDelete = $allowDelete;
96
 
97
        var gridTable = $('#gridTable').dataTable( {
98
            'processing': true,
99
            'serverSide': true,
100
            'searching': true,
101
            'order': [[ 0, 'asc' ]],
102
            'ordering':  true,
103
            'ordenable' : true,
104
            'responsive': true,
105
            'select' : false,
106
        	'paging': true,
107
            'pagingType': 'simple_numbers',
108
    		'ajax': {
109
    			'url' : '$routeDatatable',
110
    			'type' : 'get',
111
                'beforeSend': function (request) {
112
                  NProgress.start();
113
                },
114
                'dataFilter': function(response) {
115
                    var response = jQuery.parseJSON( response );
116
 
117
                    var json                = {};
118
                    json.recordsTotal       = 0;
119
                    json.recordsFiltered    = 0;
120
                    json.data               = [];
121
 
122
 
123
                    if(response.success) {
124
                        json.recordsTotal       = response.data.total;
125
                        json.recordsFiltered    = response.data.total;
126
                        json.data               = response.data.items;
127
                    } else {
128
                        $.fn.showError(response.data)
129
                    }
130
 
131
                    return JSON.stringify( json );
132
                }
133
    		},
134
            'language' : {
135
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
136
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
137
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
138
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
139
                'sInfo':           'LABEL_DATATABLE_SINFO',
140
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
141
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
142
                'sInfoPostFix':    '',
143
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
144
                'sUrl':            '',
145
                'sInfoThousands':  ',',
146
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
147
                'oPaginate': {
148
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
149
                    'sLast':     'LABEL_DATATABLE_SLAST',
150
                    'sNext':     'LABEL_DATATABLE_SNEXT',
151
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
152
                },
153
                'oAria': {
154
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
155
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
156
                },
157
            },
158
            'drawCallback': function( settings ) {
159
                NProgress.done();
160
 
161
            },
162
            'aoColumns': [
163
                { 'mDataProp': 'name' },
164
                { 'mDataProp': 'status' },
165
                { 'mDataProp': 'actions' },
166
    	    ],
167
            'columnDefs': [
168
                {
169
                    'targets': 0,
170
                    'className' : 'text-vertical-middle',
171
                },
172
                {
173
                    'targets': -2,
174
                    'orderable': false,
175
                    'className' : 'text-center',
176
                      'render' : function ( data, type, row ) {
177
 
178
                        checked = data == 'a'  ? 'checked' : '';
179
                        return '<div class="form-check">' +
180
                            '<input type="checkbox" class="form-check-input" disabled="" checked="' + checked + '">' +
181
                            '<label class="form-check-label" for="checkCheckedDisabled"></label></div>' ;
182
                    }
183
                },
184
                {
185
                    'targets': -1,
186
                    'orderable': false,
187
                    'render' : function ( data, type, row ) {
188
                        s = '';
189
 
190
                        if(allowEdit) {
16906 efrain 191
                            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;';
16822 efrain 192
                        }
193
                        if(allowDelete) {
194
                            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;';
195
                        }
196
                        return s;
197
                    }
198
                }
199
              ],
200
        });
201
 
202
 
203
        var validator = $('#form').validate({
204
            debug: true,
205
            onclick: false,
206
            onkeyup: false,
207
            ignore: [],
208
            rules: {
209
                'name': {
210
                    required: true,
211
                    maxlength: 64,
212
                },
213
                'description': {
214
                    updateCkeditor:function() {
215
                        CKEDITOR.instances.description.updateElement();
216
                    },
217
                    required: true,
218
                },
219
                'status': {
220
                    required: false,
221
 
222
                },
223
            },
224
            submitHandler: function(form)
225
            {
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
                });
256
                return false;
257
            },
258
            invalidHandler: function(form, validator) {
259
 
260
            }
261
        });
262
 
263
        $('body').on('click', 'button.btn-add', function(e) {
264
            e.preventDefault();
265
 
16840 efrain 266
 
16822 efrain 267
            $('#form').attr('action', '$routeAdd');
268
            $('#form #name').val('');
269
            $('#form #status').bootstrapToggle('on');
270
            CKEDITOR.instances.description.setData('');
271
 
272
            validator.resetForm();
273
            $('#modal').modal('show');
274
        });
275
 
276
        $('body').on('click', 'button.btn-edit', function(e) {
277
            e.preventDefault();
278
            NProgress.start();
279
            var action = $(this).data('href');
280
 
281
            $.ajax({
282
                'dataType'  : 'json',
283
                'accept'    : 'application/json',
284
                'method'    : 'get',
285
                'url'       :  action,
286
            }).done(function(response) {
287
                if(response['success']) {
288
 
16840 efrain 289
 
16822 efrain 290
                    $('#form').attr('action', action);
291
                    $('#form #name').val(response['data']['name']);
292
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
293
                    CKEDITOR.instances.description.setData(response['data']['description']);
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-delete', function(e) {
309
        e.preventDefault();
310
        var action = $(this).data('href');
311
 
312
 
313
          swal.fire({
314
            title: 'LABEL_ARE_YOU_SURE',
315
            icon: 'question',
316
            cancelButtonText: 'LABEL_NO',
317
            showCancelButton: true,
318
            confirmButtonText: 'LABEL_YES'
319
          }).then((result) => {
320
            if (result.isConfirmed) {
321
 
322
                    NProgress.start();
323
                    $.ajax({
324
                        'dataType'  : 'json',
325
                        'accept'    : 'application/json',
326
                        'method'    : 'post',
327
                        'url'       :  action,
328
                    }).done(function(response) {
329
                        if(response['success']) {
330
                            $.fn.showSuccess(response['data']);
331
                            gridTable.api().ajax.reload(null, false);
332
                        } else {
333
                            $.fn.showError(response['data']);
334
                        }
335
                    }).fail(function( jqXHR, textStatus, errorThrown) {
336
                        $.fn.showError(textStatus);
337
                    }).always(function() {
338
                        NProgress.done();
339
                    });
16829 efrain 340
                }
341
            });
342
        });
16822 efrain 343
 
344
        $('body').on('click', 'button.btn-refresh', function(e) {
345
            e.preventDefault();
346
            gridTable.api().ajax.reload(null, false);
347
        });
348
 
349
 
350
        $('body').on('click', 'button.btn-cancel', function(e) {
351
            e.preventDefault();
352
            $('#modal').modal('hide');
353
        });
354
 
355
 
356
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
357
        CKEDITOR.replace( 'description')
358
    });
5682 stevensc 359
JS;
16822 efrain 360
$this->inlineScript()->captureEnd();
1 www 361
?>
16822 efrain 362
 
1 www 363
 
16822 efrain 364
 
365
<div class="container">
366
    	<div class="row">
16891 efrain 367
        	<div class="col-12 mt-3">
16822 efrain 368
				<div class="card">
16829 efrain 369
 
16822 efrain 370
					<div class="card-body">
16829 efrain 371
                        <h6 class="card-title">LABEL_DEGREES</h6>
16822 efrain 372
						<div class="row">
16841 efrain 373
							<div class="col-12  mt-3">
16845 efrain 374
    							<table id="gridTable" class="table   table-bordered">
16822 efrain 375
                              		<thead>
376
                						<tr>
377
                                        	<th>LABEL_NAME</th>
378
                                          	<th>LABEL_ACTIVE</th>
379
                                          	<th>LABEL_ACTIONS</th>
380
                                        </tr>
381
                               		</thead>
382
                                 	<tbody>
383
                                 	</tbody>
384
                            	</table>
385
							</div>
386
						</div>
387
 
388
                   	</div>
389
                   	<div class="card-footer text-right">
390
 
391
							<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH  </button>
392
							<?php if($allowAdd) : ?>
393
							<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
394
							<?php endif; ?>
395
 
396
                 	</div>
397
          		</div>
398
           	</div>
399
        </div>
400
</div>
401
 
402
<!-- The Modal -->
403
<div class="modal" id="modal">
404
	<div class="modal-dialog  modal-xl">
405
    	<div class="modal-content">
406
 
407
            <!-- Modal Header -->
408
      		<div class="modal-header">
16845 efrain 409
        		<h6 class="modal-title">LABEL_DEGREES</h6>
16822 efrain 410
        		<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
411
      		</div>
412
 
413
            <!-- Modal body -->
16831 efrain 414
            <?php
16822 efrain 415
                    $form = $this->form;
416
            		$form->setAttributes([
417
                        'method'    => 'post',
418
                        'name'      => 'form',
419
                        'id'        => 'form'
420
                    ]);
421
 
422
                    $form->prepare();
423
                    echo $this->form()->openTag($form);
16831 efrain 424
                    ?>
425
 
426
      		<div class="modal-body">
427
 
428
    					<div class="row">
16841 efrain 429
                            <div class="col-12  mr-3">
16822 efrain 430
        					<?php
431
                            $element = $form->get('name');
432
                            $element->setOptions(['label' => 'LABEL_NAME']);
433
                            $element->setAttributes(['class' => 'form-control']);
434
 
435
                            echo $this->formLabel($element);
436
                            echo $this->formText($element);
437
                            ?>
16831 efrain 438
                            </div>
16822 efrain 439
						</div>
16831 efrain 440
						<div class="row">
16841 efrain 441
                            <div class="col-12  mr-3">
16822 efrain 442
                    	<?php
443
                            $element = $form->get('description');
444
                            $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
445
                            $element->setAttributes(['class' => 'form-control']);
446
 
447
                            echo $this->formLabel($element);
448
                            echo $this->formTextArea($element);
449
                        ?>
16831 efrain 450
                            </div>
16822 efrain 451
						</div>
16831 efrain 452
						<div class="row">
16841 efrain 453
                            <div class="col-12  mr-3">
16822 efrain 454
                      	<?php
455
                            $element = $form->get('status');
456
                            echo $this->formCheckbox($element);
457
                        ?>
16831 efrain 458
                            </div>
16822 efrain 459
						</div>
460
 
16831 efrain 461
 
462
 
463
 
16822 efrain 464
      		</div>
465
 
466
            <!-- Modal footer -->
16891 efrain 467
      		<div class="modal-footer text-right">
16831 efrain 468
              <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
469
                    		<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
16822 efrain 470
      		</div>
16831 efrain 471
              <?php echo $this->form()->closeTag($form); ?>
16822 efrain 472
 
473
    	</div>
474
	</div>
475
</div>
476
 
477
 
478
 
479
 
480