Rev 8290 | Rev 16840 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpuse LeadersLinked\Library\Functions;use LeadersLinked\Model\CompanyMicrolearningQuiz;$acl = $this->viewModel()->getRoot()->getVariable('acl');$currentUser = $this->currentUserHelper();$roleName = $currentUser->getUserTypeId();$params = ['quiz_id' => $quiz_uuid,'question_id' => $question_uuid];$routeAdd = $this->url('microlearning/content/quizzes/questions/answers/add', $params);$routeDatatable = $this->url('microlearning/content/quizzes/questions/answers', $params);$allowAdd = $acl->isAllowed($roleName, 'microlearning/content/quizzes/questions/answers/add') ? 1 : 0;$allowEdit = $acl->isAllowed($roleName, 'microlearning/content/quizzes/questions/answers/edit') ? 1 : 0;$allowDelete = $acl->isAllowed($roleName, 'microlearning/content/quizzes/questions/answers/delete') ? 1 : 0;$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));$this->inlineScript()->captureStart();echo <<<JSjQuery( document ).ready(function( $ ) {var show_points = $show_points;var allowAdd = $allowAdd;var allowEdit = $allowEdit;var allowDelete = $allowDelete;var gridTable = $('#gridTable').dataTable( {'processing': true,'serverSide': true,'searching': true,'order': [[ 0, 'asc' ]],'ordering': true,'ordenable' : true,'responsive': true,'select' : false,'paging': true,'pagingType': 'simple_numbers','ajax': {'url' : '$routeDatatable','type' : 'get','beforeSend': function (request) {NProgress.start();},'dataFilter': function(response) {var response = jQuery.parseJSON( response );var json = {};json.recordsTotal = 0;json.recordsFiltered = 0;json.data = [];if(response.success) {json.recordsTotal = response.data.total;json.recordsFiltered = response.data.total;json.data = response.data.items;} else {$.fn.showError(response.data)}return JSON.stringify( json );}},'language' : {'sProcessing': 'LABEL_DATATABLE_SPROCESSING','sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU','sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS','sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE','sInfo': 'LABEL_DATATABLE_SINFO','sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY','sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED','sInfoPostFix': '','sSearch': 'LABEL_DATATABLE_SSEARCH','sUrl': '','sInfoThousands': ',','sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS','oPaginate': {'sFirst': 'LABEL_DATATABLE_SFIRST','sLast': 'LABEL_DATATABLE_SLAST','sNext': 'LABEL_DATATABLE_SNEXT','sPrevious': 'LABEL_DATATABLE_SPREVIOUS'},'oAria': {'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING','sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'},},'drawCallback': function( settings ) {NProgress.done();$('button.btn-delete').confirmation({rootSelector: 'button.btn-delete',title : 'LABEL_ARE_YOU_SURE',singleton : true,btnOkLabel: 'LABEL_YES',btnCancelLabel: 'LABEL_NO',onConfirm: function(value) {action = $(this).data('href');NProgress.start();$.ajax({'dataType' : 'json','accept' : 'application/json','method' : 'post','url' : action,}).done(function(response) {if(response['success']) {$.fn.showSuccess(response['data']);gridTable.api().ajax.reload(null, false);} else {$.fn.showError(response['data']);}}).fail(function( jqXHR, textStatus, errorThrown) {$.fn.showError(textStatus);}).always(function() {NProgress.done();});},});},'aoColumns': [{ 'mDataProp': 'text' },{ 'mDataProp': 'details' },{ 'mDataProp': 'actions' },],'columnDefs': [{'targets': 0,'className' : 'text-vertical-middle',},{'targets': 1,'orderable': false,'render' : function ( data, type, row ) {var s = row['details']['correct'] + '<br>';if(show_points) {s = s + 'LABEL_POINTS : ' + row['details']['points'] + '<br>';}return s;}},{'targets': -1,'orderable': false,'render' : function ( data, type, row ) {s = '';if(allowEdit && data['link_edit'] ) {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> ';}if(allowDelete && data['link_delete'] ) {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> ';}return s;}}],});var validator = $('#form').validate({debug: true,onclick: false,onkeyup: false,ignore: [],rules: {'text': {updateCkeditor:function() {CKEDITOR.instances.text.updateElement();},required: true},'correct' : {required: true,},'points' : {required: function (element) {return $('#form #correct').val() == 'y' ? true : false;} ,digits: true,min: 0,max: 100},},submitHandler: function(form){$('input[type="submit"]').prop('disabled', true);$.ajax({'dataType' : 'json','accept' : 'application/json','method' : 'post','url' : $('#form').attr('action'),'data' : $('#form').serialize(),}).done(function(response) {if(response['success']) {$.fn.showSuccess(response['data']);$('#modal-form').modal('hide');gridTable.api().ajax.reload(null, false);} else {validator.resetForm();if(jQuery.type(response['data']) == 'string') {$.fn.showError(response['data']);} else {$.each(response['data'], function( fieldname, errors ) {$.fn.showFormErrorValidator('#form #' + fieldname, errors);});}}}).fail(function( jqXHR, textStatus, errorThrown) {$.fn.showError(textStatus);}).always(function() {NProgress.done();});return false;},invalidHandler: function(form, validator) {}});$('body').on('click', 'button.btn-add', function(e) {e.preventDefault();$('span[id="form-title"]').html('LABEL_ADD');$('#form').attr('action', '$routeAdd');$('#form #name').val('');$('#form #correct').val('');$('#form #points').val('0');$('#form #points').hide();CKEDITOR.instances['text'].setData('');validator.resetForm();$('#modal-form').modal('show');return false;});$('#form #correct').change(function(e) {e.preventDefault();if(show_points) {var value = $(this).val();if(value == 'y') {$('#form #points').show();} else {$('#form #points').hide();}} else {$('#form #points').val('0');$('#form #points').hide();}});$('#form #type').change(function(e) {e.preventDefault();var value = $(this).val();if(value == 'sl' || value == 'ml') {$('#form #maxlength').show();} else {$('#form #maxlength').val('');$('#form #maxlength').hide();}});$('body').on('click', 'button.btn-edit', function(e) {e.preventDefault();NProgress.start();var action = $(this).data('href');$.ajax({'dataType' : 'json','accept' : 'application/json','method' : 'get','url' : action,}).done(function(response) {if(response['success']) {$('span[id="form-title"]').html('LABEL_EDIT');$('#form').attr('action', action);$('#form #name').val(response['data']['name']);$('#form #correct').val(response['data']['correct']);if(show_points) {if(response['data']['correct'] == 'y') {$('#form #points').val(response['data']['points']);$('#form #points').show();} else {$('#form #points').val('0');$('#form #points').hide();}} else {$('#form #points').val('0');$('#form #points').hide();}CKEDITOR.instances['text'].setData(response['data']['text']);validator.resetForm();$('#modal-form').modal('show');return false;} else {$.fn.showError(response['data']);}}).fail(function( jqXHR, textStatus, errorThrown) {$.fn.showError(textStatus);}).always(function() {NProgress.done();});});$('#form #points').inputNumberFormat({decimal: 0});CKEDITOR.replace('text', {toolbar: [{ name: 'editing', items: ['Scayt'] },{ name: 'links', items: ['Link', 'Unlink'] },{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },{ name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },'/',{ name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },{ name: 'styles', items: ['Styles', 'Format'] },{ name: 'tools', items: ['Maximize'] }],removePlugins: 'elementspath,Anchor',heigth: 100});});JS;$this->inlineScript()->captureEnd();?><!-- Content Header (Page header) --><section class="content-header"><div class="container-fluid"><div class="row mb-2"><div class="col-sm-12"><h1>LABEL_ANSWERS</h1><h2><?php echo $quiz_name ?></h2><h3><?php echo $question_name ?></h3></div></div></div><!-- /.container-fluid --></section><section class="content"><div class="container-fluid"><div class="row"><div class="col-12"><div class="card"><div class="card-body"><table id="gridTable" class="table table-hover"><thead><tr><th>LABEL_NAME</th><th>LABEL_DETAILS</th><th>LABEL_ACTIONS</th></tr></thead><tbody></tbody></table></div><div class="card-footer clearfix"><div style="float:right;"><button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button><?php if($allowAdd) : ?><button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button><?php endif; ?></div></div></div></div></div></div></section><div class="modal" tabindex="-1" role="dialog" id="modal-form"><div class="modal-dialog modal-lg"><div class="modal-content"><?php$form = $this->formCreateOrEdit;$form->setAttributes(['method' => 'post','name' => 'form','id' => 'form']);$form->prepare();echo $this->form()->openTag($form);?><div class="modal-content"><div class="modal-header"><h3 class="modal-title" ><span id="form-title">LABEL_ADD</span></h3></div><div class="modal-body"><div class="form-group"><?php$element = $form->get('text');$element->setAttributes(['id' => 'text', 'rows' => '2', 'placeholder' => '', 'class' => 'form-control']);$element->setOptions(['label' => 'LABEL_TEXT']);echo $this->formLabel($element);echo $this->formTextArea($element);?></div><div class="form-group"><?php$element = $form->get('correct');$element->setAttributes(['class' => 'form-control']);$element->setOptions(['label' => 'LABEL_CORRECT']);echo $this->formLabel($element);echo $this->formSelect($element);?></div><?php if($show_points) : ?><div class="form-group"><?php$element = $form->get('points');$element->setAttributes(['class' => 'form-control']);$element->setOptions(['label' => 'LABEL_POINTS']);echo $this->formLabel($element);echo $this->formText($element);?></div><?php else : ?><?php$element = $form->get('points');echo $this->formHidden($element);?><?php endif; ?></div><div class="modal-footer"><button type="submit" class="btn btn-primary">LABEL_SAVE</button><button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button></div><?php echo $this->form()->closeTag($form); ?></div></div></div></div>