Rev 16845 | Rev 16891 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php$acl = $this->viewModel()->getRoot()->getVariable('acl');$currentUser = $this->currentUserHelper();$roleName = $currentUser->getUserTypeId();$routeDatatable = $this->url('self-evaluation/reviews');$routeDashboard = $this->url('dashboard');$allowEdit = $acl->isAllowed($roleName, 'self-evaluation/reviews/edit') ? 1 : 0;$allowReport = $acl->isAllowed($roleName, 'self-evaluation/reviews/report') ? 1 : 0;$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/jquery.validate.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/additional-methods.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/localization/messages_es.js'));$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2/css/select2.min.css'));$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2-bootstrap4-theme/select2-bootstrap4.min.css'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/select2.full.min.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/moment/moment-with-locales.min.js'));$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-input-number/input-number-format.jquery.js'));// bootbox Alert //// JsRender //$this->inlineScript()->appendFile($this->basePath('assets/vendors/jsrender/jsrender.min.js'));// Page Styles$this->headLink()->appendStylesheet($this->basePath('css/pages/self-evaluation.css'));$pending = \LeadersLinked\Model\SelfEvaluationTest::STATUS_PENDING;$review = \LeadersLinked\Model\SelfEvaluationTest::STATUS_REVIEW;$completed = \LeadersLinked\Model\SelfEvaluationTest::STATUS_COMPLETED;$this->inlineScript()->captureStart();echo <<<JSconst classFormGenerator = function() {this.id = 0,this.table = '',this.name = '',this.text = '',this.status = 'a',this.sections = [],this.clear = function() {this.sections = [];this.render();},/*** Render array sections*/this.renderSection = function(slug_section) {var s = '';for (i = 0; i < this.sections.length; i++) {if (slug_section != this.sections[i].slug_section) {continue;}for (j = 0; j < this.sections[i].questions.length; j++) {this.sections[i].questions[j].position = j;if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {this.sections[i].questions[j].options.sort(function(a, b) {if (a.position > b.position) {return 1;}if (a.position < b.position) {return -1;}return 0;});for (k = 0; k < this.sections[i].questions[j].options.length; k++) {this.sections[i].questions[j].options[k].position = j;}}}}$('[data-toggle="tooltip"]').tooltip();},this.render = function() {this.sections.sort(function(a, b) {if (a.position > b.position) {return 1;}if (a.position < b.position) {return -1;}return 0;});var s = '';for (i = 0; i < this.sections.length; i++) {this.sections[i].position = i;this.sections[i].questions.sort(function(a, b) {if (a.position > b.position) {return 1;}if (a.position < b.position) {return -1;}return 0;});for (j = 0; j < this.sections[i].questions.length; j++) {this.sections[i].questions[j].position = j;if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {this.sections[i].questions[j].options.sort(function(a, b) {if (a.position > b.position) {return 1;}if (a.position < b.position) {return -1;}return 0;});for (k = 0; k < this.sections[i].questions[j].options.length; k++) {this.sections[i].questions[j].options[k].position = j;}}}}$('[data-toggle="tooltip"]').tooltip();};/*** Add element to question array*/this.editQuestion = function(slug_section, slug_question, comment, question_value, status) {var renderTable = false;for (i = 0; i < this.sections.length; i++) {if (slug_section == this.sections[i].slug_section) {for (j = 0; j < this.sections[i].questions.length; j++) {if (slug_question == this.sections[i].questions[j].slug_question) {this.sections[i].questions[j].status = status;this.sections[i].questions[j].comment = comment;this.sections[i].questions[j].question_value = question_value;this.renderSection(slug_section);return true;}}}}};}jQuery(document).ready(function($) {var objFormGenerator = new classFormGenerator();objFormGenerator.render();var allowEdit = $allowEdit;var allowReport = $allowReport;/*** Get rows and set data table*/var tableForm = $('#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) {if ($('#only_pending').is(':checked')) {let items = response.data.items.filter((item) => item.status == 'Pendiente');json.recordsTotal = items.length;json.recordsFiltered = items.length;json.data = items;} else {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();},'aoColumns': [{'mDataProp': 'user'}, {'mDataProp': 'name'},{'mDataProp': 'language'},{'mDataProp': 'status'},{'mDataProp': 'added_on'},{'mDataProp': 'actions'},],'columnDefs': [{'targets': 0,'className': 'text-vertical-middle',}, {'targets': 1,'className': 'text-vertical-middle',},{'targets': -1,'className': 'text-vertical-middle',},{'targets': -1,'className': 'text-center','className': 'text-vertical-middle',},{'targets': -1,'className': 'text-vertical-middle',},{'targets': -1,'orderable': false,'render': function(data, type, row) {s = '';if (allowEdit && data['link_edit']) {s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_MAKE_CHECK">LABEL_MAKE_CHECK</button> ';}if (allowReport && data['link_report']) {s = s + '<a class="btn btn-primary btn-edit-form" href="' + data['link_report'] + '" target="_blank" data-toggle="tooltip" title="LABEL_VIEW_REPORT">LABEL_VIEW_REPORT</a> ';}return s;}}],});/*** Clicked edit question*/$('body').on('click', 'button.btn-add-review', function(e) {e.preventDefault();if ($('#question-value').val() == '') {$.fn.showError('ERROR_ENTER_VALUE');return false;} else {objFormGenerator.editQuestion($('#section').val(),$('#question').val(),$('#question-comment').val(),$('#question-value').val(),$('#question-status').val() == '1' ? true : false);renderSectionData(objFormGenerator.sections);$('#form-review')[0].reset();$('#modal-review').modal('hide');}});/*** Clicked edit question*/$('body').on('click', 'button.btn-edit-review', function(e) {e.preventDefault();e.preventDefault();var slug_section = $(this).data('section');var slug_question = $(this).data('question');var showForm = false;for (i = 0; i < objFormGenerator.sections.length; i++) {if (slug_section == objFormGenerator.sections[i].slug_section) {for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {$('#form-review #section').val(objFormGenerator.sections[i].slug_section);$('#form-review #question').val(objFormGenerator.sections[i].questions[j].slug_question);if (objFormGenerator.sections[i].questions[j].status) {$('#form-review #question-status').val('1');} else {$('#form-review #question-status').val('0');}if (objFormGenerator.sections[i].questions[j].comment) {$('#form-review #question-comment').val(objFormGenerator.sections[i].questions[j].comment);} else {$('#form-review #question-comment').val('');}if (objFormGenerator.sections[i].questions[j].question_value) {$('#form-review #question-value').val(objFormGenerator.sections[i].questions[j].question_value);} else {$('#form-review #question-value').val(0);}$('#modal-review').modal('show');return true;}}}}});/*** Clicked on edit form*/$('body').on('click', 'button.btn-edit-form', function(e) {e.preventDefault();form_id = $(this).data('id')var action = $(this).data('href');$.ajax({'dataType': 'json','accept': 'application/json','method': 'get','url': action,}).done(function(response) {if (response['success']) {$('#form-main').attr('action', action);$('#form-main #form-id').val(response['data']['id']),$('#name').html(response['data']['name']);$('#comments').val(response['data']['comments'] || '');$('#text').html(response['data']['text']);$('#user').html(response['data']['user']);/*-------------Render Sections -------*/objFormGenerator.clear();objFormGenerator.sections = response['data']['content'] || [];objFormGenerator.render();renderSectionData(objFormGenerator.sections);$('#row-forms').hide();$('#row-edit').show();} else {$.fn.showError(response['message'] || 'ERROR_UNKNOWN');}}).fail(function(jqXHR, textStatus, errorThrown) {$.fn.showError(textStatus);});});$('button.btn-form-save-close').click(function(e) {var formContinue = parseFloat($('#form-main #form-continue').val());var data = {'comments': $('#form-main #comments').val(),'content': JSON.stringify(objFormGenerator.sections)}$.ajax({'dataType': 'json','method': 'post','url': $('#form-main').attr('action'),'data': data,}).done(function(response) {if (response['success']) {$.fn.showSuccess(response['data']);$('#row-edit').hide();$('#row-forms').show();/*---------- Reset Form -------- */$('#form-main')[0].reset();/*--------Reset Sections ----------*/clearSectionData();/* ------- Refresh Table -----------*/tableForm.fnDraw();} else {$.fn.showError(response['message'] || 'ERROR_UNKNOWN');}}).fail(function(jqXHR, textStatus, errorThrown) {$.fn.showError(textStatus);});return false;});/*** Clicked cancel new/edit Form*/$('button.btn-edit-cancel').click(function(e) {e.preventDefault();$('#row-edit').hide();$('#row-forms').show();});/*** Get Answers*/const getAnswer = (type, options, answer) => {if (type == 'open' || type == 'rating-range') {return answer;}if (type == 'multiple') {let opt = '';opt += removeTags(options.filter((opt) => answer.includes(opt.slug_option))[0].text) + ' ';return opt;}return removeTags(options.filter((opt) => opt.slug_option == answer)[0].text);}/*** Get Status*/const getStatus = (options, answer, type) => {let status;status = type == 'multiple' ?options.filter((opt) => answer.includes(opt.slug_option) && opt.correct == '1') :options.filter((opt) => opt.slug_option == answer && opt.correct == '1');return status.length != 0 ? '<font color="green">LABEL_CORRECT</font>' : '<font color="red">LABEL_FAIL</red>';}const getPtos = (options, answer, type, value, question_value) => {let ptos = 0;if (type == "open" || type == "rating-open" || type == "rating-range") {ptos = question_value ? question_value : 0;} else {if (type == 'multiple') {options.map((opt) => {if (answer.includes(opt.slug_option)) {ptos += parseFloat(opt.value);}})} else {options.map((opt) => {if (opt.slug_option == answer) {ptos = parseFloat(opt.value);}});}}return parseFloat(ptos).toFixed(2) + '/' + parseFloat(value).toFixed(2);}/*** Remove Html Tags*/const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')/*** Render Sections data*/const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {removeTags: removeTags,getAnswer: getAnswer,getStatus: getStatus,getPtos: getPtos}));/*** Clear Div Section data*/const clearSectionData = () => $("#rows").html('');/*** Clicked refresh button*/$('button.btn-refresh').click(function(e) {tableForm.fnDraw();});$('body').on('click', 'button.btn-delete', function(e) {e.preventDefault();var action = $(this).data('href');swal.fire({title: 'LABEL_ARE_YOU_SURE',icon: 'question',cancelButtonText: 'LABEL_NO',showCancelButton: true,confirmButtonText: 'LABEL_YES'}).then((result) => {if (result.isConfirmed) {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();});}});});/*** Format input number (Form Option)*/$('#form-review #question-value').inputNumberFormat({'decimal': 2});$('input[type=checkbox]').change(function() {tableForm.fnDraw();});});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_REVIEWS</h1></div></div></div><!-- /.container-fluid --></section><section class="content" style="padding: 13px;"><div class="container-fluid" id="row-forms"><div class="row"><div class="col-12"><div class="card"><div class="card-body"><table id="gridTable" class="table table-bordered"><thead><tr><th style="width: 16.6%;">LABEL_USER</th><th style="width: 16.6%;">LABEL_NAME</th><th style="width: 16.6%;">LABEL_LANGUAGE</th><th style="width: 16.6%;">LABEL_STATUS</th><th style="width: 16.6%;">LABEL_REGISTER</th><th style="width: 16.6%;">LABEL_ACTIONS</th></tr></thead><tbody></tbody></table></div><div class="card-footer clearfix"><div class="row"><div class="col-md-6 col-sm-6 col-xs-12"><div class="form-check"><input class="form-check-input" type="checkbox" id="only_pending" name="only_pending" value="1"><label class="form-check-label">LABEL_ONLY_PENDING</label></div></div><div class="col-md-6 col-sm-6 col-xs-12"><div style="float:right;"><button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button></div></div></div></div></div></div></div></div><!-- Create/Edit Form --><div class="row" id="row-edit" style="display: none"><div class="col-xs-12 col-md-12"><form action="#" name="form-main" id="form-main"><div class="form-group"><label for="form-status">LABEL_USER:</label><div id="user"></div></div><div class="form-group"><label for="form-status">LABEL_FORM:</label><div id="name"></div></div><div class="form-group"><label for="form-status">LABEL_DESCRIPTION:</label><div id="text"></div></div><div class="row"><div class="col-xs-12 col-md-12"><div class="panel-group" id="rows"></div></div></div><div class="row"><div class="col-xs-12 col-md-12"><div class="form-group"><label >LABEL_FINAL_COMMENT</label><textarea id="comments" name="comments" class="form-control" rows="10" cols="50" ></textarea></div></div></div><div class="form-group"><button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE</button><button type="button" class="btn btn-light btn-edit-cancel">LABEL_CANCEL</button></div></form></div></div><!-- Create/Edit Form--><div id="modal-review" class="modal" tabindex="-1" role="dialog"><div class="modal-dialog modal-lg" role="document"><form action="#" name="form-option" id="form-review"><input type="hidden" name="section" id="section" value="" /><input type="hidden" name="question" id="question" value="" /><div class="modal-content"><div class="modal-header"><h6 class="modal-title">LABEL_RESPONSE_REVIEW</h6><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button></div><div class="modal-body"><div class="form-group"><label for="option-text">LABEL_COMMENT</label><!-- ckeditor --><textarea name="question-comment" id="question-comment" rows="5" class="form-control" placeholder="LABEL_ENTER_COMMENT"></textarea></div><div class="form-group"><label for="question-status">LABEL_ANSWER_CORRECT</label><select name="question-status" id="question-status" class="form-control"><option value="1">LABEL_YES</option><option value="0">LABEL_NOT</option></select></div><div class="form-group"><label for="question-value">LABEL_VALUE</label><input type="text" name="question-value" id="question-value" class="form-control" /></div></div><div class="modal-footer"><button type="button" class="btn btn-primary btn-add-review">LABEL_SAVE</button><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close">LABEL_CLOSE</button></div></div></form></div></div><!---Template Sections ---><script id="sectionTemplate" type="text/x-jsrender"><div class="panel panel-default" id="panel-{{:slug_section}}"><div class="panel-heading"><h6 class="panel-title"><a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}"><span class="section-name{{:slug_section}}">{{:name}}</span></a></h6></div><div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show"><div class="panel-body"><div class="table-responsive"><table class="table table-bordered table-review"><thead><tr><th style="width: 30%;">LABEL_QUESTION</th><th style="width: 30%;">LABEL_ANSWER</th><th style="width: 10%;">LABEL_STATUS</th><th style="width: 15%;">LABEL_PTOS</th><th style="width: 15%;">LABEL_ACTIONS</th></tr></thead><tbody>{{for questions}}<tr class="tr-question"><td class="text-left">{{:~removeTags(text)}} </td><td>{{:~getAnswer(type,options,answer)}}</td><td>{{if type == 'simple' || type=='multiple' }}{{:~getStatus(options,answer,type)}}{{else}}{{if status}}<font color="green">LABEL_CORRECT</font>{{else}}<font color="red">LABEL_FAIL</font>{{/if}}{{/if}}</td><td>{{:~getPtos(options,answer,type, value, question_value)}}</td><td>{{if type != 'simple' && type !='multiple' }}<button class="btn btn-default btn-edit-review" data-original-title="LABEL_EDIT" data-section="{{:slug_section}}" data-question="{{:slug_question}}"><i class="fa fa-pencil" aria-hidden="true"></i> LABEL_EDIT</button>{{/if}}</td></tr>{{/for}}</tbody></table></div></div></div></div></script><!-- End Template Sections--></section>