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