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/industries/add');
9
$routeDatatable = $this->url('settings/industries');
10
$routeDashboard = $this->url('dashboard');
11
 
12
$allowAdd               = $acl->isAllowed($roleName, 'settings/industries/add') ? 1 : 0;
13
$allowEdit              = $acl->isAllowed($roleName, 'settings/industries/edit') ? 1 : 0;
14
$allowDelete            = $acl->isAllowed($roleName, 'settings/industries/delete') ? 1 : 0;
15
 
16822 efrain 16
 
17
 
16835 efrain 18
$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));
16822 efrain 19
 
1 www 20
 
16835 efrain 21
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
22
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
16822 efrain 23
 
16835 efrain 24
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/jquery.validate.js'));
25
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/additional-methods.js'));
26
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/localization/messages_es.js'));
1 www 27
 
16835 efrain 28
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
16822 efrain 29
 
16835 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'));
16822 efrain 32
 
16835 efrain 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'));
16822 efrain 37
 
16835 efrain 38
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
39
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
1 www 40
 
41
 
16822 efrain 42
 
43
$status_active = \LeadersLinked\Model\Industry::STATUS_ACTIVE;
44
 
45
 
46
$this->inlineScript()->captureStart();
47
echo <<<JS
48
    jQuery( document ).ready(function( $ ) {
49
 
50
 
51
       $.validator.setDefaults({
52
            debug: true,
53
            highlight: function(element) {
54
                $(element).addClass('is-invalid');
55
            },
56
            unhighlight: function(element) {
57
                $(element).removeClass('is-invalid');
58
            },
59
            errorElement: 'span',
60
            errorClass: 'error invalid-feedback',
61
            errorPlacement: function(error, element) {
62
                if(element.parent('.form-group').length) {
63
                    error.insertAfter(element);
64
                } else if(element.parent('.toggle').length) {
65
                    error.insertAfter(element.parent().parent());
66
                } else {
67
                    error.insertAfter(element.parent());
68
                }
69
            }
70
        });
71
 
72
 
73
        $.fn.showFormErrorValidator = function(fieldname, errors) {
74
            var field = $(fieldname);
75
            if(field) {
76
                $(field).addClass('is-invalid');
77
 
78
 
79
                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
80
                if(field.parent('.form-group').length) {
81
                    error.insertAfter(field);
82
                } else  if(field.parent('.toggle').length) {
83
                    error.insertAfter(field.parent().parent());
84
                } else {
85
                    error.insertAfter(field.parent());
86
                }
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
            'aoColumns': [
162
                { 'mDataProp': 'name' },
163
                { 'mDataProp': 'status' },
164
                { 'mDataProp': 'actions' },
165
    	    ],
166
            'columnDefs': [
167
                {
168
                    'targets': 0,
169
                    'className' : 'text-vertical-middle',
170
                },
171
                {
172
                    'targets': -2,
173
                    'orderable': false,
174
                    'className' : 'text-center',
175
                      'render' : function ( data, type, row ) {
176
 
177
                        checked = data == 'a'  ? 'checked' : '';
178
                        return '<div class="form-check">' +
179
                            '<input type="checkbox" class="form-check-input" disabled="" checked="' + checked + '">' +
180
                            '<label class="form-check-label" for="checkCheckedDisabled"></label></div>' ;
181
                    }
182
                },
183
                {
184
                    'targets': -1,
185
                    'orderable': false,
186
                    'render' : function ( data, type, row ) {
187
                        s = '';
188
 
189
                        if(allowEdit) {
16906 efrain 190
                            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 191
                        }
192
                        if(allowDelete) {
193
                            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;';
194
                        }
195
                        return s;
196
                    }
197
                }
198
              ],
199
        });
200
 
201
 
202
        var validator = $('#form').validate({
203
            debug: true,
204
            onclick: false,
205
            onkeyup: false,
206
            ignore: [],
207
            rules: {
208
                'name': {
209
                    required: true,
210
                    maxlength: 64,
211
                },
212
                'description': {
213
                    updateCkeditor:function() {
214
                        CKEDITOR.instances.description.updateElement();
215
                    },
216
                    required: true,
217
                },
218
                'status': {
219
                    required: false,
220
 
221
                },
222
            },
223
            submitHandler: function(form)
224
            {
225
                $.ajax({
226
                    'dataType'  : 'json',
227
                    'accept'    : 'application/json',
228
                    'method'    : 'post',
229
                    'url'       :  $('#form').attr('action'),
230
                    'data'      :  $('#form').serialize()
231
                }).done(function(response) {
232
                    NProgress.start();
233
                    if(response['success']) {
234
                        $.fn.showSuccess(response['data']);
235
 
236
                        $('#modal').modal('hide');
237
 
238
                         gridTable.api().ajax.reload(null, false);
239
                    } else {
240
                        validator.resetForm();
241
                        if(jQuery.type(response['data']) == 'string') {
242
                            $.fn.showError(response['data']);
243
                        } else  {
244
                            $.each(response['data'], function( fieldname, errors ) {
245
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
246
                            });
247
                        }
248
                    }
249
                }).fail(function( jqXHR, textStatus, errorThrown) {
250
                   $.fn.showError(textStatus);
251
                }).always(function() {
252
                    NProgress.done();
253
                });
254
                return false;
255
            },
256
            invalidHandler: function(form, validator) {
257
 
258
            }
259
        });
260
 
261
        $('body').on('click', 'button.btn-add', function(e) {
262
            e.preventDefault();
263
 
16840 efrain 264
 
16822 efrain 265
            $('#form').attr('action', '$routeAdd');
266
            $('#form #name').val('');
267
            $('#form #status').bootstrapToggle('on');
268
            CKEDITOR.instances.description.setData('');
269
 
270
 
271
            validator.resetForm();
272
            $('#modal').modal('show');
273
        });
274
 
275
        $('body').on('click', 'button.btn-edit', function(e) {
276
            e.preventDefault();
277
            NProgress.start();
278
            var action = $(this).data('href');
279
 
280
            $.ajax({
281
                'dataType'  : 'json',
282
                'accept'    : 'application/json',
283
                'method'    : 'get',
284
                'url'       :  action,
285
            }).done(function(response) {
286
                if(response['success']) {
287
 
16840 efrain 288
 
16822 efrain 289
                    $('#form').attr('action', action);
290
                    $('#form #name').val(response['data']['name']);
291
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
292
                    CKEDITOR.instances.description.setData(response['data']['description']);
293
 
294
                    validator.resetForm();
295
 
296
                    $('#modal').modal('show');
297
                } else {
298
                    $.fn.showError(response['data']);
299
                }
300
            }).fail(function( jqXHR, textStatus, errorThrown) {
301
                $.fn.showError(textStatus);
302
            }).always(function() {
303
                NProgress.done();
304
            });
305
        });
306
 
307
        $('body').on('click', 'button.btn-refresh', function(e) {
308
            e.preventDefault();
309
            gridTable.api().ajax.reload(null, false);
310
        });
311
 
312
        $('body').on('click', 'button.btn-cancel', function(e) {
313
            e.preventDefault();
314
            $('#modal').modal('hide');
315
        });
316
 
317
    $('body').on('click', 'button.btn-delete', function(e) {
318
        e.preventDefault();
319
        var action = $(this).data('href');
320
 
321
 
322
          swal.fire({
323
            title: 'LABEL_ARE_YOU_SURE',
324
            icon: 'question',
325
            cancelButtonText: 'LABEL_NO',
326
            showCancelButton: true,
327
            confirmButtonText: 'LABEL_YES'
328
          }).then((result) => {
329
            if (result.isConfirmed) {
330
 
331
                    NProgress.start();
332
                    $.ajax({
333
                        'dataType'  : 'json',
334
                        'accept'    : 'application/json',
335
                        'method'    : 'post',
336
                        'url'       :  action,
337
                    }).done(function(response) {
338
                        if(response['success']) {
339
                            $.fn.showSuccess(response['data']);
340
                            gridTable.api().ajax.reload(null, false);
341
                        } else {
342
                            $.fn.showError(response['data']);
343
                        }
344
                    }).fail(function( jqXHR, textStatus, errorThrown) {
345
                        $.fn.showError(textStatus);
346
                    }).always(function() {
347
                        NProgress.done();
348
                    });
349
                }
350
           });
351
        });
352
 
353
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
354
        CKEDITOR.replace( 'description');
355
    });
5668 stevensc 356
JS;
16822 efrain 357
$this->inlineScript()->captureEnd();
1 www 358
?>
359
 
16822 efrain 360
<div class="container">
16836 efrain 361
	<div class="card">
362
 
16835 efrain 363
		<div class="card-body">
364
			<h6 class="card-title">LABEL_INDUSTRIES</h6>
16836 efrain 365
            <div class="row">
16891 efrain 366
        	    <div class="col-12 mt-3">
16845 efrain 367
        	    <table id="gridTable" class="table   table-bordered">
16836 efrain 368
                    <thead>
369
        				<tr>
370
                            <th>LABEL_NAME</th>
371
                            <th>LABEL_ACTIVE</th>
372
                            <th>LABEL_ACTIONS</th>
373
                        </tr>
374
                    </thead>
375
                    <tbody>
376
                    </tbody>
377
                </table>
378
          	</div>
379
        </div>
380
        <div class="card-footer text-right">
381
			<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH  </button>
382
			<?php if($allowAdd) : ?>
383
			<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
384
			<?php endif; ?>
16835 efrain 385
        </div>
386
    </div>
16822 efrain 387
</div>
388
 
389
<!-- The Modal -->
390
<div class="modal" id="modal">
391
	<div class="modal-dialog  modal-xl">
392
    	<div class="modal-content">
393
 
394
            <!-- Modal Header -->
395
      		<div class="modal-header">
16845 efrain 396
        		<h6 class="modal-title">LABEL_INDUSTRIES</h6>
16822 efrain 397
        		<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
398
      		</div>
399
 
400
            <!-- Modal body -->
401
      		<div class="modal-body">
402
       			 <?php
403
                    $form = $this->form;
404
            		$form->setAttributes([
405
                        'method'    => 'post',
406
                        'name'      => 'form',
407
                        'id'        => 'form'
408
                    ]);
409
 
410
                    $form->prepare();
411
                    echo $this->form()->openTag($form);
412
                    ?>
16837 efrain 413
    					<div class="row">
16841 efrain 414
                            <div class="col-12  mt-3">
16822 efrain 415
        					<?php
416
                            $element = $form->get('name');
417
                            $element->setOptions(['label' => 'LABEL_NAME']);
418
                            $element->setAttributes(['class' => 'form-control']);
419
 
420
                            echo $this->formLabel($element);
421
                            echo $this->formText($element);
422
                            ?>
16837 efrain 423
						    </div>
16822 efrain 424
						</div>
16837 efrain 425
						<div class="row">
16841 efrain 426
                            <div class="col-12  mt-3">
16822 efrain 427
                    	<?php
428
                            $element = $form->get('description');
429
                            $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
430
                            $element->setAttributes(['class' => 'form-control']);
431
 
432
                            echo $this->formLabel($element);
433
                            echo $this->formTextArea($element);
434
                        ?>
16837 efrain 435
						    </div>
16822 efrain 436
						</div>
16837 efrain 437
						<div class="row">
16841 efrain 438
                            <div class="col-12  mt-3">
16822 efrain 439
                      	<?php
440
                            $element = $form->get('status');
441
                            echo $this->formCheckbox($element);
442
                        ?>
16837 efrain 443
                            </div>
16822 efrain 444
						</div>
445
 
16837 efrain 446
 
447
 
16822 efrain 448
      		</div>
449
 
450
            <!-- Modal footer -->
16838 efrain 451
      		<div class="modal-footer text-right">
16837 efrain 452
              <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
453
                    		<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
16822 efrain 454
      		</div>
16837 efrain 455
            <?php echo $this->form()->closeTag($form); ?>
16822 efrain 456
    	</div>
457
	</div>
458
</div>
459