Proyectos de Subversion LeadersLinked - Backend

Rev

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