Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16993 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
66 efrain 1
<?php
2
use LeadersLinked\Library\Functions;
17003 efrain 3
use LeadersLinked\Model\MicrolearningQuiz;
66 efrain 4
 
5
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
6
$currentUser    = $this->currentUserHelper();
7
$roleName       = $currentUser->getUserTypeId();
8
 
9
$params = [
10
    'quiz_id' => $quiz_uuid,
11
    'question_id' => $question_uuid
12
];
13
 
14
$routeAdd       = $this->url('microlearning/content/quizzes/questions/answers/add', $params);
15
$routeDatatable = $this->url('microlearning/content/quizzes/questions/answers', $params);
16992 efrain 16
$routeRegresar = $this->url('microlearning/content/quizzes/questions', ['quiz_id' => $quiz_uuid]);
66 efrain 17
 
18
$allowAdd = $acl->isAllowed($roleName, 'microlearning/content/quizzes/questions/answers/add') ? 1 : 0;
19
$allowEdit = $acl->isAllowed($roleName, 'microlearning/content/quizzes/questions/answers/edit') ? 1 : 0;
20
$allowDelete = $acl->isAllowed($roleName, 'microlearning/content/quizzes/questions/answers/delete') ? 1 : 0;
21
 
16992 efrain 22
 
23
 
24
 
16822 efrain 25
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
26
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
66 efrain 27
 
16822 efrain 28
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
29
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));
66 efrain 30
 
16822 efrain 31
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
32
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
33
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
34
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));
66 efrain 35
 
36
 
16822 efrain 37
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
38
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
66 efrain 39
 
40
 
41
 
42
 
43
 
44
 
45
 
16822 efrain 46
$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));
47
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-input-number/input-number-format.jquery.js'));
66 efrain 48
 
49
 
50
 
51
 
52
 
16822 efrain 53
 
54
 
55
 
16929 efrain 56
 
57
 
58
 
66 efrain 59
$this->inlineScript()->captureStart();
60
echo <<<JS
61
 
62
 
63
jQuery( document ).ready(function( $ ) {
64
    var show_points = $show_points;
65
    var allowAdd = $allowAdd;
66
    var allowEdit = $allowEdit;
67
    var allowDelete = $allowDelete;
68
 
69
    var gridTable = $('#gridTable').dataTable( {
70
            'processing': true,
71
            'serverSide': true,
72
            'searching': true,
73
            'order': [[ 0, 'asc' ]],
74
            'ordering':  true,
75
            'ordenable' : true,
76
            'responsive': true,
77
            'select' : false,
78
        	'paging': true,
79
            'pagingType': 'simple_numbers',
80
    		'ajax': {
81
    			'url' : '$routeDatatable',
82
    			'type' : 'get',
83
                'beforeSend': function (request) {
84
                  NProgress.start();
85
                },
86
                'dataFilter': function(response) {
87
                    var response = jQuery.parseJSON( response );
88
 
89
                    var json                = {};
90
                    json.recordsTotal       = 0;
91
                    json.recordsFiltered    = 0;
92
                    json.data               = [];
93
 
94
 
95
                    if(response.success) {
96
                        json.recordsTotal       = response.data.total;
97
                        json.recordsFiltered    = response.data.total;
98
                        json.data               = response.data.items;
99
                    } else {
100
                        $.fn.showError(response.data)
101
                    }
102
 
103
                    return JSON.stringify( json );
104
                }
105
    		},
106
            'language' : {
107
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
108
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
109
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
110
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
111
                'sInfo':           'LABEL_DATATABLE_SINFO',
112
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
113
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
114
                'sInfoPostFix':    '',
115
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
116
                'sUrl':            '',
117
                'sInfoThousands':  ',',
118
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
119
                'oPaginate': {
120
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
121
                    'sLast':     'LABEL_DATATABLE_SLAST',
122
                    'sNext':     'LABEL_DATATABLE_SNEXT',
123
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
124
                },
125
                'oAria': {
126
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
127
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
128
                },
129
            },
130
            'drawCallback': function( settings ) {
131
                NProgress.done();
16822 efrain 132
 
66 efrain 133
            },
134
            'aoColumns': [
135
                { 'mDataProp': 'text' },
136
                { 'mDataProp': 'details' },
137
                { 'mDataProp': 'actions' },
138
    	    ],
139
            'columnDefs': [
140
                {
141
                    'targets': 0,
142
                    'className' : 'text-vertical-middle',
143
                },
144
                {
145
                    'targets': 1,
146
                    'orderable': false,
147
                    'render' : function ( data, type, row ) {
12080 nelberth 148
                        var s =  row['details']['correct'] + '<br>';
66 efrain 149
                        if(show_points) {
150
                            s = s + 'LABEL_POINTS : ' + row['details']['points'] + '<br>';
151
                        }
152
                        return s;
153
                    }
154
                },
155
                {
156
                    'targets': -1,
157
                    'orderable': false,
158
                    'render' : function ( data, type, row ) {
159
                        s = '';
160
 
161
                        if(allowEdit && data['link_edit']  ) {
16906 efrain 162
                            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 163
                        }
164
                        if(allowDelete && data['link_delete']  ) {
165
                            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;';
166
                        }
167
 
168
 
169
 
170
                        return s;
171
                    }
172
                }
173
              ],
174
        });
175
 
176
 
177
 
178
    var validator = $('#form').validate({
179
        debug: true,
180
        onclick: false,
181
        onkeyup: false,
182
        ignore: [],
183
        rules: {
184
            'text': {
185
                updateCkeditor:function() {
186
                        CKEDITOR.instances.text.updateElement();
187
                },
188
                required: true
189
            },
190
            'correct' : {
191
                required: true,
192
            },
193
            'points' : {
194
                required: function (element) {
195
                        return $('#form #correct').val() == 'y' ? true : false;
196
                    } ,
197
                digits: true,
198
                min: 0,
199
                max: 100
200
            },
201
        },
202
        submitHandler: function(form)
203
        {
204
            $('input[type="submit"]').prop('disabled', true);
205
 
206
            $.ajax({
207
                'dataType'  : 'json',
208
                'accept'    : 'application/json',
209
                'method'    : 'post',
210
                'url'       :  $('#form').attr('action'),
211
                'data'      :  $('#form').serialize(),
212
            }).done(function(response) {
213
                if(response['success']) {
214
                    $.fn.showSuccess(response['data']);
215
 
216
                    $('#modal-form').modal('hide');
217
                    gridTable.api().ajax.reload(null, false);
218
                } else {
219
                    validator.resetForm();
220
                    if(jQuery.type(response['data']) == 'string') {
221
                        $.fn.showError(response['data']);
222
                    } else  {
223
                        $.each(response['data'], function( fieldname, errors ) {
224
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
225
                        });
226
                    }
227
                }
228
            }).fail(function( jqXHR, textStatus, errorThrown) {
229
                $.fn.showError(textStatus);
230
            }).always(function() {
231
                NProgress.done();
232
            });
233
            return false;
234
        },
235
        invalidHandler: function(form, validator) {
236
 
237
        }
238
    });
239
 
16992 efrain 240
    $('body').on('click', 'button.btn-back', function(e) {
241
        e.preventDefault();
66 efrain 242
 
16992 efrain 243
        window.location.href = '$routeRegresar';
244
 
245
    });
246
 
247
 
66 efrain 248
    $('body').on('click', 'button.btn-add', function(e) {
249
        e.preventDefault();
250
 
16840 efrain 251
 
66 efrain 252
        $('#form').attr('action', '$routeAdd');
253
        $('#form #name').val('');
254
        $('#form #correct').val('');
255
 
256
        $('#form #points').val('0');
257
        $('#form #points').hide();
258
 
259
        CKEDITOR.instances['text'].setData('');
260
        validator.resetForm();
261
 
262
        $('#modal-form').modal('show');
263
        return false;
264
    });
265
 
266
    $('#form #correct').change(function(e) {
267
        e.preventDefault();
268
 
269
        if(show_points) {
270
            var value = $(this).val();
271
            if(value == 'y') {
272
                $('#form #points').show();
273
            } else {
274
                $('#form #points').hide();
275
            }
276
        } else {
277
            $('#form #points').val('0');
278
            $('#form #points').hide();
279
        }
280
 
281
    });
282
 
283
 
284
    $('#form #type').change(function(e) {
285
        e.preventDefault();
286
 
287
        var value = $(this).val();
288
        if(value == 'sl' || value == 'ml') {
289
            $('#form #maxlength').show();
290
        } else {
291
            $('#form #maxlength').val('');
292
            $('#form #maxlength').hide();
293
        }
294
 
295
    });
296
 
16993 efrain 297
    $('body').on('click', 'button.btn-refresh', function(e) {
298
        e.preventDefault();
299
        gridTable.api().ajax.reload(null, false);
300
    });
301
 
66 efrain 302
    $('body').on('click', 'button.btn-edit', function(e) {
303
            e.preventDefault();
304
            NProgress.start();
305
            var action = $(this).data('href');
306
 
307
            $.ajax({
308
                'dataType'  : 'json',
309
                'accept'    : 'application/json',
310
                'method'    : 'get',
311
                'url'       :  action,
312
            }).done(function(response) {
313
                if(response['success']) {
314
 
16840 efrain 315
 
66 efrain 316
                    $('#form').attr('action', action);
317
                    $('#form #name').val(response['data']['name']);
318
                    $('#form #correct').val(response['data']['correct']);
319
 
320
                    if(show_points) {
321
 
322
                        if(response['data']['correct'] == 'y') {
323
                            $('#form #points').val(response['data']['points']);
324
                            $('#form #points').show();
325
                        } else {
326
                            $('#form #points').val('0');
327
                            $('#form #points').hide();
328
                        }
329
                    } else {
330
                        $('#form #points').val('0');
331
                        $('#form #points').hide();
332
                    }
333
 
334
                    CKEDITOR.instances['text'].setData(response['data']['text']);
335
                    validator.resetForm();
336
 
337
                    $('#modal-form').modal('show');
338
                    return false;
339
                } else {
340
                    $.fn.showError(response['data']);
341
                }
342
            }).fail(function( jqXHR, textStatus, errorThrown) {
343
                $.fn.showError(textStatus);
344
            }).always(function() {
345
                NProgress.done();
346
            });
347
        });
348
 
16992 efrain 349
 
350
 
16822 efrain 351
    $('body').on('click', 'button.btn-delete', function(e) {
352
        e.preventDefault();
353
        var action = $(this).data('href');
66 efrain 354
 
16822 efrain 355
 
356
          swal.fire({
357
            title: 'LABEL_ARE_YOU_SURE',
358
            icon: 'question',
359
            cancelButtonText: 'LABEL_NO',
360
            showCancelButton: true,
361
            confirmButtonText: 'LABEL_YES'
362
          }).then((result) => {
363
            if (result.isConfirmed) {
364
 
365
                    NProgress.start();
366
                    $.ajax({
367
                        'dataType'  : 'json',
368
                        'accept'    : 'application/json',
369
                        'method'    : 'post',
370
                        'url'       :  action,
371
                    }).done(function(response) {
372
                        if(response['success']) {
373
                            $.fn.showSuccess(response['data']);
374
                            gridTable.api().ajax.reload(null, false);
375
                        } else {
376
                            $.fn.showError(response['data']);
377
                        }
378
                    }).fail(function( jqXHR, textStatus, errorThrown) {
379
                        $.fn.showError(textStatus);
380
                    }).always(function() {
381
                        NProgress.done();
382
                    });
383
            }
384
       });
385
    });
386
 
387
 
66 efrain 388
    $('#form #points').inputNumberFormat({decimal: 0});
389
 
8290 stevensc 390
    CKEDITOR.replace('text', {
391
        toolbar: [
392
            { name: 'editing', items: ['Scayt'] },
393
            { name: 'links', items: ['Link', 'Unlink'] },
394
            { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
395
            { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
396
            '/',
397
            { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
398
            { name: 'styles', items: ['Styles', 'Format'] },
399
            { name: 'tools', items: ['Maximize'] }
400
        ],
401
        removePlugins: 'elementspath,Anchor',
402
        heigth: 100
403
    });
66 efrain 404
 
405
});
406
JS;
407
$this->inlineScript()->captureEnd();
408
?>
409
 
16910 efrain 410
<div class="container">
411
	<div class="card" id="">
412
	 	<div class="card-header">
413
	 		<h6 class="card-title"> <?php echo $quiz_name ?> - <?php echo $question_name ?> - LABEL_ANSWERS </h6>
414
	 	</div>
415
	 	<div class="card-body">
416
	 		<div class="row">
417
	 	         <div class="col-12 mt-3">
418
 
419
	 	         <table id="gridTable" class="table   table-bordered">
66 efrain 420
                      		<thead>
421
        						<tr>
422
                                	<th>LABEL_NAME</th>
423
                                  	<th>LABEL_DETAILS</th>
424
                                  	<th>LABEL_ACTIONS</th>
425
                                </tr>
426
                       		</thead>
427
                         	<tbody>
428
                         	</tbody>
429
                    	</table>
16910 efrain 430
 
431
	 	         </div>
432
	 	     </div>
433
	 	</div>
434
	 	<div class="card-footer text-right">
16992 efrain 435
							<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH  </button>
66 efrain 436
							<?php if($allowAdd) : ?>
437
							<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
438
							<?php endif; ?>
16992 efrain 439
 
440
							<button type="button" class="btn btn-primary btn-back"><i class="fa fa-undo"></i> LABEL_BACK </button>
16910 efrain 441
	 	</div>
442
	</div>
443
</div>
444
 
445
 
66 efrain 446
 
447
 
448
 
449
<div class="modal" tabindex="-1" role="dialog" id="modal-form">
450
	<div class="modal-dialog  modal-lg">
451
    	<div class="modal-content">
452
		<?php
453
		$form = $this->formCreateOrEdit;
454
	    $form->setAttributes([
455
	       'method'    => 'post',
456
	        'name'      => 'form',
457
	        'id'        => 'form'
458
	    ]);
459
	    $form->prepare();
460
	    echo $this->form()->openTag($form);
461
	    ?>
462
    	<div class="modal-content">
463
      		<div class="modal-header">
16935 efrain 464
        		<h6 class="modal-title" ><span id="form-title">LABEL_ADD</span></h6>
66 efrain 465
      		</div>
466
      		<div class="modal-body">
16910 efrain 467
    	 		<div class="row">
468
    	 	         <div class="col-12 mt-3">
469
                    	<?php
470
                        $element = $form->get('text');
471
                        $element->setAttributes(['id' => 'text', 'rows' => '2', 'placeholder' => '', 'class' => 'form-control']);
472
                        $element->setOptions(['label' => 'LABEL_TEXT']);
66 efrain 473
                        echo $this->formLabel($element);
16910 efrain 474
                        echo $this->formTextArea($element);
475
                        ?>
476
    	 	         </div>
477
    	 	     </div>
478
    	 		<div class="row">
479
    	 	         <div class="col-12 mt-3">
480
        				<?php
481
                            $element = $form->get('correct');
482
                            $element->setAttributes(['class' => 'form-control']);
483
                            $element->setOptions(['label' => 'LABEL_CORRECT']);
484
                            echo $this->formLabel($element);
485
                            echo $this->formSelect($element);
486
                        ?>
487
    	 	         </div>
488
    	 	     </div>
489
    				<?php if($show_points) : ?>
490
    	 		<div class="row">
491
    	 	         <div class="col-12 mt-3">
492
        				<?php
493
                            $element = $form->get('points');
494
                            $element->setAttributes(['class' => 'form-control']);
495
                            $element->setOptions(['label' => 'LABEL_POINTS']);
496
                            echo $this->formLabel($element);
497
                            echo $this->formText($element);
498
                        ?>
499
    	 	         </div>
500
    	 	     </div>
501
    				<?php else : ?>
502
    					<?php
503
                            $element = $form->get('points');
504
                            echo $this->formHidden($element);
505
                        ?>
506
    				<?php endif; ?>
66 efrain 507
          	</div>
508
 
16891 efrain 509
         	<div class="modal-footer text-right">
66 efrain 510
    			<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
16822 efrain 511
    			 <button type="button" class="btn btn-light" data-bs-dismiss="modal">LABEL_CLOSE</button>
66 efrain 512
          	</div>
513
      	<?php echo $this->form()->closeTag($form); ?>
514
    	</div>
515
 
516
    	</div>
517
    </div>
518
</div>
519
 
520