Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 5667 | Rev 15497 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5668 stevensc 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/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
 
16
 
17
 
18
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
19
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
20
 
21
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
22
 
23
 
24
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
25
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
26
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
27
 
28
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
29
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
30
 
31
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
32
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
33
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
34
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
35
 
36
 
37
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
38
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
39
 
40
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
41
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
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
 
5668 stevensc 97
        /* var gridTable = $('#gridTable').dataTable( {
1 www 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
                $('button.btn-delete').confirmation({
161
                    rootSelector: 'button.btn-delete',
162
                    title : 'LABEL_ARE_YOU_SURE',
163
                    singleton : true,
164
                    btnOkLabel: 'LABEL_YES',
165
                    btnCancelLabel: 'LABEL_NO',
166
                    onConfirm: function(value) {
167
                        action = $(this).data('href');
168
                        NProgress.start();
169
                        $.ajax({
170
                            'dataType'  : 'json',
171
                            'accept'    : 'application/json',
172
                            'method'    : 'post',
173
                            'url'       :  action,
174
                        }).done(function(response) {
175
                            if(response['success']) {
176
                                $.fn.showSuccess(response['data']);
177
                                gridTable.api().ajax.reload(null, false);
178
                            } else {
179
                                $.fn.showError(response['data']);
180
                            }
181
                        }).fail(function( jqXHR, textStatus, errorThrown) {
182
                            $.fn.showError(textStatus);
183
                        }).always(function() {
184
                            NProgress.done();
185
                        });
186
                    },
187
                });
188
            },
189
            'aoColumns': [
190
                { 'mDataProp': 'name' },
191
                { 'mDataProp': 'status' },
192
                { 'mDataProp': 'actions' },
193
    	    ],
194
            'columnDefs': [
195
                {
196
                    'targets': 0,
197
                    'className' : 'text-vertical-middle',
198
                },
199
                {
200
                    'targets': -2,
201
                    'orderable': false,
202
                    'className' : 'text-center',
203
                      'render' : function ( data, type, row ) {
204
 
205
                        checked = data == 'a' ? ' checked="checked" ' : '';
206
                        return '<div class="checkbox checkbox-success">' +
207
                            '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
208
                            '<label ></label></div>';
209
                    }
210
                },
211
                {
212
                    'targets': -1,
213
                    'orderable': false,
214
                    'render' : function ( data, type, row ) {
215
                        s = '';
216
 
217
                        if(allowEdit) {
218
                            s = s + '<button class="btn btn-primary btn-edit" data-href="' + data['link_edit']+ '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
219
                        }
220
                        if(allowDelete) {
221
                            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;';
222
                        }
223
                        return s;
224
                    }
225
                }
226
              ],
227
        });
228
 
229
 
230
        var validator = $('#form').validate({
231
            debug: true,
232
            onclick: false,
233
            onkeyup: false,
234
            ignore: [],
235
            rules: {
236
                'name': {
237
                    required: true,
238
                    maxlength: 64,
239
                },
240
                'description': {
241
                    updateCkeditor:function() {
242
                        CKEDITOR.instances.description.updateElement();
243
                    },
244
                    required: true,
245
                },
246
                'status': {
247
                    required: false,
248
 
249
                },
250
            },
251
            submitHandler: function(form)
252
            {
253
                $.ajax({
254
                    'dataType'  : 'json',
255
                    'accept'    : 'application/json',
256
                    'method'    : 'post',
257
                    'url'       :  $('#form').attr('action'),
258
                    'data'      :  $('#form').serialize()
259
                }).done(function(response) {
260
                    NProgress.start();
261
                    if(response['success']) {
262
                        $.fn.showSuccess(response['data']);
263
 
264
                        $('#modal').modal('hide');
265
 
266
                         gridTable.api().ajax.reload(null, false);
267
                    } else {
268
                        validator.resetForm();
269
                        if(jQuery.type(response['data']) == 'string') {
270
                            $.fn.showError(response['data']);
271
                        } else  {
272
                            $.each(response['data'], function( fieldname, errors ) {
273
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
274
                            });
275
                        }
276
                    }
277
                }).fail(function( jqXHR, textStatus, errorThrown) {
278
                   $.fn.showError(textStatus);
279
                }).always(function() {
280
                    NProgress.done();
281
                });
282
                return false;
283
            },
284
            invalidHandler: function(form, validator) {
285
 
286
            }
287
        });
288
 
289
        $('body').on('click', 'button.btn-add', function(e) {
290
            e.preventDefault();
291
 
292
            $('span[id="form-title"]').html('LABEL_ADD');
293
            $('#form').attr('action', '$routeAdd');
294
            $('#form #name').val('');
295
            $('#form #status').bootstrapToggle('on');
296
            CKEDITOR.instances.description.setData('');
297
 
298
 
299
            validator.resetForm();
300
            $('#modal').modal('show');
301
        });
302
 
303
        $('body').on('click', 'button.btn-edit', function(e) {
304
            e.preventDefault();
305
            NProgress.start();
306
            var action = $(this).data('href');
307
 
308
            $.ajax({
309
                'dataType'  : 'json',
310
                'accept'    : 'application/json',
311
                'method'    : 'get',
312
                'url'       :  action,
313
            }).done(function(response) {
314
                if(response['success']) {
315
 
316
                    $('span[id="form-title"]').html('LABEL_EDIT');
317
                    $('#form').attr('action', action);
318
                    $('#form #name').val(response['data']['name']);
319
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
320
                    CKEDITOR.instances.description.setData(response['data']['description']);
321
 
322
                    validator.resetForm();
323
 
324
                    $('#modal').modal('show');
325
                } else {
326
                    $.fn.showError(response['data']);
327
                }
328
            }).fail(function( jqXHR, textStatus, errorThrown) {
329
                $.fn.showError(textStatus);
330
            }).always(function() {
331
                NProgress.done();
332
            });
333
        });
334
 
335
        $('body').on('click', 'button.btn-refresh', function(e) {
336
            e.preventDefault();
337
            gridTable.api().ajax.reload(null, false);
338
        });
339
 
340
        $('body').on('click', 'button.btn-cancel', function(e) {
341
            e.preventDefault();
342
            $('#modal').modal('hide');
343
        });
344
 
345
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
5668 stevensc 346
        CKEDITOR.replace( 'description'); */
1 www 347
    });
348
JS;
349
$this->inlineScript()->captureEnd();
5668 stevensc 350
$js = <<<JS
351
const urlsVar = {
352
        linkTable: '$routeDatatable',
353
        addUrl: '$routeAdd',
354
        allowAdd: '$allowAdd',
355
        allowEdit: '$allowEdit',
356
        allowDelete: '$allowDelete',
357
   }
358
JS;
359
 
360
$this->inlineScript()->appendScript($js);
361
$this->inlineScript()->appendFile('/react-bundles/settings/industries/industriesBundle.js');
1 www 362
?>
363
 
5668 stevensc 364
 
1 www 365
<!-- Content Header (Page header) -->
366
 
5668 stevensc 367
<div id="industries">
368
</div>