Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 20 | Rev 15458 | Ir a la última revisión | | 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
$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
 
16
$typeURL = \LeadersLinked\Model\Page::TYPE_URL;
17
$typePAGE = \LeadersLinked\Model\Page::TYPE_PAGE;
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
 
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 );
149
 
150
                    var json                = {};
151
                    json.recordsTotal       = 0;
152
                    json.recordsFiltered    = 0;
153
                    json.data               = [];
154
 
155
 
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
                    }
163
 
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': 'id' },
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 ) {
242
 
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 = '';
254
 
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></button>&nbsp;';
260
                        }
261
                        return s;
262
                    }
263
                }
264
              ],
265
        });
266
 
267
 
268
        var validator = $('#form').validate({
269
            debug: true,
270
            onclick: false,
271
            onkeyup: false,
272
            ignore: [],
273
            rules: {
274
                'id': {
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');
306
            $('#form #id').val('');
307
            $('#form #id').removeAttr('disabled');
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();
316
            $('#modal').modal('show');
317
        });
318
 
319
        $('body').on('click', 'button.btn-edit', function(e) {
320
            e.preventDefault();
321
            NProgress.start();
322
            var action = $(this).data('href');
323
 
324
            $.ajax({
325
                'dataType'  : 'json',
326
                'accept'    : 'application/json',
327
                'method'    : 'get',
328
                'url'       :  action,
329
            }).done(function(response) {
330
                if(response['success']) {
331
 
332
                    $('span[id="form-title"]').html('LABEL_EDIT');
333
                    $('#form').attr('action', action);
334
                    $('#form #id').val(response['data']['id']);
335
                    $('#form #id').attr('disabled','disabled');
336
                    $('#form #title').val(response['data']['title']);
337
                    $('#form #type').val(response['data']['type']).trigger('change');
338
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
339
 
340
                    var content = $.trim(response['data']['content']);
341
                    CKEDITOR.instances.content.setData(content.length > 0 ? content : '');
342
                    $('#form #url').val(response['data']['url']);
343
 
344
                    validator.resetForm();
345
 
346
                    $('#modal').modal('show');
347
                } else {
348
                    $.fn.showError(response['data']);
349
                }
350
            }).fail(function( jqXHR, textStatus, errorThrown) {
351
                $.fn.showError(textStatus);
352
            }).always(function() {
353
                NProgress.done();
354
            });
355
        });
356
 
357
        $('body').on('click', 'button.btn-refresh', function(e) {
358
            e.preventDefault();
359
            gridTable.api().ajax.reload(null, false);
360
        });
361
 
362
 
363
        $('body').on('click', 'button.btn-cancel', function(e) {
364
            e.preventDefault();
365
            $('#modal').modal('hide');
366
        });
367
 
368
        $('#form #type').select2({
369
            theme: 'bootstrap4',
370
        });
371
 
372
 
373
        $('#form #type').change(function(e) {
374
            e.preventDefault();
375
 
376
            var value = $(this).val();
377
            if(value == '$typePAGE') {
378
                $('#form #url').val('');
379
                $('#form #url').parent().hide();
380
                $('#form #content').parent().show();
381
            } else {
382
                CKEDITOR.instances.content.setData('');
383
 
384
                $('#form #content').parent().hide();
385
                $('#form #url').parent().show();
386
            }
387
        });
388
 
389
        $('button[type="submit"]').click(function(e) {
390
            e.preventDefault();
391
            CKEDITOR.instances.content.updateElement();
392
 
393
            if($('#form').valid()) {
394
 
395
                $.ajax({
396
                    'dataType'  : 'json',
397
                    'accept'    : 'application/json',
398
                    'method'    : 'post',
399
                    'url'       :  $('#form').attr('action'),
400
                    'data'      :  $('#form').serialize()
401
                }).done(function(response) {
402
                    NProgress.start();
403
                    if(response['success']) {
404
                        $.fn.showSuccess(response['data']);
405
 
406
                        $('#modal').modal('hide');
407
                         gridTable.api().ajax.reload(null, false);
408
                    } else {
409
                        validator.resetForm();
410
                        if(jQuery.type(response['data']) == 'string') {
411
                            $.fn.showError(response['data']);
412
                        } else  {
413
                            $.each(response['data'], function( fieldname, errors ) {
414
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
415
                            });
416
                        }
417
                    }
418
                }).fail(function( jqXHR, textStatus, errorThrown) {
419
                   $.fn.showError(textStatus);
420
                }).always(function() {
421
                    NProgress.done();
422
                });
423
                return false;
424
 
425
            }
426
        })
427
 
428
 
429
 
430
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
8775 stevensc 431
        CKEDITOR.replace( 'content', {
432
            toolbar: [
433
                    { name: 'editing', items: ['Scayt'] },
434
                    { name: 'links', items: ['Link', 'Unlink'] },
435
                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
436
                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
437
                    '/',
438
                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
439
                    { name: 'styles', items: ['Styles', 'Format'] },
440
                    { name: 'tools', items: ['Maximize'] }
441
                ],
442
                removePlugins: 'elementspath,Anchor',
443
                heigth: 100
444
        });
1 www 445
    });
446
JS;
447
$this->inlineScript()->captureEnd();
448
?>
449
 
450
 
451
 
452
<!-- Content Header (Page header) -->
453
<section class="content-header">
454
	<div class="container-fluid">
455
    	<div class="row mb-2">
456
        	<div class="col-sm-12">
457
            	<h1>LABEL_PAGES</h1>
458
			</div>
459
		</div>
460
	</div><!-- /.container-fluid -->
461
</section>
462
 
463
<section class="content">
464
	<div class="container-fluid">
465
    	<div class="row">
466
        	<div class="col-12">
467
				<div class="card">
468
					<div class="card-body">
20 steven 469
        	    		<table id="gridTable" class="table   table-hover">
1 www 470
                      		<thead>
471
        						<tr>
472
        							<th>LABEL_ID</th>
473
                                	<th>LABEL_TITLE</th>
474
                                  	<th>LABEL_ACTIVE</th>
475
                                  	<th>LABEL_ACTIONS</th>
476
                                </tr>
477
                       		</thead>
478
                         	<tbody>
479
                         	</tbody>
480
                    	</table>
481
                   	</div>
482
                   	<div class="card-footer clearfix">
483
                   		<div style="float:right;">
484
							<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH  </button>
485
							<?php if($allowAdd) : ?>
486
							<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
487
							<?php endif; ?>
488
						</div>
489
                 	</div>
490
          		</div>
491
           	</div>
492
        </div>
493
 	</div>
494
</section>
495
 
496
<!-- The Modal -->
497
<div class="modal" id="modal">
498
	<div class="modal-dialog  modal-xl">
499
    	<div class="modal-content">
500
 
501
            <!-- Modal Header -->
502
      		<div class="modal-header">
503
        		<h4 class="modal-title">LABEL_PAGES - <span id="form-title"></span></h4>
504
        		<button type="button" class="close" data-dismiss="modal">&times;</button>
505
      		</div>
506
 
507
            <!-- Modal body -->
508
      		<div class="modal-body">
509
       			 <?php
510
                    $form = $this->form;
511
            		$form->setAttributes([
512
                        'method'    => 'post',
513
                        'name'      => 'form',
514
                        'id'        => 'form'
515
                    ]);
516
 
517
                    $form->prepare();
518
                    echo $this->form()->openTag($form);
519
                    ?>
520
                       	<div class="form-group">
521
        					<?php
522
                            $element = $form->get('id');
523
                            $element->setOptions(['label' => 'LABEL_ID']);
524
                            $element->setAttributes(['class' => 'form-control']);
525
 
526
                            echo $this->formLabel($element);
527
                            echo $this->formText($element);
528
                            ?>
529
						</div>
530
    					<div class="form-group">
531
        					<?php
532
                            $element = $form->get('title');
533
                            $element->setOptions(['label' => 'LABEL_TITLE']);
534
                            $element->setAttributes(['class' => 'form-control']);
535
 
536
                            echo $this->formLabel($element);
537
                            echo $this->formText($element);
538
                            ?>
539
						</div>
540
						<div class="form-group">
541
                      	<?php
542
                            $element = $form->get('type');
543
                            $element->setOptions(['label' => 'LABEL_TYPE']);
544
                            $element->setAttributes(['class' => 'form-control']);
545
 
546
                            echo $this->formLabel($element);
547
                            echo $this->formSelect($element);
548
                        ?>
549
						</div>
550
						<div class="form-group">
551
                    	<?php
552
                            $element = $form->get('content');
553
                            $element->setOptions(['label' => 'LABEL_CONTENT']);
554
                            $element->setAttributes(['class' => 'form-control']);
555
 
556
                            echo $this->formLabel($element);
557
                            echo $this->formTextArea($element);
558
                        ?>
559
						</div>
560
						<div class="form-group">
561
        					<?php
562
                            $element = $form->get('url');
563
                            $element->setOptions(['label' => 'LABEL_URL']);
564
                            $element->setAttributes(['class' => 'form-control']);
565
 
566
                            echo $this->formLabel($element);
567
                            echo $this->formText($element);
568
                            ?>
569
						</div>
570
						<div class="form-group">
571
                      	<?php
572
                            $element = $form->get('status');
573
                            $element->setAttributes(['class' => 'form-control']);
574
                            echo $this->formCheckbox($element);
575
                        ?>
576
						</div>
577
 
578
        				<div class="form-group">
579
                    		<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
580
                    		<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
581
                   		</div>
582
     	      		<?php echo $this->form()->closeTag($form); ?>
583
      		</div>
584
 
585
            <!-- Modal footer -->
586
      		<div class="modal-footer">
587
        		<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
588
      		</div>
589
 
590
    	</div>
591
	</div>
592
</div>
593
 
594
 
595
 
596
 
597
 
598
 
599
 
600
 
601
 
602
 
603
 
604
 
605