Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16994 | | Comparar con el anterior | 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
 
16822 efrain 16
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
17
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
66 efrain 18
 
16822 efrain 19
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
20
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));
66 efrain 21
 
16822 efrain 22
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
23
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
24
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
25
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));
66 efrain 26
 
27
 
16822 efrain 28
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
29
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
66 efrain 30
 
31
 
32
 
33
 
34
 
35
 
36
 
16822 efrain 37
$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));
38
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-input-number/input-number-format.jquery.js'));
66 efrain 39
 
40
 
41
 
16822 efrain 42
 
43
 
44
 
16929 efrain 45
 
46
 
47
 
66 efrain 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();
16822 efrain 133
 
66 efrain 134
            },
135
            'aoColumns': [
136
                { 'mDataProp': 'name' },
137
                { 'mDataProp': 'details' },
138
                { 'mDataProp': 'actions' },
139
    	    ],
140
            'columnDefs': [
141
                {
142
                    'targets': 0,
143
                    'className' : 'text-vertical-middle',
144
                    'render' : function ( data, type, row ) {
145
                        var s = data;
146
                        if(allowQuestion && row['actions']['link_question']  ) {
16932 efrain 147
                            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-alt"></i> LABEL_QUESTIONS </button';
66 efrain 148
                        }
149
 
150
                        return s;
151
 
152
 
153
                     }
154
                },
155
                {
156
                    'targets': 1,
157
                    'orderable': false,
158
                    'render' : function ( data, type, row ) {
159
                        var s = 'LABEL_STATUS : ' + row['details']['status'] + '<br>';
160
                        s = s + 'LABEL_VERIFICATION : ' + row['details']['check'] + '<br>';
161
                        if(allowCheck && row['actions']['link_check']  ) {
16994 efrain 162
                            s = s + '<button class="btn btn-info btn-sm btn-quizz-check" data-href="' + row['actions']['link_check']+ '" data-toggle="tooltip" title="LABEL_CHECK"><i class="fa fa-check"></i> LABEL_CHECK </button><br>';
66 efrain 163
                        }
164
                        s = s + 'LABEL_POINTS : ' + row['details']['points'] + '<br>';
165
                        s = s + 'LABEL_MINUTES : ' + row['details']['max_time'] + '<br>';
166
                        s = s + 'LABEL_SLIDES  : ' + row['details']['slides'] + '<br>';
167
 
168
 
169
                        return s;
170
                    }
171
                },
172
 
173
                {
174
                    'targets': -1,
175
                    'orderable': false,
176
                    'render' : function ( data, type, row ) {
177
                        s = '';
178
 
179
                        if(allowEdit && data['link_edit']  ) {
16906 efrain 180
                            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-pen"></i> LABEL_EDIT </button>&nbsp;';
66 efrain 181
                        }
182
                        if(allowDelete && data['link_delete']  ) {
183
                            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;';
184
                        }
185
                        if(allowCopy && data['link_copy']  ) {
186
                            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;';
187
                        }
188
 
189
                        return s;
190
                    }
191
                }
192
              ],
193
        });
194
 
195
 
196
 
197
 
198
 
199
        $.validator.setDefaults({
200
            debug: true,
201
            highlight: function(element) {
202
                $(element).addClass('is-invalid');
203
            },
204
            unhighlight: function(element) {
205
                $(element).removeClass('is-invalid');
206
            },
207
            errorElement: 'span',
208
            errorClass: 'error invalid-feedback',
209
            errorPlacement: function(error, element) {
210
                if(element.parent('.btn-file').length) {
211
                    error.insertAfter(element.parent().parent());
212
                } else if(element.parent('.toggle').length) {
213
                    error.insertAfter(element.parent().parent());
214
                } else {
215
                    error.insertAfter(element.parent());
216
                }
217
            }
218
        });
219
 
220
 
221
 
222
    var validator = $('#form').validate({
223
        debug: true,
224
        onclick: false,
225
        onkeyup: false,
226
        ignore: [],
227
        rules: {
228
            'name': {
229
                required: true,
230
                maxlength: 128,
231
            },
232
            'points' : {
233
                required: true,
234
                digits: true,
235
                min: 1,
236
                max: 100
237
            },
238
            'status' : {
239
                required: true,
240
            },
241
            'minimum_points_required' : {
242
                 required: true,
243
                digits: true,
244
                min: 1,
245
                lessThan: '#points'
246
            }
247
        },
248
        submitHandler: function(form)
249
        {
250
            $('input[type="submit"]').prop('disabled', true);
251
 
252
            $.ajax({
253
                'dataType'  : 'json',
254
                'accept'    : 'application/json',
255
                'method'    : 'post',
256
                'url'       :  $('#form').attr('action'),
257
                'data'      :  $('#form').serialize(),
258
            }).done(function(response) {
259
                if(response['success']) {
260
                    $.fn.showSuccess(response['data']);
261
 
262
                    $('#modal-form').modal('hide');
263
                    gridTable.api().ajax.reload(null, false);
264
                } else {
265
                    validator.resetForm();
266
                    if(jQuery.type(response['data']) == 'string') {
267
                        $.fn.showError(response['data']);
268
                    } else  {
269
                        $.each(response['data'], function( fieldname, errors ) {
270
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
271
                        });
272
                    }
273
                }
274
            }).fail(function( jqXHR, textStatus, errorThrown) {
275
                $.fn.showError(textStatus);
276
            }).always(function() {
277
                NProgress.done();
278
            });
279
            return false;
280
        },
281
        invalidHandler: function(form, validator) {
282
 
283
        }
284
    });
285
 
286
    $('body').on('click', 'button.btn-question', function(e) {
287
        e.preventDefault();
288
        NProgress.start();
289
        var action = $(this).data('href');
290
        window.location.href = action;
291
    });
292
 
16993 efrain 293
    $('body').on('click', 'button.btn-refresh', function(e) {
294
        e.preventDefault();
295
        gridTable.api().ajax.reload(null, false);
296
    });
66 efrain 297
 
16993 efrain 298
 
66 efrain 299
    $('body').on('click', 'button.btn-add', function(e) {
300
        e.preventDefault();
301
 
16840 efrain 302
 
66 efrain 303
        $('#form').attr('action', '$routeAdd');
304
        $('#form #name').val('');
305
        $('#form #status').val('');
306
        $('#form #points').val('');
307
        $('#form #minimum_points_required').val('');
308
        $('#form #max_time').val('');
309
 
310
        validator.resetForm();
311
 
312
        $('#modal-form').modal('show');
313
        return false;
314
    });
315
 
316
 
317
 
318
    $('body').on('click', 'button.btn-edit', function(e) {
319
        e.preventDefault();
320
        NProgress.start();
321
        var action = $(this).data('href');
322
 
323
        $.ajax({
324
            'dataType'  : 'json',
325
            'accept'    : 'application/json',
326
            'method'    : 'get',
327
            'url'       :  action,
328
        }).done(function(response) {
329
            if(response['success']) {
16840 efrain 330
 
66 efrain 331
                $('#form').attr('action', action);
332
                $('#form #name').val(response['data']['name']);
333
                $('#form #status').val(response['data']['status']);
334
                $('#form #points').val(response['data']['points']);
335
                $('#form #minimum_points_required').val(response['data']['minimum_points_required']);
336
                $('#form #max_time').val(response['data']['max_time']);
337
 
338
                validator.resetForm();
339
 
340
                $('#modal-form').modal('show');
341
                return false;
342
            } else {
343
                $.fn.showError(response['data']);
344
             }
345
        }).fail(function( jqXHR, textStatus, errorThrown) {
346
            $.fn.showError(textStatus);
347
        }).always(function() {
348
            NProgress.done();
349
        });
350
    });
351
 
16994 efrain 352
    $('body').on('click', 'button.btn-quizz-check', function(e) {
66 efrain 353
        e.preventDefault();
354
        NProgress.start();
355
        var action = $(this).data('href');
356
 
357
        $.ajax({
358
            'dataType'  : 'json',
359
            'accept'    : 'application/json',
360
            'method'    : 'post',
361
            'url'       :  action,
362
        }).done(function(response) {
363
            if(response['success']) {
364
                $.fn.showSuccess(response['data']);
365
            } else {
366
                $.fn.showError(response['data']);
367
            }
368
            gridTable.api().ajax.reload(null, false);
369
        }).fail(function( jqXHR, textStatus, errorThrown) {
370
            $.fn.showError(textStatus);
371
        }).always(function() {
372
            NProgress.done();
373
        });
374
    });
375
 
376
    $('body').on('click', 'button.btn-copy', function(e) {
377
        e.preventDefault();
378
        NProgress.start();
379
        var action = $(this).data('href');
380
 
381
        $.ajax({
382
            'dataType'  : 'json',
383
            'accept'    : 'application/json',
384
            'method'    : 'post',
385
            'url'       :  action,
386
        }).done(function(response) {
387
            if(response['success']) {
388
                $.fn.showSuccess(response['data']);
389
            } else {
390
                $.fn.showError(response['data']);
391
            }
392
            gridTable.api().ajax.reload(null, false);
393
        }).fail(function( jqXHR, textStatus, errorThrown) {
394
            $.fn.showError(textStatus);
395
        }).always(function() {
396
            NProgress.done();
397
        });
398
    });
399
 
16822 efrain 400
    $('body').on('click', 'button.btn-delete', function(e) {
401
        e.preventDefault();
402
        var action = $(this).data('href');
66 efrain 403
 
404
 
16822 efrain 405
          swal.fire({
406
            title: 'LABEL_ARE_YOU_SURE',
407
            icon: 'question',
408
            cancelButtonText: 'LABEL_NO',
409
            showCancelButton: true,
410
            confirmButtonText: 'LABEL_YES'
411
          }).then((result) => {
412
            if (result.isConfirmed) {
413
 
414
                    NProgress.start();
415
                    $.ajax({
416
                        'dataType'  : 'json',
417
                        'accept'    : 'application/json',
418
                        'method'    : 'post',
419
                        'url'       :  action,
420
                    }).done(function(response) {
421
                        if(response['success']) {
422
                            $.fn.showSuccess(response['data']);
423
                            gridTable.api().ajax.reload(null, false);
424
                        } else {
425
                            $.fn.showError(response['data']);
426
                        }
427
                    }).fail(function( jqXHR, textStatus, errorThrown) {
428
                        $.fn.showError(textStatus);
429
                    }).always(function() {
430
                        NProgress.done();
431
                    });
432
            }
433
       });
434
    });
435
 
436
 
66 efrain 437
    $('#form #points').inputNumberFormat({decimal: 0});
438
    $('#form #minimum_points_required').inputNumberFormat({decimal: 0});
439
 
440
});
441
JS;
442
$this->inlineScript()->captureEnd();
443
?>
444
 
16910 efrain 445
<div class="container">
446
	<div class="card" id="">
447
	 	<div class="card-header">
448
	 		<h6 class="card-title">LABEL_QUIZZES</h6>
449
	 	</div>
450
	 	<div class="card-body">
451
	 		<div class="row">
452
	 	         <div class="col-12 mt-3">
453
 
454
	 	         <table id="gridTable" class="table   table-bordered">
66 efrain 455
                      		<thead>
456
        						<tr>
457
                                	<th>LABEL_NAME</th>
458
                                  	<th>LABEL_DETAILS</th>
459
                                  	<th>LABEL_ACTIONS</th>
460
                                </tr>
461
                       		</thead>
462
                         	<tbody>
463
                         	</tbody>
464
                    	</table>
16910 efrain 465
 
466
	 	         </div>
467
	 	     </div>
468
	 	</div>
469
	 	<div class="card-footer text-right">
16992 efrain 470
							<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH  </button>
66 efrain 471
							<?php if($allowAdd) : ?>
472
							<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
473
							<?php endif; ?>
16910 efrain 474
	 	</div>
475
	</div>
476
</div>
66 efrain 477
 
478
 
479
 
480
 
481
 
16910 efrain 482
 
483
 
66 efrain 484
<div class="modal" tabindex="-1" role="dialog" id="modal-form">
485
	<div class="modal-dialog  modal-lg">
486
    	<div class="modal-content">
487
		<?php
488
	    $form = $this->form;
489
	    $form->setAttributes([
490
	       'method'    => 'post',
491
	        'name'      => 'form',
492
	        'id'        => 'form'
493
	    ]);
494
	    $form->prepare();
495
	    echo $this->form()->openTag($form);
496
	    ?>
497
    	<div class="modal-content">
498
      		<div class="modal-header">
16935 efrain 499
        		<h6 class="modal-title" ><span id="form-title">LABEL_ADD</span></h6>
66 efrain 500
      		</div>
501
      		<div class="modal-body">
16910 efrain 502
    	 		<div class="row">
503
    	 	         <div class="col-12 mt-3">
504
        				<?php
505
                            $element = $form->get('name');
506
                            $element->setAttributes(['class' => 'form-control']);
507
                            $element->setOptions(['label' => 'LABEL_NAME']);
508
                            echo $this->formLabel($element);
509
                            echo $this->formText($element);
510
                        ?>
511
    				</div>
512
    			</div>
513
    	 		<div class="row">
514
    	 	         <div class="col-12 mt-3">
515
        				<?php
516
        				    $element = $form->get('status');
517
        				    $element->setAttributes(['class' => 'form-control']);
518
                            $element->setOptions(['label' => 'LABEL_STATUS']);
519
                            echo $this->formLabel($element);
520
                            echo $this->formSelect($element);
521
                        ?>
522
    				</div>
523
    	 		<div class="row">
524
	 	         <div class="col-12 mt-3">
66 efrain 525
    				<?php
526
                        $element = $form->get('points');
527
                        $element->setAttributes(['class' => 'form-control']);
528
                        $element->setOptions(['label' => 'LABEL_POINTS']);
529
                        echo $this->formLabel($element);
530
                        echo $this->formText($element);
531
                    ?>
16910 efrain 532
                    </div>
66 efrain 533
				</div>
16910 efrain 534
    	 		<div class="row">
535
    	 	         <div class="col-12 mt-3">
66 efrain 536
    				<?php
537
                        $element = $form->get('minimum_points_required');
538
                        $element->setAttributes(['class' => 'form-control']);
539
                        $element->setOptions(['label' => 'LABEL_MINIMUM_POINTS_REQUIRED']);
540
                        echo $this->formLabel($element);
541
                        echo $this->formText($element);
542
                    ?>
16910 efrain 543
                    </div>
66 efrain 544
				</div>
16910 efrain 545
    	 		<div class="row">
546
    	 	         <div class="col-12 mt-3">
547
        				<?php
548
                            $element = $form->get('max_time');
549
                            $element->setAttributes(['class' => 'form-control']);
550
                             $element->setOptions(['label' => 'LABEL_MAX_TIME_QUIZ']);
551
                            echo $this->formLabel($element);
552
                            echo $this->formText($element);
553
                        ?>
554
    				</div>
66 efrain 555
				</div>
556
          	</div>
557
 
16891 efrain 558
         	<div class="modal-footer text-right">
66 efrain 559
    			<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
16822 efrain 560
    			 <button type="button" class="btn btn-light" data-bs-dismiss="modal">LABEL_CLOSE</button>
66 efrain 561
          	</div>
562
      	<?php echo $this->form()->closeTag($form); ?>
563
    	</div>
564
 
565
		</div>
566
	</div>
567
</div>
568
 
569