Proyectos de Subversion LeadersLinked - Backend

Rev

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

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