17003 |
efrain |
1 |
<?php
|
|
|
2 |
$acl = $this->viewModel()->getRoot()->getVariable('acl');
|
|
|
3 |
$currentUser = $this->currentUserHelper();
|
|
|
4 |
|
|
|
5 |
$roleName = $currentUser->getUserTypeId();
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
$routeAdd = $this->url('media/categories/add');
|
|
|
9 |
$routeDatatable = $this->url('media/categories');
|
|
|
10 |
$routeDashboard = $this->url('dashboard');
|
|
|
11 |
|
|
|
12 |
$allowAdd = $acl->isAllowed($roleName, 'media/categories/add') ? 1 : 0;
|
|
|
13 |
$allowEdit = $acl->isAllowed($roleName, 'media/categories/edit') ? 1 : 0;
|
|
|
14 |
$allowDelete = $acl->isAllowed($roleName, 'media/categories/delete') ? 1 : 0;
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
|
|
|
19 |
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
|
|
|
26 |
|
|
|
27 |
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
|
|
|
28 |
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));
|
|
|
29 |
|
|
|
30 |
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
|
|
|
31 |
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
|
|
|
32 |
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
|
|
|
33 |
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
$this->inlineScript()->captureStart();
|
|
|
39 |
echo <<<JS
|
|
|
40 |
jQuery( document ).ready(function( $ ) {
|
|
|
41 |
|
|
|
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();
|
|
|
111 |
|
|
|
112 |
},
|
|
|
113 |
'aoColumns': [
|
|
|
114 |
{ 'mDataProp': 'name' },
|
|
|
115 |
{ 'mDataProp': 'actions' },
|
|
|
116 |
],
|
|
|
117 |
'columnDefs': [
|
|
|
118 |
{
|
|
|
119 |
'targets': 0,
|
|
|
120 |
'className' : 'text-vertical-middle',
|
|
|
121 |
},
|
|
|
122 |
|
|
|
123 |
{
|
|
|
124 |
'targets': -1,
|
|
|
125 |
'orderable': false,
|
|
|
126 |
'render' : function ( data, type, row ) {
|
|
|
127 |
s = '';
|
|
|
128 |
|
|
|
129 |
if(allowEdit) {
|
|
|
130 |
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> ';
|
|
|
131 |
}
|
|
|
132 |
if(allowDelete) {
|
|
|
133 |
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> ';
|
|
|
134 |
}
|
|
|
135 |
return s;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
],
|
|
|
139 |
});
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
var validator = $('#form').validate({
|
|
|
143 |
debug: true,
|
|
|
144 |
onclick: false,
|
|
|
145 |
onkeyup: false,
|
|
|
146 |
ignore: [],
|
|
|
147 |
rules: {
|
|
|
148 |
'name': {
|
|
|
149 |
required: true,
|
|
|
150 |
maxlength: 100,
|
|
|
151 |
}
|
|
|
152 |
},
|
|
|
153 |
submitHandler: function(form)
|
|
|
154 |
{
|
|
|
155 |
$.ajax({
|
|
|
156 |
'dataType' : 'json',
|
|
|
157 |
'accept' : 'application/json',
|
|
|
158 |
'method' : 'post',
|
|
|
159 |
'url' : $('#form').attr('action'),
|
|
|
160 |
'data' : $('#form').serialize()
|
|
|
161 |
}).done(function(response) {
|
|
|
162 |
NProgress.start();
|
|
|
163 |
if(response['success']) {
|
|
|
164 |
$.fn.showSuccess(response['data']);
|
|
|
165 |
|
|
|
166 |
$('#modal').modal('hide');
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
gridTable.api().ajax.reload(null, false);
|
|
|
170 |
} else {
|
|
|
171 |
validator.resetForm();
|
|
|
172 |
if(jQuery.type(response['data']) == 'string') {
|
|
|
173 |
$.fn.showError(response['data']);
|
|
|
174 |
} else {
|
|
|
175 |
$.each(response['data'], function( fieldname, errors ) {
|
|
|
176 |
$.fn.showFormErrorValidator('#form #' + fieldname, errors);
|
|
|
177 |
});
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
}).fail(function( jqXHR, textStatus, errorThrown) {
|
|
|
181 |
$.fn.showError(textStatus);
|
|
|
182 |
}).always(function() {
|
|
|
183 |
NProgress.done();
|
|
|
184 |
});
|
|
|
185 |
return false;
|
|
|
186 |
},
|
|
|
187 |
invalidHandler: function(form, validator) {
|
|
|
188 |
|
|
|
189 |
}
|
|
|
190 |
});
|
|
|
191 |
|
|
|
192 |
$('body').on('click', 'button.btn-add', function(e) {
|
|
|
193 |
e.preventDefault();
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
$('#form').attr('action', '$routeAdd');
|
|
|
197 |
$('#form #name').val('');
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
validator.resetForm();
|
|
|
201 |
$('#modal').modal('show');
|
|
|
202 |
});
|
|
|
203 |
|
|
|
204 |
$('body').on('click', 'button.btn-edit', function(e) {
|
|
|
205 |
e.preventDefault();
|
|
|
206 |
NProgress.start();
|
|
|
207 |
var action = $(this).data('href');
|
|
|
208 |
|
|
|
209 |
$.ajax({
|
|
|
210 |
'dataType' : 'json',
|
|
|
211 |
'accept' : 'application/json',
|
|
|
212 |
'method' : 'get',
|
|
|
213 |
'url' : action,
|
|
|
214 |
}).done(function(response) {
|
|
|
215 |
if(response['success']) {
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
$('#form').attr('action', action);
|
|
|
219 |
$('#form #name').val(response['data']['name']);
|
|
|
220 |
|
|
|
221 |
validator.resetForm();
|
|
|
222 |
|
|
|
223 |
$('#modal').modal('show');
|
|
|
224 |
} else {
|
|
|
225 |
$.fn.showError(response['data']);
|
|
|
226 |
}
|
|
|
227 |
}).fail(function( jqXHR, textStatus, errorThrown) {
|
|
|
228 |
$.fn.showError(textStatus);
|
|
|
229 |
}).always(function() {
|
|
|
230 |
NProgress.done();
|
|
|
231 |
});
|
|
|
232 |
});
|
|
|
233 |
|
|
|
234 |
$('body').on('click', 'button.btn-delete', function(e) {
|
|
|
235 |
e.preventDefault();
|
|
|
236 |
var action = $(this).data('href');
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
swal.fire({
|
|
|
240 |
title: 'LABEL_ARE_YOU_SURE',
|
|
|
241 |
icon: 'question',
|
|
|
242 |
cancelButtonText: 'LABEL_NO',
|
|
|
243 |
showCancelButton: true,
|
|
|
244 |
confirmButtonText: 'LABEL_YES'
|
|
|
245 |
}).then((result) => {
|
|
|
246 |
if (result.isConfirmed) {
|
|
|
247 |
|
|
|
248 |
NProgress.start();
|
|
|
249 |
$.ajax({
|
|
|
250 |
'dataType' : 'json',
|
|
|
251 |
'accept' : 'application/json',
|
|
|
252 |
'method' : 'post',
|
|
|
253 |
'url' : action,
|
|
|
254 |
}).done(function(response) {
|
|
|
255 |
if(response['success']) {
|
|
|
256 |
$.fn.showSuccess(response['data']);
|
|
|
257 |
gridTable.api().ajax.reload(null, false);
|
|
|
258 |
} else {
|
|
|
259 |
$.fn.showError(response['data']);
|
|
|
260 |
}
|
|
|
261 |
}).fail(function( jqXHR, textStatus, errorThrown) {
|
|
|
262 |
$.fn.showError(textStatus);
|
|
|
263 |
}).always(function() {
|
|
|
264 |
NProgress.done();
|
|
|
265 |
});
|
|
|
266 |
}
|
|
|
267 |
});
|
|
|
268 |
|
|
|
269 |
});
|
|
|
270 |
|
|
|
271 |
$('body').on('click', 'button.btn-refresh', function(e) {
|
|
|
272 |
e.preventDefault();
|
|
|
273 |
gridTable.api().ajax.reload(null, false);
|
|
|
274 |
});
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
$('body').on('click', 'button.btn-cancel', function(e) {
|
|
|
278 |
e.preventDefault();
|
|
|
279 |
$('#modal').modal('hide');
|
|
|
280 |
});
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
});
|
|
|
284 |
JS;
|
|
|
285 |
$this->inlineScript()->captureEnd();
|
|
|
286 |
?>
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
<div class="container">
|
|
|
291 |
<div class="row">
|
|
|
292 |
<div class="col-12 mt-3">
|
|
|
293 |
<div class="card">
|
|
|
294 |
|
|
|
295 |
<div class="card-body">
|
|
|
296 |
<h6 class="card-title">LABEL_MEDIA_CATEGORIES</h6>
|
|
|
297 |
<div class="row">
|
|
|
298 |
<div class="col-12 mt-3">
|
|
|
299 |
<table id="gridTable" class="table table-bordered">
|
|
|
300 |
<thead>
|
|
|
301 |
<tr>
|
|
|
302 |
<th>LABEL_NAME</th>
|
|
|
303 |
<th>LABEL_ACTIONS</th>
|
|
|
304 |
</tr>
|
|
|
305 |
</thead>
|
|
|
306 |
<tbody>
|
|
|
307 |
</tbody>
|
|
|
308 |
</table>
|
|
|
309 |
</div>
|
|
|
310 |
</div>
|
|
|
311 |
|
|
|
312 |
</div>
|
|
|
313 |
<div class="card-footer text-right">
|
|
|
314 |
|
|
|
315 |
<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH </button>
|
|
|
316 |
<?php if($allowAdd) : ?>
|
|
|
317 |
<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
|
|
|
318 |
<?php endif; ?>
|
|
|
319 |
|
|
|
320 |
</div>
|
|
|
321 |
</div>
|
|
|
322 |
</div>
|
|
|
323 |
</div>
|
|
|
324 |
</div>
|
|
|
325 |
|
|
|
326 |
<!-- The Modal -->
|
|
|
327 |
<div class="modal" id="modal">
|
|
|
328 |
<div class="modal-dialog modal-lg">
|
|
|
329 |
<div class="modal-content">
|
|
|
330 |
|
|
|
331 |
<!-- Modal Header -->
|
|
|
332 |
<div class="modal-header">
|
|
|
333 |
<h6 class="modal-title">LABEL_CATEGORIES</h6>
|
|
|
334 |
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
|
|
|
335 |
</div>
|
|
|
336 |
|
|
|
337 |
<?php
|
|
|
338 |
$form = $this->form;
|
|
|
339 |
$form->setAttributes([
|
|
|
340 |
'method' => 'post',
|
|
|
341 |
'name' => 'form',
|
|
|
342 |
'id' => 'form'
|
|
|
343 |
]);
|
|
|
344 |
|
|
|
345 |
$form->prepare();
|
|
|
346 |
echo $this->form()->openTag($form);
|
|
|
347 |
?>
|
|
|
348 |
|
|
|
349 |
<!-- Modal body -->
|
|
|
350 |
<div class="modal-body">
|
|
|
351 |
|
|
|
352 |
<div class="row">
|
|
|
353 |
<div class="col mt-3">
|
|
|
354 |
<?php
|
|
|
355 |
$element = $form->get('name');
|
|
|
356 |
$element->setOptions(['label' => 'LABEL_NAME']);
|
|
|
357 |
$element->setAttributes(['class' => 'form-control']);
|
|
|
358 |
|
|
|
359 |
echo $this->formLabel($element);
|
|
|
360 |
echo $this->formText($element);
|
|
|
361 |
?>
|
|
|
362 |
</div>
|
|
|
363 |
</div>
|
|
|
364 |
|
|
|
365 |
|
|
|
366 |
</div>
|
|
|
367 |
|
|
|
368 |
<!-- Modal footer -->
|
|
|
369 |
<div class="modal-footer text-right">
|
|
|
370 |
<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
|
|
|
371 |
<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
|
|
|
372 |
</div>
|
|
|
373 |
<?php echo $this->form()->closeTag($form); ?>
|
|
|
374 |
|
|
|
375 |
</div>
|
|
|
376 |
</div>
|
|
|
377 |
</div>
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
|