Proyectos de Subversion LeadersLinked - Backend

Rev

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