Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 20 | Ir a la última revisión | | 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('settings/company-sizes/add');
8
$routeDatatable = $this->url('settings/company-sizes');
9
$routeDashboard = $this->url('dashboard');
10
 
11
$allowAdd               = $acl->isAllowed($roleName, 'settings/company-sizes/add') ? 1 : 0;
12
$allowEdit              = $acl->isAllowed($roleName, 'settings/company-sizes/edit') ? 1 : 0;
13
$allowDelete            = $acl->isAllowed($roleName, 'settings/company-sizes/delete') ? 1 : 0;
14
 
15
 
16
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.min.js'));
17
 
18
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
19
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
20
 
21
 
22
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
23
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
24
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
25
 
26
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
27
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
28
 
29
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
30
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
31
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
32
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
33
 
34
 
35
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
36
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
37
 
38
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));
39
 
40
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
41
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
42
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));
43
 
44
 
45
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
46
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
47
 
48
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
49
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
50
 
51
$status_active = \LeadersLinked\Model\CompanySize::STATUS_ACTIVE;
52
 
53
$this->inlineScript()->captureStart();
54
echo <<<JS
55
    jQuery( document ).ready(function( $ ) {
56
 
57
        $.validator.addMethod('greaterThan', function (value, element, param) {
58
            var otherElement = $(param);
59
            return parseInt(value, 10) > parseInt(otherElement.val(), 10);
60
        }, 'ERROR_INVALID_MINIMUM');
61
 
62
        $.validator.setDefaults({
63
            debug: true,
64
            highlight: function(element) {
65
                $(element).addClass('is-invalid');
66
            },
67
            unhighlight: function(element) {
68
                $(element).removeClass('is-invalid');
69
            },
70
            errorElement: 'span',
71
            errorClass: 'error invalid-feedback',
72
            errorPlacement: function(error, element) {
73
                if(element.parent('.form-group').length) {
74
                    error.insertAfter(element);
75
                } else if(element.parent('.toggle').length) {
76
                    error.insertAfter(element.parent().parent());
77
                } else {
78
                    error.insertAfter(element.parent());
79
                }
80
            }
81
        });
82
 
83
 
84
        $.fn.showFormErrorValidator = function(fieldname, errors) {
85
            var field = $(fieldname);
86
            if(field) {
87
                $(field).addClass('is-invalid');
88
 
89
 
90
                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
91
                if(field.parent('.form-group').length) {
92
                    error.insertAfter(field);
93
                } else  if(field.parent('.toggle').length) {
94
                    error.insertAfter(field.parent().parent());
95
                } else {
96
                    error.insertAfter(field.parent());
97
                }
98
            }
99
        };
100
 
101
 
102
 
103
 
104
        var allowEdit   = $allowEdit;
105
        var allowDelete = $allowDelete;
106
 
107
        var gridTable = $('#gridTable').dataTable( {
108
            'processing': true,
109
            'serverSide': true,
110
            'searching': true,
111
            'order': [[ 0, 'asc' ]],
112
            'ordering':  true,
113
            'ordenable' : true,
114
            'responsive': true,
115
            'select' : false,
116
        	'paging': true,
117
            'pagingType': 'simple_numbers',
118
    		'ajax': {
119
    			'url' : '$routeDatatable',
120
    			'type' : 'get',
121
                'beforeSend': function (request) {
122
                    NProgress.start();
123
                },
124
                'dataFilter': function(response) {
125
                    var response = jQuery.parseJSON( response );
126
 
127
                    var json                = {};
128
                    json.recordsTotal       = 0;
129
                    json.recordsFiltered    = 0;
130
                    json.data               = [];
131
 
132
 
133
                    if(response.success) {
134
                        json.recordsTotal       = response.data.total;
135
                        json.recordsFiltered    = response.data.total;
136
                        json.data               = response.data.items;
137
                    } else {
138
                        $.fn.showError(response.data)
139
                    }
140
 
141
                    return JSON.stringify( json );
142
                }
143
    		},
144
            'language' : {
145
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
146
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
147
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
148
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
149
                'sInfo':           'LABEL_DATATABLE_SINFO',
150
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
151
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
152
                'sInfoPostFix':    '',
153
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
154
                'sUrl':            '',
155
                'sInfoThousands':  ',',
156
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
157
                'oPaginate': {
158
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
159
                    'sLast':     'LABEL_DATATABLE_SLAST',
160
                    'sNext':     'LABEL_DATATABLE_SNEXT',
161
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
162
                },
163
                'oAria': {
164
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
165
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
166
                },
167
            },
168
            'drawCallback': function( settings ) {
169
                NProgress.done();
170
                $('button.btn-delete').confirmation({
171
                    rootSelector: 'button.btn-delete',
172
                    title : 'LABEL_ARE_YOU_SURE',
173
                    singleton : true,
174
                    btnOkLabel: 'LABEL_YES',
175
                    btnCancelLabel: 'LABEL_NO',
176
                    onConfirm: function(value) {
177
                        action = $(this).data('href');
178
                        NProgress.start();
179
                        $.ajax({
180
                            'dataType'  : 'json',
181
                            'accept'    : 'application/json',
182
                            'method'    : 'post',
183
                            'url'       :  action,
184
                        }).done(function(response) {
185
                            if(response['success']) {
186
                                $.fn.showSuccess(response['data']);
187
                                gridTable.api().ajax.reload(null, false);
188
                            } else {
189
                                $.fn.showError(response['data']);
190
                            }
191
                        }).fail(function( jqXHR, textStatus, errorThrown) {
192
                            $.fn.showError(textStatus);
193
                        }).always(function() {
194
                            NProgress.done();
195
                        });
196
                    },
197
                });
198
            },
199
            'aoColumns': [
200
                { 'mDataProp': 'name' },
201
    	        { 'mDataProp': 'minimum_no_of_employee'},
202
                { 'mDataProp': 'maximum_no_of_employee'},
203
                { 'mDataProp': 'status' },
204
                { 'mDataProp': 'actions' },
205
    	    ],
206
            'columnDefs': [
207
                {
208
                    'targets': 0,
209
                    'className' : 'text-vertical-middle',
210
                },
211
                {
212
                    'targets': 1,
213
                    'className' : 'text-right text-vertical-middle',
214
                },
215
                {
216
                    'targets':2,
217
                    'className' : 'text-right text-vertical-middle',
218
                },
219
                {
220
                    'targets': -2,
221
                    'orderable': false,
222
                    'className' : 'text-center',
223
                      'render' : function ( data, type, row ) {
224
 
225
                        checked = data == 'a' ? ' checked="checked" ' : '';
226
                        return '<div class="checkbox checkbox-success">' +
227
                            '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
228
                            '<label ></label></div>';
229
                    }
230
                },
231
                {
232
                    'targets': -1,
233
                    'orderable': false,
234
                    'render' : function ( data, type, row ) {
235
                        s = '';
236
 
237
                        if(allowEdit) {
238
                            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;';
239
                        }
240
                        if(allowDelete) {
241
                            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;';
242
                        }
243
                        return s;
244
                    }
245
                }
246
              ],
247
        });
248
 
249
 
250
        var validator = $('#form').validate({
251
            debug: true,
252
            onclick: false,
253
            onkeyup: false,
254
            ignore: [],
255
            rules: {
256
                'name': {
257
                    required: true,
258
                    maxlength: 64,
259
                },
260
                'minimum_no_of_employee': {
261
                    required: true,
262
                    min: 0
263
                },
264
                'maximum_no_of_employee': {
265
                    required: true,
266
                    min: 1,
267
                    greaterThan : '#minimum_no_of_employee'
268
                },
269
            },
270
            submitHandler: function(form)
271
            {
272
                $.ajax({
273
                    'dataType'  : 'json',
274
                    'accept'    : 'application/json',
275
                    'method'    : 'post',
276
                    'url'       :  $('#form').attr('action'),
277
                    'data'      :  $('#form').serialize()
278
                }).done(function(response) {
279
                    NProgress.start();
280
                    if(response['success']) {
281
                        $.fn.showSuccess(response['data']);
282
 
283
                        $('#modal').modal( 'hide');
284
 
285
                         gridTable.api().ajax.reload(null, false);
286
                    } else {
287
                        validator.resetForm();
288
                        if(jQuery.type(response['data']) == 'string') {
289
                            $.fn.showError(response['data']);
290
                        } else  {
291
                            $.each(response['data'], function( fieldname, errors ) {
292
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
293
                            });
294
                        }
295
                    }
296
                }).fail(function( jqXHR, textStatus, errorThrown) {
297
                   $.fn.showError(textStatus);
298
                }).always(function() {
299
                    NProgress.done();
300
                });
301
                return false;
302
            },
303
            invalidHandler: function(form, validator) {
304
 
305
            }
306
        });
307
 
308
        $('body').on('click', 'button.btn-add', function(e) {
309
            e.preventDefault();
310
 
311
            $('span[id="form-title"]').html('LABEL_ADD');
312
            $('#form').attr('action', '$routeAdd');
313
            $('#form #name').val('');
314
            $('#form #minimum_no_of_employee').val('');
315
            $('#form #maximum_no_of_employee').val('');
316
            $('#form #status').bootstrapToggle('on');
317
 
318
 
319
            validator.resetForm();
320
            $('#modal').modal('show');
321
        });
322
 
323
        $('body').on('click', 'button.btn-edit', function(e) {
324
            e.preventDefault();
325
            NProgress.start();
326
            var action = $(this).data('href');
327
 
328
            $.ajax({
329
                'dataType'  : 'json',
330
                'accept'    : 'application/json',
331
                'method'    : 'get',
332
                'url'       :  action,
333
            }).done(function(response) {
334
                if(response['success']) {
335
 
336
                    $('span[id="form-title"]').html('LABEL_EDIT');
337
                    $('#form').attr('action', action);
338
                    $('#form #name').val(response['data']['name']);
339
                    $('#form #minimum_no_of_employee').val(response['data']['minimum_no_of_employee']);
340
                    $('#form #maximum_no_of_employee').val(response['data']['maximum_no_of_employee']);
341
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
342
                    validator.resetForm();
343
 
344
                    $('#modal').modal('show');
345
                } else {
346
                    $.fn.showError(response['data']);
347
                }
348
            }).fail(function( jqXHR, textStatus, errorThrown) {
349
                $.fn.showError(textStatus);
350
            }).always(function() {
351
                NProgress.done();
352
            });
353
        });
354
 
355
        $('body').on('click', 'button.btn-refresh', function(e) {
356
            e.preventDefault();
357
            gridTable.api().ajax.reload(null, false);
358
        });
359
 
360
 
361
        $('body').on('click', 'button.btn-cancel', function(e) {
362
            e.preventDefault();
363
            $('#modal').modal('hide');
364
        });
365
 
366
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
367
 
368
        $('#form #minimum_no_of_employee').inputNumberFormat({decimal : 0});
369
        $('#form #maximum_no_of_employee').inputNumberFormat({decimal : 0});
370
    });
371
JS;
372
$this->inlineScript()->captureEnd();
373
?>
374
 
375
<!-- Content Header (Page header) -->
376
<section class="content-header">
377
	<div class="container-fluid">
378
    	<div class="row mb-2">
379
        	<div class="col-sm-12">
380
            	<h1>LABEL_COMPANY_SIZES</h1>
381
			</div>
382
		</div>
383
	</div><!-- /.container-fluid -->
384
</section>
385
 
386
<section class="content">
387
	<div class="container-fluid">
388
    	<div class="row">
389
        	<div class="col-12">
390
				<div class="card">
391
					<div class="card-body">
392
        	    		<table id="gridTable" class="table table-striped table-hover">
393
                      		<thead>
394
        						<tr>
395
                                	<th>LABEL_NAME</th>
396
                                  	<th>LABEL_MINIMUM</th>
397
                                  	<th>LABEL_MAXIMUM</th>
398
                                  	<th>LABEL_ACTIVE</th>
399
                                  	<th>LABEL_ACTIONS</th>
400
                                </tr>
401
                       		</thead>
402
                         	<tbody>
403
                         	</tbody>
404
                    	</table>
405
                   	</div>
406
                   	<div class="card-footer clearfix">
407
                   		<div style="float:right;">
408
							<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
409
							<?php if($allowAdd) : ?>
410
							<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
411
							<?php endif; ?>
412
						</div>
413
                 	</div>
414
          		</div>
415
           	</div>
416
        </div>
417
 	</div>
418
</section>
419
 
420
<!-- The Modal -->
421
<div class="modal" id="modal">
422
	<div class="modal-dialog  modal-xl">
423
    	<div class="modal-content">
424
 
425
            <!-- Modal Header -->
426
      		<div class="modal-header">
427
        		<h4 class="modal-title">LABEL_COMPANY_SIZES - <span id="form-title"></span></h4>
428
        		<button type="button" class="close" data-dismiss="modal">&times;</button>
429
      		</div>
430
 
431
            <!-- Modal body -->
432
      		<div class="modal-body">
433
       			 <?php
434
                    $form = $this->form;
435
            		$form->setAttributes([
436
                        'method'    => 'post',
437
                        'name'      => 'form',
438
                        'id'        => 'form'
439
                    ]);
440
 
441
                    $form->prepare();
442
                    echo $this->form()->openTag($form);
443
                    ?>
444
    					<div class="form-group">
445
        					<?php
446
                            $element = $form->get('name');
447
                            $element->setOptions(['label' => 'LABEL_NAME']);
448
                            $element->setAttributes(['class' => 'form-control']);
449
 
450
                            echo $this->formLabel($element);
451
                            echo $this->formText($element);
452
                            ?>
453
						</div>
454
						<div class="form-group">
455
                    	<?php
456
                            $element = $form->get('minimum_no_of_employee');
457
                            $element->setOptions(['label' => 'LABEL_MINIMUM']);
458
                            $element->setAttributes(['class' => 'form-control']);
459
 
460
                            echo $this->formLabel($element);
461
                            echo $this->formText($element);
462
                        ?>
463
						</div>
464
						<div class="form-group">
465
                    	<?php
466
                            $element = $form->get('maximum_no_of_employee');
467
                            $element->setOptions(['label' => 'LABEL_MAXIMUM']);
468
                            $element->setAttributes(['class' => 'form-control']);
469
 
470
                            echo $this->formLabel($element);
471
                            echo $this->formText($element);
472
                        ?>
473
						</div>
474
						<div class="form-group">
475
                      	<?php
476
                            $element = $form->get('status');
477
                            echo $this->formCheckbox($element);
478
                        ?>
479
						</div>
480
 
481
        				<div class="form-group">
482
                    		<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
483
                    		<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
484
                   		</div>
485
     	      		<?php echo $this->form()->closeTag($form); ?>
486
      		</div>
487
 
488
            <!-- Modal footer -->
489
      		<div class="modal-footer">
490
        		<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
491
      		</div>
492
 
493
    	</div>
494
	</div>
495
</div>
496
 
497
 
498
 
499
 
500
 
501