Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 8290 | Rev 16822 | 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
 
21
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
22
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
23
 
24
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
25
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
26
 
27
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
28
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
29
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
30
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
31
 
32
 
33
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
34
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
35
 
36
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
37
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
38
 
39
 
40
 
41
 
42
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
43
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
44
 
45
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
46
 
47
 
48
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
49
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
50
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
51
 
52
 
53
 
54
 
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();
128
                $('button.btn-delete').confirmation({
129
                    rootSelector: 'button.btn-delete',
130
                    title : 'LABEL_ARE_YOU_SURE',
131
                    singleton : true,
132
                    btnOkLabel: 'LABEL_YES',
133
                    btnCancelLabel: 'LABEL_NO',
134
                    onConfirm: function(value) {
135
                        action = $(this).data('href');
136
                        NProgress.start();
137
                        $.ajax({
138
                            'dataType'  : 'json',
139
                            'accept'    : 'application/json',
140
                            'method'    : 'post',
141
                            'url'       :  action,
142
                        }).done(function(response) {
143
                            if(response['success']) {
144
                                $.fn.showSuccess(response['data']);
145
                                gridTable.api().ajax.reload(null, false);
146
                            } else {
147
                                $.fn.showError(response['data']);
148
                            }
149
                        }).fail(function( jqXHR, textStatus, errorThrown) {
150
                            $.fn.showError(textStatus);
151
                        }).always(function() {
152
                            NProgress.done();
153
                        });
154
                    },
155
                });
156
            },
157
            'aoColumns': [
158
                { 'mDataProp': 'text' },
159
                { 'mDataProp': 'details' },
160
                { 'mDataProp': 'actions' },
161
    	    ],
162
            'columnDefs': [
163
                {
164
                    'targets': 0,
165
                    'className' : 'text-vertical-middle',
166
                },
167
                {
168
                    'targets': 1,
169
                    'orderable': false,
170
                    'render' : function ( data, type, row ) {
12080 nelberth 171
                        var s =  row['details']['correct'] + '<br>';
66 efrain 172
                        if(show_points) {
173
                            s = s + 'LABEL_POINTS : ' + row['details']['points'] + '<br>';
174
                        }
175
                        return s;
176
                    }
177
                },
178
                {
179
                    'targets': -1,
180
                    'orderable': false,
181
                    'render' : function ( data, type, row ) {
182
                        s = '';
183
 
184
                        if(allowEdit && data['link_edit']  ) {
185
                            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;';
186
                        }
187
                        if(allowDelete && data['link_delete']  ) {
188
                            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;';
189
                        }
190
 
191
 
192
 
193
                        return s;
194
                    }
195
                }
196
              ],
197
        });
198
 
199
 
200
 
201
    var validator = $('#form').validate({
202
        debug: true,
203
        onclick: false,
204
        onkeyup: false,
205
        ignore: [],
206
        rules: {
207
            'text': {
208
                updateCkeditor:function() {
209
                        CKEDITOR.instances.text.updateElement();
210
                },
211
                required: true
212
            },
213
            'correct' : {
214
                required: true,
215
            },
216
            'points' : {
217
                required: function (element) {
218
                        return $('#form #correct').val() == 'y' ? true : false;
219
                    } ,
220
                digits: true,
221
                min: 0,
222
                max: 100
223
            },
224
        },
225
        submitHandler: function(form)
226
        {
227
            $('input[type="submit"]').prop('disabled', true);
228
 
229
            $.ajax({
230
                'dataType'  : 'json',
231
                'accept'    : 'application/json',
232
                'method'    : 'post',
233
                'url'       :  $('#form').attr('action'),
234
                'data'      :  $('#form').serialize(),
235
            }).done(function(response) {
236
                if(response['success']) {
237
                    $.fn.showSuccess(response['data']);
238
 
239
                    $('#modal-form').modal('hide');
240
                    gridTable.api().ajax.reload(null, false);
241
                } else {
242
                    validator.resetForm();
243
                    if(jQuery.type(response['data']) == 'string') {
244
                        $.fn.showError(response['data']);
245
                    } else  {
246
                        $.each(response['data'], function( fieldname, errors ) {
247
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
248
                        });
249
                    }
250
                }
251
            }).fail(function( jqXHR, textStatus, errorThrown) {
252
                $.fn.showError(textStatus);
253
            }).always(function() {
254
                NProgress.done();
255
            });
256
            return false;
257
        },
258
        invalidHandler: function(form, validator) {
259
 
260
        }
261
    });
262
 
263
 
264
    $('body').on('click', 'button.btn-add', function(e) {
265
        e.preventDefault();
266
 
267
        $('span[id="form-title"]').html('LABEL_ADD');
268
        $('#form').attr('action', '$routeAdd');
269
        $('#form #name').val('');
270
        $('#form #correct').val('');
271
 
272
        $('#form #points').val('0');
273
        $('#form #points').hide();
274
 
275
        CKEDITOR.instances['text'].setData('');
276
        validator.resetForm();
277
 
278
        $('#modal-form').modal('show');
279
        return false;
280
    });
281
 
282
    $('#form #correct').change(function(e) {
283
        e.preventDefault();
284
 
285
        if(show_points) {
286
            var value = $(this).val();
287
            if(value == 'y') {
288
                $('#form #points').show();
289
            } else {
290
                $('#form #points').hide();
291
            }
292
        } else {
293
            $('#form #points').val('0');
294
            $('#form #points').hide();
295
        }
296
 
297
    });
298
 
299
 
300
    $('#form #type').change(function(e) {
301
        e.preventDefault();
302
 
303
        var value = $(this).val();
304
        if(value == 'sl' || value == 'ml') {
305
            $('#form #maxlength').show();
306
        } else {
307
            $('#form #maxlength').val('');
308
            $('#form #maxlength').hide();
309
        }
310
 
311
    });
312
 
313
    $('body').on('click', 'button.btn-edit', function(e) {
314
            e.preventDefault();
315
            NProgress.start();
316
            var action = $(this).data('href');
317
 
318
            $.ajax({
319
                'dataType'  : 'json',
320
                'accept'    : 'application/json',
321
                'method'    : 'get',
322
                'url'       :  action,
323
            }).done(function(response) {
324
                if(response['success']) {
325
 
326
                    $('span[id="form-title"]').html('LABEL_EDIT');
327
                    $('#form').attr('action', action);
328
                    $('#form #name').val(response['data']['name']);
329
                    $('#form #correct').val(response['data']['correct']);
330
 
331
                    if(show_points) {
332
 
333
                        if(response['data']['correct'] == 'y') {
334
                            $('#form #points').val(response['data']['points']);
335
                            $('#form #points').show();
336
                        } else {
337
                            $('#form #points').val('0');
338
                            $('#form #points').hide();
339
                        }
340
                    } else {
341
                        $('#form #points').val('0');
342
                        $('#form #points').hide();
343
                    }
344
 
345
                    CKEDITOR.instances['text'].setData(response['data']['text']);
346
                    validator.resetForm();
347
 
348
                    $('#modal-form').modal('show');
349
                    return false;
350
                } else {
351
                    $.fn.showError(response['data']);
352
                }
353
            }).fail(function( jqXHR, textStatus, errorThrown) {
354
                $.fn.showError(textStatus);
355
            }).always(function() {
356
                NProgress.done();
357
            });
358
        });
359
 
360
 
361
    $('#form #points').inputNumberFormat({decimal: 0});
362
 
8290 stevensc 363
    CKEDITOR.replace('text', {
364
        toolbar: [
365
            { name: 'editing', items: ['Scayt'] },
366
            { name: 'links', items: ['Link', 'Unlink'] },
367
            { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
368
            { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
369
            '/',
370
            { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
371
            { name: 'styles', items: ['Styles', 'Format'] },
372
            { name: 'tools', items: ['Maximize'] }
373
        ],
374
        removePlugins: 'elementspath,Anchor',
375
        heigth: 100
376
    });
66 efrain 377
 
378
});
379
JS;
380
$this->inlineScript()->captureEnd();
381
?>
382
 
383
 
384
<!-- Content Header (Page header) -->
385
<section class="content-header">
386
	<div class="container-fluid">
387
    	<div class="row mb-2">
388
        	<div class="col-sm-12">
389
            	<h1>LABEL_ANSWERS</h1>
390
            	<h2><?php echo $quiz_name ?></h2>
391
            	<h3><?php echo $question_name ?></h3>
392
			</div>
393
		</div>
394
	</div><!-- /.container-fluid -->
395
</section>
396
 
397
<section class="content">
398
	<div class="container-fluid">
399
    	<div class="row">
400
        	<div class="col-12">
401
				<div class="card">
402
					<div class="card-body">
403
        	    		<table id="gridTable" class="table   table-hover">
404
                      		<thead>
405
        						<tr>
406
                                	<th>LABEL_NAME</th>
407
                                  	<th>LABEL_DETAILS</th>
408
                                  	<th>LABEL_ACTIONS</th>
409
                                </tr>
410
                       		</thead>
411
                         	<tbody>
412
                         	</tbody>
413
                    	</table>
414
                   	</div>
415
                   	<div class="card-footer clearfix">
416
                   		<div style="float:right;">
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; ?>
421
						</div>
422
                 	</div>
423
          		</div>
424
           	</div>
425
        </div>
426
 	</div>
427
</section>
428
 
429
 
430
 
431
<div class="modal" tabindex="-1" role="dialog" id="modal-form">
432
	<div class="modal-dialog  modal-lg">
433
    	<div class="modal-content">
434
		<?php
435
		$form = $this->formCreateOrEdit;
436
	    $form->setAttributes([
437
	       'method'    => 'post',
438
	        'name'      => 'form',
439
	        'id'        => 'form'
440
	    ]);
441
	    $form->prepare();
442
	    echo $this->form()->openTag($form);
443
	    ?>
444
    	<div class="modal-content">
445
      		<div class="modal-header">
446
        		<h3 class="modal-title" ><span id="form-title">LABEL_ADD</span></h3>
447
      		</div>
448
      		<div class="modal-body">
449
   				<div class="form-group">
450
                	<?php
451
                    $element = $form->get('text');
452
                    $element->setAttributes(['id' => 'text', 'rows' => '2', 'placeholder' => '', 'class' => 'form-control']);
453
                    $element->setOptions(['label' => 'LABEL_TEXT']);
454
                    echo $this->formLabel($element);
455
                    echo $this->formTextArea($element);
456
                    ?>
457
   				</div>
458
   				<div class="form-group">
459
    				<?php
460
                        $element = $form->get('correct');
461
                        $element->setAttributes(['class' => 'form-control']);
462
                        $element->setOptions(['label' => 'LABEL_CORRECT']);
463
                        echo $this->formLabel($element);
464
                        echo $this->formSelect($element);
465
                    ?>
466
				</div>
467
				<?php if($show_points) : ?>
468
				<div class="form-group">
469
    				<?php
470
                        $element = $form->get('points');
471
                        $element->setAttributes(['class' => 'form-control']);
472
                        $element->setOptions(['label' => 'LABEL_POINTS']);
473
                        echo $this->formLabel($element);
474
                        echo $this->formText($element);
475
                    ?>
476
				</div>
477
				<?php else : ?>
478
					<?php
479
                        $element = $form->get('points');
480
                        echo $this->formHidden($element);
481
                    ?>
482
				<?php endif; ?>
483
          	</div>
484
 
485
         	<div class="modal-footer">
486
    			<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
487
    			<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
488
          	</div>
489
      	<?php echo $this->form()->closeTag($form); ?>
490
    	</div>
491
 
492
    	</div>
493
    </div>
494
</div>
495
 
496