Proyectos de Subversion LeadersLinked - Backend

Rev

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