Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
15572 anderson 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('publications/pages/add');
9
$routeDatatable = $this->url('publications/pages');
10
$routeDashboard = $this->url('dashboard');
11
 
12
$allowAdd               = $acl->isAllowed($roleName, 'publications/pages/add') ? 1 : 0;
13
$allowEdit              = $acl->isAllowed($roleName, 'publications/pages/edit') ? 1 : 0;
14
$allowDelete            = $acl->isAllowed($roleName, 'publications/pages/delete') ? 1 : 0;
15
 
15572 anderson 16
$typeURL = \LeadersLinked\Model\Page::TYPE_URL;
17
$typePAGE = \LeadersLinked\Model\Page::TYPE_PAGE;
1 www 18
 
16822 efrain 19
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
20
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
1 www 21
 
16822 efrain 22
$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));
1 www 23
 
24
 
16822 efrain 25
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/jquery.validate.js'));
26
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/additional-methods.js'));
27
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/localization/messages_es.js'));
1 www 28
 
16822 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
 
16822 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
 
37
 
16822 efrain 38
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
39
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
1 www 40
 
41
 
42
 
43
 
16822 efrain 44
$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/select2.js'));
45
$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/i18n/es.js'));
46
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2/css/select2.css'));
1 www 47
 
16927 efrain 48
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2-bootstrap5-theme/select2-bootstrap-5-theme.css'));
1 www 49
 
50
 
16822 efrain 51
 
52
 
1 www 53
$status_active = \LeadersLinked\Model\Page::STATUS_ACTIVE;
54
 
55
$this->inlineScript()->captureStart();
56
echo <<<JS
57
    jQuery( document ).ready(function( $ ) {
58
        $.validator.addMethod('requiredContent', function (value, element, param) {
59
 
60
            if($(param).val() == '$typePAGE') {
61
                value = CKEDITOR.instances.content.getData();
62
 
63
 
64
                value = $.trim($.fn.stripHtml(value));
65
                return value.length > 0;
66
            } else {
67
                return true;
68
            }
69
        }, 'ERROR_REQUIRED');
70
 
71
        $.validator.addMethod('requiredURL', function (value, element, param) {
72
            if($(param).val() == '$typeURL') {
73
                value = $.trim(value);
74
 
75
                if(value.length > 0) {
76
                    return $.fn.isUrl(value);
77
                }
78
                 return false;
79
            } else {
80
                return true;
81
            }
82
 
83
        }, 'ERROR_URL');
84
 
85
 
86
 
87
 
88
        $.validator.setDefaults({
89
            debug: true,
90
            highlight: function(element) {
91
                $(element).addClass('is-invalid');
92
            },
93
            unhighlight: function(element) {
94
                $(element).removeClass('is-invalid');
95
            },
96
            errorElement: 'span',
97
            errorClass: 'error invalid-feedback',
98
            errorPlacement: function(error, element) {
99
                if(element.parent('.form-group').length) {
100
                    error.insertAfter(element);
101
                } else if(element.parent('.toggle').length) {
102
                    error.insertAfter(element.parent().parent());
103
                } else {
104
                    error.insertAfter(element.parent());
105
                }
106
            }
107
        });
108
 
109
 
110
        $.fn.showFormErrorValidator = function(fieldname, errors) {
111
            var field = $(fieldname);
112
            if(field) {
113
                $(field).addClass('is-invalid');
114
 
115
 
116
                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
117
                if(field.parent('.form-group').length) {
118
                    error.insertAfter(field);
119
                } else  if(field.parent('.toggle').length) {
120
                    error.insertAfter(field.parent().parent());
121
                } else {
122
                    error.insertAfter(field.parent());
123
                }
124
            }
125
        };
126
 
127
        var allowEdit   = $allowEdit;
128
        var allowDelete = $allowDelete;
129
 
15573 anderson 130
        var gridTable = $('#gridTable').dataTable( {
131
            'processing': true,
132
            'serverSide': true,
133
            'searching': true,
134
            'order': [[ 0, 'asc' ]],
135
            'ordering':  true,
136
            'ordenable' : true,
137
            'responsive': true,
138
            'select' : false,
139
        	'paging': true,
140
            'pagingType': 'simple_numbers',
141
    		'ajax': {
142
    			'url' : '$routeDatatable',
143
    			'type' : 'get',
144
                'beforeSend': function (request) {
145
                  NProgress.start();
146
                },
147
                'dataFilter': function(response) {
148
                    var response = jQuery.parseJSON( response );
1 www 149
 
15573 anderson 150
                    var json                = {};
151
                    json.recordsTotal       = 0;
152
                    json.recordsFiltered    = 0;
153
                    json.data               = [];
1 www 154
 
155
 
15573 anderson 156
                    if(response.success) {
157
                        json.recordsTotal       = response.data.total;
158
                        json.recordsFiltered    = response.data.total;
159
                        json.data               = response.data.items;
160
                    } else {
161
                        $.fn.showError(response.data)
162
                    }
1 www 163
 
15573 anderson 164
                    return JSON.stringify( json );
165
                }
166
    		},
167
            'language' : {
168
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
169
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
170
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
171
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
172
                'sInfo':           'LABEL_DATATABLE_SINFO',
173
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
174
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
175
                'sInfoPostFix':    '',
176
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
177
                'sUrl':            '',
178
                'sInfoThousands':  ',',
179
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
180
                'oPaginate': {
181
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
182
                    'sLast':     'LABEL_DATATABLE_SLAST',
183
                    'sNext':     'LABEL_DATATABLE_SNEXT',
184
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
185
                },
186
                'oAria': {
187
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
188
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
189
                },
190
            },
191
            'drawCallback': function( settings ) {
192
                NProgress.done();
16822 efrain 193
 
15573 anderson 194
            },
195
            'aoColumns': [
196
                { 'mDataProp': 'code' },
197
                { 'mDataProp': 'title' },
198
                { 'mDataProp': 'status' },
199
                { 'mDataProp': 'actions' },
200
    	    ],
201
            'columnDefs': [
202
                {
203
                    'targets': 0,
204
                    'className' : 'text-vertical-middle',
205
                },
206
                {
207
                    'targets': 1,
208
                    'className' : 'text-vertical-middle',
209
                },
210
                {
211
                    'targets': -2,
212
                    'orderable': false,
213
                    'className' : 'text-center',
214
                      'render' : function ( data, type, row ) {
1 www 215
 
16822 efrain 216
                        checked = data == 'a'  ? 'checked' : '';
217
                        return '<div class="form-check">' +
218
                            '<input type="checkbox" class="form-check-input" disabled="" checked="' + checked + '">' +
219
                            '<label class="form-check-label" for="checkCheckedDisabled"></label></div>' ;
15573 anderson 220
                    }
221
                },
222
                {
223
                    'targets': -1,
224
                    'orderable': false,
225
                    'render' : function ( data, type, row ) {
226
                        s = '';
1 www 227
 
15573 anderson 228
                        if(allowEdit &&  data['link_edit']) {
16906 efrain 229
                            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;';
15573 anderson 230
                        }
231
                        if(allowDelete && data['link_delete']) {
232
                            s = s + '<button class="btn btn-delete" data-href="' + data['link_delete']+ '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
233
                        }
234
                        return s;
235
                    }
236
                }
237
              ],
238
        });
1 www 239
 
240
 
241
        var validator = $('#form').validate({
242
            debug: true,
243
            onclick: false,
244
            onkeyup: false,
245
            ignore: [],
246
            rules: {
15458 efrain 247
                'code': {
1 www 248
                    required: true,
249
                    maxlength: 64,
250
                },
251
                'title': {
252
                    required: true,
253
                    maxlength: 128,
254
                },
255
                'type' : {
256
                    required: true,
257
                },
258
                'content': {
259
                    requiredContent: '#type',
260
                },
261
                'url': {
262
                    requiredURL: '#type',
263
 
264
                },
265
                'status': {
266
                    required: false,
267
 
268
                },
269
            },
270
 
271
 
272
        });
273
 
274
        $('body').on('click', 'button.btn-add', function(e) {
275
            e.preventDefault();
276
 
16840 efrain 277
 
1 www 278
            $('#form').attr('action', '$routeAdd');
15458 efrain 279
            $('#form #code').val('');
280
            $('#form #code').removeAttr('disabled');
1 www 281
            $('#form #title').val('');
282
            $('#form #type').val('$typePAGE').trigger('change');
283
            $('#form #status').bootstrapToggle('on');
284
            CKEDITOR.instances.content.setData('');
285
            $('#form #url').val('');
286
 
287
 
288
            validator.resetForm();
15458 efrain 289
 
290
            $('#row-header').hide();
291
            $('#row-list').hide();
292
            $('#row-form').show();
293
 
1 www 294
        });
295
 
296
        $('body').on('click', 'button.btn-edit', function(e) {
297
            e.preventDefault();
298
            NProgress.start();
299
            var action = $(this).data('href');
300
 
301
            $.ajax({
302
                'dataType'  : 'json',
303
                'accept'    : 'application/json',
304
                'method'    : 'get',
305
                'url'       :  action,
306
            }).done(function(response) {
307
                if(response['success']) {
308
 
16840 efrain 309
 
1 www 310
                    $('#form').attr('action', action);
15458 efrain 311
                    $('#form #code').val(response['data']['code']);
312
                    $('#form #code').attr('disabled','disabled');
1 www 313
                    $('#form #title').val(response['data']['title']);
314
                    $('#form #type').val(response['data']['type']).trigger('change');
315
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
316
 
317
                    var content = $.trim(response['data']['content']);
318
                    CKEDITOR.instances.content.setData(content.length > 0 ? content : '');
319
                    $('#form #url').val(response['data']['url']);
320
 
321
                    validator.resetForm();
322
 
15458 efrain 323
                    $('#row-header').hide();
324
                    $('#row-list').hide();
325
                    $('#row-form').show();
326
 
1 www 327
                } else {
328
                    $.fn.showError(response['data']);
329
                }
330
            }).fail(function( jqXHR, textStatus, errorThrown) {
331
                $.fn.showError(textStatus);
332
            }).always(function() {
333
                NProgress.done();
334
            });
335
        });
336
 
337
        $('body').on('click', 'button.btn-refresh', function(e) {
338
            e.preventDefault();
339
            gridTable.api().ajax.reload(null, false);
340
        });
341
 
342
 
343
        $('body').on('click', 'button.btn-cancel', function(e) {
344
            e.preventDefault();
15458 efrain 345
            $('#row-form').hide();
346
 
347
            $('#row-header').show();
348
            $('#row-list').show();
349
 
350
 
1 www 351
        });
352
 
16822 efrain 353
 $('body').on('click', 'button.btn-delete', function(e) {
354
        e.preventDefault();
355
        var action = $(this).data('href');
356
 
357
 
358
          swal.fire({
359
            title: 'LABEL_ARE_YOU_SURE',
360
            icon: 'question',
361
            cancelButtonText: 'LABEL_NO',
362
            showCancelButton: true,
363
            confirmButtonText: 'LABEL_YES'
364
          }).then((result) => {
365
            if (result.isConfirmed) {
366
 
367
                    NProgress.start();
368
                    $.ajax({
369
                        'dataType'  : 'json',
370
                        'accept'    : 'application/json',
371
                        'method'    : 'post',
372
                        'url'       :  action,
373
                    }).done(function(response) {
374
                        if(response['success']) {
375
                            $.fn.showSuccess(response['data']);
376
                            gridTable.api().ajax.reload(null, false);
377
                        } else {
378
                            $.fn.showError(response['data']);
379
                        }
380
                    }).fail(function( jqXHR, textStatus, errorThrown) {
381
                        $.fn.showError(textStatus);
382
                    }).always(function() {
383
                        NProgress.done();
384
                    });
385
            }
386
       });
387
    });
388
 
1 www 389
        $('#form #type').select2({
16918 efrain 390
            theme: 'bootstrap-5',
1 www 391
        });
392
 
393
 
394
        $('#form #type').change(function(e) {
395
            e.preventDefault();
396
 
397
            var value = $(this).val();
398
            if(value == '$typePAGE') {
399
                $('#form #url').val('');
400
                $('#form #url').parent().hide();
401
                $('#form #content').parent().show();
402
            } else {
403
                CKEDITOR.instances.content.setData('');
404
 
405
                $('#form #content').parent().hide();
406
                $('#form #url').parent().show();
407
            }
408
        });
409
 
410
        $('button[type="submit"]').click(function(e) {
411
            e.preventDefault();
412
            CKEDITOR.instances.content.updateElement();
413
 
414
            if($('#form').valid()) {
415
 
416
                $.ajax({
417
                    'dataType'  : 'json',
418
                    'accept'    : 'application/json',
419
                    'method'    : 'post',
420
                    'url'       :  $('#form').attr('action'),
15458 efrain 421
                    'data'      :  {
422
                        'code': $('#form #code').val(),
423
                        'title': $('#form #title').val(),
424
                        'type' : $('#form #type').val(),
425
                        'content':$('#form #content').val(),
426
                        'url': $('#form #url').val(),
427
                        'status': $('#form #status').val(),
428
                  }
1 www 429
                }).done(function(response) {
430
                    NProgress.start();
431
                    if(response['success']) {
432
                        $.fn.showSuccess(response['data']);
433
 
15458 efrain 434
                        $('#row-form').hide();
435
                        $('#row-header').show();
436
                        $('#row-list').show();
1 www 437
                         gridTable.api().ajax.reload(null, false);
438
                    } else {
439
                        validator.resetForm();
440
                        if(jQuery.type(response['data']) == 'string') {
441
                            $.fn.showError(response['data']);
442
                        } else  {
443
                            $.each(response['data'], function( fieldname, errors ) {
444
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
445
                            });
446
                        }
447
                    }
448
                }).fail(function( jqXHR, textStatus, errorThrown) {
449
                   $.fn.showError(textStatus);
450
                }).always(function() {
451
                    NProgress.done();
452
                });
453
                return false;
454
 
455
            }
456
        })
457
 
458
 
459
 
460
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
8775 stevensc 461
        CKEDITOR.replace( 'content', {
462
            toolbar: [
463
                    { name: 'editing', items: ['Scayt'] },
464
                    { name: 'links', items: ['Link', 'Unlink'] },
465
                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
466
                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
467
                    '/',
468
                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
469
                    { name: 'styles', items: ['Styles', 'Format'] },
470
                    { name: 'tools', items: ['Maximize'] }
471
                ],
472
                removePlugins: 'elementspath,Anchor',
473
                heigth: 100
474
        });
1 www 475
    });
476
JS;
477
$this->inlineScript()->captureEnd();
478
?>
15572 anderson 479
 
480
 
481
 
1 www 482
 
16841 efrain 483
<div class="container">
484
	<div class="card" id="row-list">
485
 
486
	 	<div class="card-body">
487
	 		<h6 class="card-title">LABEL_PAGES</h6>
16845 efrain 488
	 		<table id="gridTable" class="table table-bordered">
16841 efrain 489
             	<thead>
490
               		<tr>
491
                 		<th>LABEL_ID</th>
492
                     	<th>LABEL_TITLE</th>
493
                    	<th>LABEL_ACTIVE</th>
494
                 		<th>LABEL_ACTIONS</th>
495
             		</tr>
496
                </thead>
497
              	<tbody>
498
             	</tbody>
499
          	</table>
500
	 	</div>
501
	 	<div class="card-footer text-right">
502
			<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
503
            <?php if ($allowAdd) : ?>
504
    		<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
505
      		<?php endif; ?>
506
 
507
	 	</div>
508
	</div>
509
 
510
 
511
 
512
	<div class="card"  id="row-form" style="display: none">
513
	 	<?php
15458 efrain 514
                        $form = $this->form;
15572 anderson 515
                        $form->setAttributes([
15458 efrain 516
                            'method'    => 'post',
517
                            'name'      => 'form',
518
                            'id'        => 'form'
519
                        ]);
15572 anderson 520
 
15458 efrain 521
                        $form->prepare();
522
                        echo $this->form()->openTag($form);
16841 efrain 523
        ?>
524
	 	<div class="card-body">
525
	 		<h6 class="card-title">LABEL_PAGES</h6>
526
	 		<div class="row">
527
	 			<div class="col-12 mt-3">
15572 anderson 528
                            <?php
529
                            $element = $form->get('code');
530
                            $element->setOptions(['label' => 'LABEL_CODE']);
531
                            $element->setAttributes(['class' => 'form-control']);
532
 
533
                            echo $this->formLabel($element);
534
                            echo $this->formText($element);
15458 efrain 535
                            ?>
16841 efrain 536
          		</div>
537
          	</div>
538
			<div class="row">
539
	 			<div class="col-12 mt-3">
15572 anderson 540
                            <?php
541
                            $element = $form->get('title');
542
                            $element->setOptions(['label' => 'LABEL_TITLE']);
543
                            $element->setAttributes(['class' => 'form-control']);
544
 
545
                            echo $this->formLabel($element);
546
                            echo $this->formText($element);
1 www 547
                            ?>
16841 efrain 548
          		</div>
549
          	</div>
550
			<div class="row">
551
	 			<div class="col-12 mt-3">
15572 anderson 552
                            <?php
553
                            $element = $form->get('type');
554
                            $element->setOptions(['label' => 'LABEL_TYPE']);
555
                            $element->setAttributes(['class' => 'form-control']);
556
 
557
                            echo $this->formLabel($element);
558
                            echo $this->formSelect($element);
1 www 559
                            ?>
16841 efrain 560
          		</div>
561
          	</div>
562
			<div class="row">
563
	 			<div class="col-12 mt-3">
15572 anderson 564
                            <?php
565
                            $element = $form->get('content');
566
                            $element->setOptions(['label' => 'LABEL_CONTENT']);
567
                            $element->setAttributes(['class' => 'form-control']);
568
 
569
                            echo $this->formLabel($element);
570
                            echo $this->formTextArea($element);
571
                            ?>
16841 efrain 572
          		</div>
573
          	</div>
574
			<div class="row">
575
	 			<div class="col-12 mt-3">
15572 anderson 576
                            <?php
577
                            $element = $form->get('url');
578
                            $element->setOptions(['label' => 'LABEL_URL']);
579
                            $element->setAttributes(['class' => 'form-control']);
580
 
581
                            echo $this->formLabel($element);
582
                            echo $this->formText($element);
583
                            ?>
16841 efrain 584
          		</div>
585
          	</div>
586
			<div class="row">
587
	 			<div class="col-12 mt-3">
15572 anderson 588
                            <?php
589
                            $element = $form->get('status');
590
                            $element->setAttributes(['class' => 'form-control']);
591
                            echo $this->formCheckbox($element);
592
                            ?>
16841 efrain 593
          		</div>
594
          	</div>
595
	 	</div>
596
	 	<div class="card-footer text-right">
597
	 	 		<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
598
                <button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
599
	 	</div>
600
	 	<?php echo $this->form()->closeTag($form); ?>
601
	</div>
602
</div>
15572 anderson 603