Proyectos de Subversion LeadersLinked - Backend

Rev

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