Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15458 | Rev 15573 | 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
 
19
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
20
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
21
 
22
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
23
 
24
 
25
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
26
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
27
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
28
 
29
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
30
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
31
 
32
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
33
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
34
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
35
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
36
 
37
 
38
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
39
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
40
 
41
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
42
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
43
 
44
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.js'));
45
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/i18n/es.js'));
46
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.css'));
47
 
48
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.css'));
49
 
50
 
51
 
52
 
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
 
15572 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
 
15572 anderson 150
        //             var json                = {};
151
        //             json.recordsTotal       = 0;
152
        //             json.recordsFiltered    = 0;
153
        //             json.data               = [];
1 www 154
 
155
 
15572 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
 
15572 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();
193
        //         $('button.btn-delete').confirmation({
194
        //             rootSelector: 'button.btn-delete',
195
        //             title : 'LABEL_ARE_YOU_SURE',
196
        //             singleton : true,
197
        //             btnOkLabel: 'LABEL_YES',
198
        //             btnCancelLabel: 'LABEL_NO',
199
        //             onConfirm: function(value) {
200
        //                 action = $(this).data('href');
201
        //                 NProgress.start();
202
        //                 $.ajax({
203
        //                     'dataType'  : 'json',
204
        //                     'accept'    : 'application/json',
205
        //                     'method'    : 'post',
206
        //                     'url'       :  action,
207
        //                 }).done(function(response) {
208
        //                     if(response['success']) {
209
        //                         $.fn.showSuccess(response['data']);
210
        //                         gridTable.api().ajax.reload(null, false);
211
        //                     } else {
212
        //                         $.fn.showError(response['data']);
213
        //                     }
214
        //                 }).fail(function( jqXHR, textStatus, errorThrown) {
215
        //                     $.fn.showError(textStatus);
216
        //                 }).always(function() {
217
        //                     NProgress.done();
218
        //                 });
219
        //             },
220
        //         });
221
        //     },
222
        //     'aoColumns': [
223
        //         { 'mDataProp': 'code' },
224
        //         { 'mDataProp': 'title' },
225
        //         { 'mDataProp': 'status' },
226
        //         { 'mDataProp': 'actions' },
227
    	//     ],
228
        //     'columnDefs': [
229
        //         {
230
        //             'targets': 0,
231
        //             'className' : 'text-vertical-middle',
232
        //         },
233
        //         {
234
        //             'targets': 1,
235
        //             'className' : 'text-vertical-middle',
236
        //         },
237
        //         {
238
        //             'targets': -2,
239
        //             'orderable': false,
240
        //             'className' : 'text-center',
241
        //               'render' : function ( data, type, row ) {
1 www 242
 
15572 anderson 243
        //                 checked = data == 'a' ? ' checked="checked" ' : '';
244
        //                 return '<div class="checkbox checkbox-success">' +
245
        //                     '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
246
        //                     '<label ></label></div>';
247
        //             }
248
        //         },
249
        //         {
250
        //             'targets': -1,
251
        //             'orderable': false,
252
        //             'render' : function ( data, type, row ) {
253
        //                 s = '';
1 www 254
 
15572 anderson 255
        //                 if(allowEdit &&  data['link_edit']) {
256
        //                     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;';
257
        //                 }
258
        //                 if(allowDelete && data['link_delete']) {
259
        //                     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;';
260
        //                 }
261
        //                 return s;
262
        //             }
263
        //         }
264
        //       ],
265
        // });
1 www 266
 
267
 
268
        var validator = $('#form').validate({
269
            debug: true,
270
            onclick: false,
271
            onkeyup: false,
272
            ignore: [],
273
            rules: {
15458 efrain 274
                'code': {
1 www 275
                    required: true,
276
                    maxlength: 64,
277
                },
278
                'title': {
279
                    required: true,
280
                    maxlength: 128,
281
                },
282
                'type' : {
283
                    required: true,
284
                },
285
                'content': {
286
                    requiredContent: '#type',
287
                },
288
                'url': {
289
                    requiredURL: '#type',
290
 
291
                },
292
                'status': {
293
                    required: false,
294
 
295
                },
296
            },
297
 
298
 
299
        });
300
 
301
        $('body').on('click', 'button.btn-add', function(e) {
302
            e.preventDefault();
303
 
304
            $('span[id="form-title"]').html('LABEL_ADD');
305
            $('#form').attr('action', '$routeAdd');
15458 efrain 306
            $('#form #code').val('');
307
            $('#form #code').removeAttr('disabled');
1 www 308
            $('#form #title').val('');
309
            $('#form #type').val('$typePAGE').trigger('change');
310
            $('#form #status').bootstrapToggle('on');
311
            CKEDITOR.instances.content.setData('');
312
            $('#form #url').val('');
313
 
314
 
315
            validator.resetForm();
15458 efrain 316
 
317
            $('#row-header').hide();
318
            $('#row-list').hide();
319
            $('#row-form').show();
320
 
1 www 321
        });
322
 
323
        $('body').on('click', 'button.btn-edit', function(e) {
324
            e.preventDefault();
325
            NProgress.start();
326
            var action = $(this).data('href');
327
 
328
            $.ajax({
329
                'dataType'  : 'json',
330
                'accept'    : 'application/json',
331
                'method'    : 'get',
332
                'url'       :  action,
333
            }).done(function(response) {
334
                if(response['success']) {
335
 
336
                    $('span[id="form-title"]').html('LABEL_EDIT');
337
                    $('#form').attr('action', action);
15458 efrain 338
                    $('#form #code').val(response['data']['code']);
339
                    $('#form #code').attr('disabled','disabled');
1 www 340
                    $('#form #title').val(response['data']['title']);
341
                    $('#form #type').val(response['data']['type']).trigger('change');
342
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
343
 
344
                    var content = $.trim(response['data']['content']);
345
                    CKEDITOR.instances.content.setData(content.length > 0 ? content : '');
346
                    $('#form #url').val(response['data']['url']);
347
 
348
                    validator.resetForm();
349
 
15458 efrain 350
                    $('#row-header').hide();
351
                    $('#row-list').hide();
352
                    $('#row-form').show();
353
 
1 www 354
                } else {
355
                    $.fn.showError(response['data']);
356
                }
357
            }).fail(function( jqXHR, textStatus, errorThrown) {
358
                $.fn.showError(textStatus);
359
            }).always(function() {
360
                NProgress.done();
361
            });
362
        });
363
 
364
        $('body').on('click', 'button.btn-refresh', function(e) {
365
            e.preventDefault();
366
            gridTable.api().ajax.reload(null, false);
367
        });
368
 
369
 
370
        $('body').on('click', 'button.btn-cancel', function(e) {
371
            e.preventDefault();
15458 efrain 372
            $('#row-form').hide();
373
 
374
            $('#row-header').show();
375
            $('#row-list').show();
376
 
377
 
1 www 378
        });
379
 
380
        $('#form #type').select2({
381
            theme: 'bootstrap4',
382
        });
383
 
384
 
385
        $('#form #type').change(function(e) {
386
            e.preventDefault();
387
 
388
            var value = $(this).val();
389
            if(value == '$typePAGE') {
390
                $('#form #url').val('');
391
                $('#form #url').parent().hide();
392
                $('#form #content').parent().show();
393
            } else {
394
                CKEDITOR.instances.content.setData('');
395
 
396
                $('#form #content').parent().hide();
397
                $('#form #url').parent().show();
398
            }
399
        });
400
 
401
        $('button[type="submit"]').click(function(e) {
402
            e.preventDefault();
403
            CKEDITOR.instances.content.updateElement();
404
 
405
            if($('#form').valid()) {
406
 
407
                $.ajax({
408
                    'dataType'  : 'json',
409
                    'accept'    : 'application/json',
410
                    'method'    : 'post',
411
                    'url'       :  $('#form').attr('action'),
15458 efrain 412
                    'data'      :  {
413
                        'code': $('#form #code').val(),
414
                        'title': $('#form #title').val(),
415
                        'type' : $('#form #type').val(),
416
                        'content':$('#form #content').val(),
417
                        'url': $('#form #url').val(),
418
                        'status': $('#form #status').val(),
419
                  }
1 www 420
                }).done(function(response) {
421
                    NProgress.start();
422
                    if(response['success']) {
423
                        $.fn.showSuccess(response['data']);
424
 
15458 efrain 425
                        $('#row-form').hide();
426
                        $('#row-header').show();
427
                        $('#row-list').show();
1 www 428
                         gridTable.api().ajax.reload(null, false);
429
                    } else {
430
                        validator.resetForm();
431
                        if(jQuery.type(response['data']) == 'string') {
432
                            $.fn.showError(response['data']);
433
                        } else  {
434
                            $.each(response['data'], function( fieldname, errors ) {
435
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
436
                            });
437
                        }
438
                    }
439
                }).fail(function( jqXHR, textStatus, errorThrown) {
440
                   $.fn.showError(textStatus);
441
                }).always(function() {
442
                    NProgress.done();
443
                });
444
                return false;
445
 
446
            }
447
        })
448
 
449
 
450
 
451
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
8775 stevensc 452
        CKEDITOR.replace( 'content', {
453
            toolbar: [
454
                    { name: 'editing', items: ['Scayt'] },
455
                    { name: 'links', items: ['Link', 'Unlink'] },
456
                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
457
                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
458
                    '/',
459
                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
460
                    { name: 'styles', items: ['Styles', 'Format'] },
461
                    { name: 'tools', items: ['Maximize'] }
462
                ],
463
                removePlugins: 'elementspath,Anchor',
464
                heigth: 100
465
        });
1 www 466
    });
467
JS;
468
$this->inlineScript()->captureEnd();
469
?>
15572 anderson 470
 
471
 
472
 
1 www 473
<!-- Content Header (Page header) -->
15458 efrain 474
<section class="content-header" id="row-header">
15572 anderson 475
    <div class="container-fluid">
476
        <div class="row mb-2">
477
            <div class="col-sm-12">
478
                <h1>LABEL_PAGES</h1>
479
            </div>
480
        </div>
481
    </div><!-- /.container-fluid -->
1 www 482
</section>
483
 
15458 efrain 484
<section class="content" id="row-list">
15572 anderson 485
    <div class="container-fluid">
486
        <div class="row">
487
            <div class="col-12">
488
                <div class="card">
489
                    <div class="card-body">
490
                        <table id="gridTable" class="table   table-hover">
491
                            <thead>
492
                                <tr>
493
                                    <th>LABEL_ID</th>
494
                                    <th>LABEL_TITLE</th>
495
                                    <th>LABEL_ACTIVE</th>
496
                                    <th>LABEL_ACTIONS</th>
1 www 497
                                </tr>
15572 anderson 498
                            </thead>
499
                            <tbody>
500
                            </tbody>
501
                        </table>
502
                    </div>
503
                    <div class="card-footer clearfix">
504
                        <div style="float:right;">
505
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
506
                            <?php if ($allowAdd) : ?>
507
                                <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
508
                            <?php endif; ?>
509
                        </div>
510
                    </div>
511
                </div>
512
            </div>
513
        </div>
514
    </div>
515
</section>
1 www 516
 
517
 
15458 efrain 518
<section class="content" id="row-form" style="display: none">
15572 anderson 519
    <div class="container-fluid">
520
        <div class="row">
521
            <div class="col-12">
522
                <div class="card">
523
                    <div class="card-header">
524
                        <h4>LABEL_PAGES - <span id="form-title"></span></h4>
525
                    </div>
526
                    <div class="card-body">
527
                        <?php
15458 efrain 528
                        $form = $this->form;
15572 anderson 529
                        $form->setAttributes([
15458 efrain 530
                            'method'    => 'post',
531
                            'name'      => 'form',
532
                            'id'        => 'form'
533
                        ]);
15572 anderson 534
 
15458 efrain 535
                        $form->prepare();
536
                        echo $this->form()->openTag($form);
15572 anderson 537
                        ?>
538
                        <div class="form-group">
539
                            <?php
540
                            $element = $form->get('code');
541
                            $element->setOptions(['label' => 'LABEL_CODE']);
542
                            $element->setAttributes(['class' => 'form-control']);
543
 
544
                            echo $this->formLabel($element);
545
                            echo $this->formText($element);
15458 efrain 546
                            ?>
15572 anderson 547
                        </div>
548
                        <div class="form-group">
549
                            <?php
550
                            $element = $form->get('title');
551
                            $element->setOptions(['label' => 'LABEL_TITLE']);
552
                            $element->setAttributes(['class' => 'form-control']);
553
 
554
                            echo $this->formLabel($element);
555
                            echo $this->formText($element);
1 www 556
                            ?>
15572 anderson 557
                        </div>
558
                        <div class="form-group">
559
                            <?php
560
                            $element = $form->get('type');
561
                            $element->setOptions(['label' => 'LABEL_TYPE']);
562
                            $element->setAttributes(['class' => 'form-control']);
563
 
564
                            echo $this->formLabel($element);
565
                            echo $this->formSelect($element);
1 www 566
                            ?>
15572 anderson 567
                        </div>
568
                        <div class="form-group">
569
                            <?php
570
                            $element = $form->get('content');
571
                            $element->setOptions(['label' => 'LABEL_CONTENT']);
572
                            $element->setAttributes(['class' => 'form-control']);
573
 
574
                            echo $this->formLabel($element);
575
                            echo $this->formTextArea($element);
576
                            ?>
577
                        </div>
578
                        <div class="form-group">
579
                            <?php
580
                            $element = $form->get('url');
581
                            $element->setOptions(['label' => 'LABEL_URL']);
582
                            $element->setAttributes(['class' => 'form-control']);
583
 
584
                            echo $this->formLabel($element);
585
                            echo $this->formText($element);
586
                            ?>
587
                        </div>
588
                        <div class="form-group">
589
                            <?php
590
                            $element = $form->get('status');
591
                            $element->setAttributes(['class' => 'form-control']);
592
                            echo $this->formCheckbox($element);
593
                            ?>
594
                        </div>
595
 
596
                        <div class="form-group">
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 class="card-footer">
603
                    </div>
604
                </div>
605
            </div>
606
        </div>
607
    </div>
608
</section>