Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16971 | | Comparar con el anterior | Ultima modificación | Ver Log |

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