Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16822 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
66 efrain 1
<?php
2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
$roleName       = $currentUser->getUserTypeId();
5
 
6
$routeAdd           = $this->url('microlearning/content/quizzes/add');
7
$routeDatatable    = $this->url('microlearning/content/quizzes');
8
 
9
$allowAdd = $acl->isAllowed($roleName, 'microlearning/content/quizzes/add') ? 1 : 0;
10
$allowEdit = $acl->isAllowed($roleName, 'microlearning/content/quizzes/edit') ? 1 : 0;
11
$allowDelete = $acl->isAllowed($roleName, 'microlearning/content/quizzes/delete') ? 1 : 0;
12
$allowCopy = $acl->isAllowed($roleName, 'microlearning/content/quizzes/copy') ? 1 : 0;
13
$allowCheck = $acl->isAllowed($roleName, 'microlearning/content/quizzes/check') ? 1 : 0;
14
$allowQuestion = $acl->isAllowed($roleName, 'microlearning/content/quizzes/questions') ? 1 : 0;
15
 
16
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
17
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
18
 
19
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
20
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
21
 
22
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
23
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
24
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
25
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
26
 
27
 
28
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
29
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
30
 
31
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
32
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
33
 
34
 
35
 
36
 
37
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
38
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
39
 
40
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
41
 
42
 
43
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
44
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
45
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
46
 
47
 
48
$this->inlineScript()->captureStart();
49
echo <<<JS
50
 
51
 
52
 
53
    var allowAdd = $allowAdd;
54
    var allowEdit = $allowEdit;
55
    var allowDelete = $allowDelete;
56
    var allowCopy = $allowCopy;
57
    var allowCheck = $allowCheck;
58
    var allowQuestion = $allowQuestion;
59
 
60
 
61
 
62
    jQuery( document ).ready(function( $ ) {
63
        $.validator.addMethod('lessThan', function (value, element, param) {
64
            var otherElement = $(param);
65
            return parseInt(value, 10) < parseInt(otherElement.val(), 10);
66
        },
67
        'ERROR_INVALID_MAXIMUM'
68
    );
69
 
70
    var gridTable = $('#gridTable').dataTable( {
71
            'processing': true,
72
            'serverSide': true,
73
            'searching': true,
74
            'order': [[ 0, 'asc' ]],
75
            'ordering':  true,
76
            'ordenable' : true,
77
            'responsive': true,
78
            'select' : false,
79
        	'paging': true,
80
            'pagingType': 'simple_numbers',
81
    		'ajax': {
82
    			'url' : '$routeDatatable',
83
    			'type' : 'get',
84
                'beforeSend': function (request) {
85
                  NProgress.start();
86
                },
87
                'dataFilter': function(response) {
88
                    var response = jQuery.parseJSON( response );
89
 
90
                    var json                = {};
91
                    json.recordsTotal       = 0;
92
                    json.recordsFiltered    = 0;
93
                    json.data               = [];
94
 
95
 
96
                    if(response.success) {
97
                        json.recordsTotal       = response.data.total;
98
                        json.recordsFiltered    = response.data.total;
99
                        json.data               = response.data.items;
100
                    } else {
101
                        $.fn.showError(response.data)
102
                    }
103
 
104
                    return JSON.stringify( json );
105
                }
106
    		},
107
            'language' : {
108
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
109
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
110
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
111
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
112
                'sInfo':           'LABEL_DATATABLE_SINFO',
113
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
114
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
115
                'sInfoPostFix':    '',
116
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
117
                'sUrl':            '',
118
                'sInfoThousands':  ',',
119
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
120
                'oPaginate': {
121
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
122
                    'sLast':     'LABEL_DATATABLE_SLAST',
123
                    'sNext':     'LABEL_DATATABLE_SNEXT',
124
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
125
                },
126
                'oAria': {
127
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
128
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
129
                },
130
            },
131
            'drawCallback': function( settings ) {
132
                NProgress.done();
133
                $('button.btn-delete').confirmation({
134
                    rootSelector: 'button.btn-delete',
135
                    title : 'LABEL_ARE_YOU_SURE',
136
                    singleton : true,
137
                    btnOkLabel: 'LABEL_YES',
138
                    btnCancelLabel: 'LABEL_NO',
139
                    onConfirm: function(value) {
140
                        action = $(this).data('href');
141
                        NProgress.start();
142
                        $.ajax({
143
                            'dataType'  : 'json',
144
                            'accept'    : 'application/json',
145
                            'method'    : 'post',
146
                            'url'       :  action,
147
                        }).done(function(response) {
148
                            if(response['success']) {
149
                                $.fn.showSuccess(response['data']);
150
                                gridTable.api().ajax.reload(null, false);
151
                            } else {
152
                                $.fn.showError(response['data']);
153
                            }
154
                        }).fail(function( jqXHR, textStatus, errorThrown) {
155
                            $.fn.showError(textStatus);
156
                        }).always(function() {
157
                            NProgress.done();
158
                        });
159
                    },
160
                });
161
            },
162
            'aoColumns': [
163
                { 'mDataProp': 'name' },
164
                { 'mDataProp': 'details' },
165
                { 'mDataProp': 'actions' },
166
    	    ],
167
            'columnDefs': [
168
                {
169
                    'targets': 0,
170
                    'className' : 'text-vertical-middle',
171
                    'render' : function ( data, type, row ) {
172
                        var s = data;
173
                        if(allowQuestion && row['actions']['link_question']  ) {
174
                            s = s + '<br><button class="btn btn-info btn-sm btn-question" data-href="' + row['actions']['link_question']+ '" data-toggle="tooltip" title="LABEL_QUESTIONS"><i class="fa fa-external-link"></i> LABEL_QUESTIONS </button';
175
                        }
176
 
177
                        return s;
178
 
179
 
180
                     }
181
                },
182
                {
183
                    'targets': 1,
184
                    'orderable': false,
185
                    'render' : function ( data, type, row ) {
186
                        var s = 'LABEL_STATUS : ' + row['details']['status'] + '<br>';
187
                        s = s + 'LABEL_VERIFICATION : ' + row['details']['check'] + '<br>';
188
                        if(allowCheck && row['actions']['link_check']  ) {
189
                            s = s + '<button class="btn btn-info btn-sm btn-check" data-href="' + row['actions']['link_check']+ '" data-toggle="tooltip" title="LABEL_CHECK"><i class="fa fa-check"></i> LABEL_CHECK </button><br>';
190
                        }
191
                        s = s + 'LABEL_POINTS : ' + row['details']['points'] + '<br>';
192
                        s = s + 'LABEL_MINUTES : ' + row['details']['max_time'] + '<br>';
193
                        s = s + 'LABEL_SLIDES  : ' + row['details']['slides'] + '<br>';
194
 
195
 
196
                        return s;
197
                    }
198
                },
199
 
200
                {
201
                    'targets': -1,
202
                    'orderable': false,
203
                    'render' : function ( data, type, row ) {
204
                        s = '';
205
 
206
                        if(allowEdit && data['link_edit']  ) {
207
                            s = s + '<button class="btn btn-info btn-sm btn-edit" data-href="' + data['link_edit']+ '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
208
                        }
209
                        if(allowDelete && data['link_delete']  ) {
210
                            s = s + '<button class="btn btn-danger btn-sm btn-delete" data-href="' + data['link_delete']+ '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
211
                        }
212
                        if(allowCopy && data['link_copy']  ) {
213
                            s = s + '<button class="btn btn-info btn-sm btn-copy" data-href="' + data['link_copy']+ '" data-toggle="tooltip" title="LABEL_COPY"><i class="fa fa-files-o"></i> LABEL_COPY </button>&nbsp;';
214
                        }
215
 
216
 
217
                        return s;
218
                    }
219
                }
220
              ],
221
        });
222
 
223
 
224
 
225
 
226
 
227
        $.validator.setDefaults({
228
            debug: true,
229
            highlight: function(element) {
230
                $(element).addClass('is-invalid');
231
            },
232
            unhighlight: function(element) {
233
                $(element).removeClass('is-invalid');
234
            },
235
            errorElement: 'span',
236
            errorClass: 'error invalid-feedback',
237
            errorPlacement: function(error, element) {
238
                if(element.parent('.btn-file').length) {
239
                    error.insertAfter(element.parent().parent());
240
                } else if(element.parent('.toggle').length) {
241
                    error.insertAfter(element.parent().parent());
242
                } else {
243
                    error.insertAfter(element.parent());
244
                }
245
            }
246
        });
247
 
248
 
249
        $.fn.showFormErrorValidator = function(fieldname, errors) {
250
            var field = $(fieldname);
251
            if(field) {
252
                $(field).addClass('is-invalid');
253
 
254
 
255
                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
256
                if(element.parent('.btn-file').length) {
257
                    error.insertAfter(element.parent().parent());
258
                } else if(element.parent('.toggle').length) {
259
                    error.insertAfter(element.parent().parent());
260
                } else {
261
                    error.insertAfter(element.parent());
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
            'name': {
275
                required: true,
276
                maxlength: 128,
277
            },
278
            'points' : {
279
                required: true,
280
                digits: true,
281
                min: 1,
282
                max: 100
283
            },
284
            'status' : {
285
                required: true,
286
            },
287
            'minimum_points_required' : {
288
                 required: true,
289
                digits: true,
290
                min: 1,
291
                lessThan: '#points'
292
            }
293
        },
294
        submitHandler: function(form)
295
        {
296
            $('input[type="submit"]').prop('disabled', true);
297
 
298
            $.ajax({
299
                'dataType'  : 'json',
300
                'accept'    : 'application/json',
301
                'method'    : 'post',
302
                'url'       :  $('#form').attr('action'),
303
                'data'      :  $('#form').serialize(),
304
            }).done(function(response) {
305
                if(response['success']) {
306
                    $.fn.showSuccess(response['data']);
307
 
308
                    $('#modal-form').modal('hide');
309
                    gridTable.api().ajax.reload(null, false);
310
                } else {
311
                    validator.resetForm();
312
                    if(jQuery.type(response['data']) == 'string') {
313
                        $.fn.showError(response['data']);
314
                    } else  {
315
                        $.each(response['data'], function( fieldname, errors ) {
316
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
317
                        });
318
                    }
319
                }
320
            }).fail(function( jqXHR, textStatus, errorThrown) {
321
                $.fn.showError(textStatus);
322
            }).always(function() {
323
                NProgress.done();
324
            });
325
            return false;
326
        },
327
        invalidHandler: function(form, validator) {
328
 
329
        }
330
    });
331
 
332
    $('body').on('click', 'button.btn-question', function(e) {
333
        e.preventDefault();
334
        NProgress.start();
335
        var action = $(this).data('href');
336
        window.location.href = action;
337
    });
338
 
339
 
340
    $('body').on('click', 'button.btn-add', function(e) {
341
        e.preventDefault();
342
 
343
        $('span[id="form-title"]').html('LABEL_ADD');
344
        $('#form').attr('action', '$routeAdd');
345
        $('#form #name').val('');
346
        $('#form #status').val('');
347
        $('#form #points').val('');
348
        $('#form #minimum_points_required').val('');
349
        $('#form #max_time').val('');
350
 
351
        validator.resetForm();
352
 
353
        $('#modal-form').modal('show');
354
        return false;
355
    });
356
 
357
 
358
 
359
    $('body').on('click', 'button.btn-edit', function(e) {
360
        e.preventDefault();
361
        NProgress.start();
362
        var action = $(this).data('href');
363
 
364
        $.ajax({
365
            'dataType'  : 'json',
366
            'accept'    : 'application/json',
367
            'method'    : 'get',
368
            'url'       :  action,
369
        }).done(function(response) {
370
            if(response['success']) {
371
                $('span[id="form-title"]').html('LABEL_EDIT');
372
                $('#form').attr('action', action);
373
                $('#form #name').val(response['data']['name']);
374
                $('#form #status').val(response['data']['status']);
375
                $('#form #points').val(response['data']['points']);
376
                $('#form #minimum_points_required').val(response['data']['minimum_points_required']);
377
                $('#form #max_time').val(response['data']['max_time']);
378
 
379
                validator.resetForm();
380
 
381
                $('#modal-form').modal('show');
382
                return false;
383
            } else {
384
                $.fn.showError(response['data']);
385
             }
386
        }).fail(function( jqXHR, textStatus, errorThrown) {
387
            $.fn.showError(textStatus);
388
        }).always(function() {
389
            NProgress.done();
390
        });
391
    });
392
 
393
    $('body').on('click', 'button.btn-check', function(e) {
394
        e.preventDefault();
395
        NProgress.start();
396
        var action = $(this).data('href');
397
 
398
        $.ajax({
399
            'dataType'  : 'json',
400
            'accept'    : 'application/json',
401
            'method'    : 'post',
402
            'url'       :  action,
403
        }).done(function(response) {
404
            if(response['success']) {
405
                $.fn.showSuccess(response['data']);
406
            } else {
407
                $.fn.showError(response['data']);
408
            }
409
            gridTable.api().ajax.reload(null, false);
410
        }).fail(function( jqXHR, textStatus, errorThrown) {
411
            $.fn.showError(textStatus);
412
        }).always(function() {
413
            NProgress.done();
414
        });
415
    });
416
 
417
    $('body').on('click', 'button.btn-copy', function(e) {
418
        e.preventDefault();
419
        NProgress.start();
420
        var action = $(this).data('href');
421
 
422
        $.ajax({
423
            'dataType'  : 'json',
424
            'accept'    : 'application/json',
425
            'method'    : 'post',
426
            'url'       :  action,
427
        }).done(function(response) {
428
            if(response['success']) {
429
                $.fn.showSuccess(response['data']);
430
            } else {
431
                $.fn.showError(response['data']);
432
            }
433
            gridTable.api().ajax.reload(null, false);
434
        }).fail(function( jqXHR, textStatus, errorThrown) {
435
            $.fn.showError(textStatus);
436
        }).always(function() {
437
            NProgress.done();
438
        });
439
    });
440
 
441
 
442
 
443
    $('#form #points').inputNumberFormat({decimal: 0});
444
    $('#form #minimum_points_required').inputNumberFormat({decimal: 0});
445
 
446
});
447
JS;
448
$this->inlineScript()->captureEnd();
449
?>
450
 
451
<!-- Content Header (Page header) -->
452
<section class="content-header">
453
	<div class="container-fluid">
454
    	<div class="row mb-2">
455
        	<div class="col-sm-12">
456
            	<h1>LABEL_QUIZZES</h1>
457
			</div>
458
		</div>
459
	</div><!-- /.container-fluid -->
460
</section>
461
 
462
<section class="content">
463
	<div class="container-fluid">
464
    	<div class="row">
465
        	<div class="col-12">
466
				<div class="card">
467
					<div class="card-body">
468
        	    		<table id="gridTable" class="table   table-hover">
469
                      		<thead>
470
        						<tr>
471
                                	<th>LABEL_NAME</th>
472
                                  	<th>LABEL_DETAILS</th>
473
                                  	<th>LABEL_ACTIONS</th>
474
                                </tr>
475
                       		</thead>
476
                         	<tbody>
477
                         	</tbody>
478
                    	</table>
479
                   	</div>
480
                   	<div class="card-footer clearfix">
481
                   		<div style="float:right;">
482
							<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH  </button>
483
							<?php if($allowAdd) : ?>
484
							<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
485
							<?php endif; ?>
486
						</div>
487
                 	</div>
488
          		</div>
489
           	</div>
490
        </div>
491
 	</div>
492
</section>
493
 
494
 
495
 
496
 
497
 
498
<div class="modal" tabindex="-1" role="dialog" id="modal-form">
499
	<div class="modal-dialog  modal-lg">
500
    	<div class="modal-content">
501
		<?php
502
	    $form = $this->form;
503
	    $form->setAttributes([
504
	       'method'    => 'post',
505
	        'name'      => 'form',
506
	        'id'        => 'form'
507
	    ]);
508
	    $form->prepare();
509
	    echo $this->form()->openTag($form);
510
	    ?>
511
    	<div class="modal-content">
512
      		<div class="modal-header">
513
        		<h3 class="modal-title" ><span id="form-title">LABEL_ADD</span></h3>
514
      		</div>
515
      		<div class="modal-body">
516
      			<div class="form-group">
517
    				<?php
518
                        $element = $form->get('name');
519
                        $element->setAttributes(['class' => 'form-control']);
520
                        $element->setOptions(['label' => 'LABEL_NAME']);
521
                        echo $this->formLabel($element);
522
                        echo $this->formText($element);
523
                    ?>
524
				</div>
525
				<div class="form-group">
526
    				<?php
527
    				    $element = $form->get('status');
528
    				    $element->setAttributes(['class' => 'form-control']);
529
                        $element->setOptions(['label' => 'LABEL_STATUS']);
530
                        echo $this->formLabel($element);
531
                        echo $this->formSelect($element);
532
                    ?>
533
				</div>
534
				<div class="form-group">
535
    				<?php
536
                        $element = $form->get('points');
537
                        $element->setAttributes(['class' => 'form-control']);
538
                        $element->setOptions(['label' => 'LABEL_POINTS']);
539
                        echo $this->formLabel($element);
540
                        echo $this->formText($element);
541
                    ?>
542
				</div>
543
				<div class="form-group">
544
    				<?php
545
                        $element = $form->get('minimum_points_required');
546
                        $element->setAttributes(['class' => 'form-control']);
547
                        $element->setOptions(['label' => 'LABEL_MINIMUM_POINTS_REQUIRED']);
548
                        echo $this->formLabel($element);
549
                        echo $this->formText($element);
550
                    ?>
551
				</div>
552
				<div class="form-group">
553
    				<?php
554
                        $element = $form->get('max_time');
555
                        $element->setAttributes(['class' => 'form-control']);
556
                         $element->setOptions(['label' => 'LABEL_MAX_TIME_QUIZ']);
557
                        echo $this->formLabel($element);
558
                        echo $this->formText($element);
559
                    ?>
560
				</div>
561
          	</div>
562
 
563
         	<div class="modal-footer">
564
    			<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
565
    			<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
566
          	</div>
567
      	<?php echo $this->form()->closeTag($form); ?>
568
    	</div>
569
 
570
		</div>
571
	</div>
572
</div>
573
 
574