Rev 924 | Rev 1105 | 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();$routeAdd = $this->url('settings/competencies/add');$routeDatatable = $this->url('settings/competencies');$routeImport = $this->url('settings/competencies/import');$allowAdd = $acl->isAllowed($roleName, 'settings/competencies/add') ? 1 : 0;$allowEdit = $acl->isAllowed($roleName, 'settings/competencies/edit') ? 1 : 0;$allowDelete = $acl->isAllowed($roleName, 'settings/competencies/delete') ? 1 : 0;$allowImport = $acl->isAllowed($roleName, 'settings/competencies/import') ? 1 : 0;$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.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->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/select2/js/select2.js'));$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/i18n/es.js'));$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.css'));$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.css'));// JsRender //$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));// bootbox Alert //$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));$status_active = \LeadersLinked\Model\Competency::STATUS_ACTIVE;$this->inlineScript()->captureStart();echo <<<JSlet behaviors = [];jQuery(document).ready(function($) {$.validator.setDefaults({debug: true,highlight: function(element) {$(element).addClass('is-invalid');},unhighlight: function(element) {$(element).removeClass('is-invalid');},errorElement: 'span',errorClass: 'error invalid-feedback',errorPlacement: function(error, element) {const child = element.children(':first-child');if (element[0].localName == 'input') {let _error = error_error[0].style.display = 'block'_error.insertBefore(element);} else if (element.parent('.form-group').length) {error.insertAfter(element);} else if (element.parent('.toggle').length) {error.insertAfter(element.parent().parent());} else {error.insertAfter(element.parent());}}});$.fn.showFormErrorValidator = function(fieldname, errors) {var field = $(fieldname);if (field) {$(field).addClass('is-invalid');var error = $('<span id="' + fieldname + '-error" class="error invalid-feedback">' + errors + '</div>');if (field.parent('.form-group').length) {error.insertAfter(field);} else if (field.parent('.toggle').length) {error.insertAfter(field.parent().parent());} else {error.insertAfter(field.parent());}}};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': 'type'},{'mDataProp': 'name'},{'mDataProp': 'status'},{'mDataProp': 'actions'},],'columnDefs': [{'targets': 0,'className': 'text-vertical-middle',},{'targets': 1,'className': 'text-vertical-middle',},{'targets': -2,'orderable': false,'className': 'text-center','render': function(data, type, row) {checked = data == 'a' ? ' checked="checked" ' : '';return '<div class="checkbox checkbox-success">' +'<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +'<label ></label></div>';}},{'targets': -1,'orderable': false,'render': function(data, type, row) {s = '';if (allowEdit) {s = s + '<button class="btn btn-primary btn-edit" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button> ';}if (allowDelete) {s = s + '<button class="btn btn-danger 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: {'competency_type_id': {required: true,},'name': {required: true,maxlength: 128,},'description': {updateCkeditor: function() {CKEDITOR.instances.description.updateElement();},required: true,},'status': {required: false,},},submitHandler: function(form) {if (behaviors.length == 0) {$.fn.showError('ERROR_NOT_OBSERVABLE_CONDUCT');} else {$.ajax({'dataType': 'json','accept': 'application/json','method': 'post','url': $('#form').attr('action'),'data': {'name': $('#name').val(),'description': $('#description').val(),'competency_type_id': $('#competency_type_id').val(),'status': $('#status').val(),'behaviors': JSON.stringify(behaviors)}}).done(function(response) {NProgress.start();if (response['success']) {$.fn.showSuccess(response['data']);$('#row-form').hide();$('#row-list').show();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 #competency_type_id').val('').trigger('change');$('#form #status').bootstrapToggle('on');behaviors=[];CKEDITOR.instances.description.setData('');validator.resetForm();$('#row-form').show();$('#row-list').hide();$("#rows").html('');return false;});$('body').on('click', 'button.btn-edit', function(e) {e.preventDefault();NProgress.start();var action = $(this).data('href');$("#rows").html('');$.ajax({'dataType': '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 #competency_type_id').val(response['data']['competency_type_id']).trigger('change');$('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')CKEDITOR.instances.description.setData(response['data']['description']);behaviors=response['data']['behaviors'] || [];renderData(behaviors);validator.resetForm();$('#row-form').show();$('#row-list').hide();} else {$.fn.showError(response['data']);}}).fail(function(jqXHR, textStatus, errorThrown) {$.fn.showError(textStatus);}).always(function() {NProgress.done();});return false;});$('body').on('click', 'button.btn-refresh', function(e) {e.preventDefault();gridTable.api().ajax.reload(null, false);return false;});$('body').on('click', 'button.btn-import', function(e) {e.preventDefault();NProgress.start();$.ajax({'dataType': 'json','method': 'post','url': '$routeImport',}).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();});return false;});$('body').on('click', 'button.btn-cancel', function(e) {e.preventDefault();$('#modal').modal('hide');});$('#form #competency_type_id').select2({theme: 'bootstrap4',width: '100%',});$('#form #status').bootstrapToggle({'on': 'LABEL_ACTIVE','off': 'LABEL_INACTIVE','width': '160px','height': '40px'});CKEDITOR.replace('description');/*** Clicked on add new conduct*/$('body').on('click', 'button[id="btn-add-conduct"]', function(e) {e.preventDefault();$('#form-conduct #conduct-id').val('');$('#form-conduct #conduct-description').val('');$('#form-conduct #conduct-level').val('0');$('#modal-conduct h4[class="modal-title"]').html('LABEL_ADD LABEL_CONDUCT');$('#modal-conduct').modal('show');});/*** Clicked on edit conduct*/$('body').on('click', 'button.btn-edit-conduct', function(e) {e.preventDefault();var id = $(this).data('conduct');behaviors.map((item) => {if (item.id == id) {$('#form-conduct #conduct-id').val(item.id);$('#form-conduct #conduct-description').val(item.description);$('#form-conduct #conduct-level').val(item.level);$('#modal-conduct h4[class="modal-title"]').html('LABEL_EDIT LABEL_CONDUCT');$('#modal-conduct').modal('show');return;}});});/*** Clicked on remove conduct*/$('body').on('click', 'button.btn-delete-conduct', function(e) {e.preventDefault();var id = $(this).data('conduct');bootbox.confirm({title: "LABEL_DELETE LABEL_CONDUCT",message: "LABEL_QUESTION_DELETE",buttons: {cancel: {label: '<i class="fa fa-times"></i> LABEL_CANCEL'},confirm: {label: '<i class="fa fa-check"></i> LABEL_ACCEPT'}},callback: function(result) {if (result) {removeBehavior(id);}}});});/*** Clicked cancel new/edit Form*/$('button.btn-conduct-submit').click(function(e) {if ($("#conduct-description").val() == "") {$.fn.showError('ERROR_ENTER_DESCRIPTION');return;} else {$("#conduct-id").val() == "" ?addBehavior($("#conduct-description").val(), $("#conduct-level").val()) :editBehavior($("#conduct-id").val(), $("#conduct-description").val(), $("#conduct-level").val())$('#modal-conduct').modal('hide');return;}});/*** Clicked cancel new/edit Form*/$('button.btn-edit-cancel').click(function(e) {e.preventDefault();$('#row-form').hide();$('#row-list').show();});/*** Add Behavior to array*/const addBehavior = (description, level) => {behaviors.push({'id': new Date().getTime(),'description': description,'level': level});renderData(behaviors);}/*** Edit item behavior*/const editBehavior = (id, description, level) => {behaviors.map((item) => {if (item.id == id) {item.description = description;item.level = level}});renderData(behaviors);}/*** Remove behavior*/const removeBehavior = (id) => {behaviors = behaviors.filter((item) => item.id != id);renderData(behaviors);}/*** Render Sections data*/const renderData = (data) => $("#rows").html($("#behaviorTemplate").render(data));});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_COMPETENCIES</h1></div></div></div><!-- /.container-fluid --></section><section class="content" id="row-list"><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_TYPE</th><th>LABEL_NAME</th><th>LABEL_ACTIVE</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($allowImport) : ?><button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button><?php endif; ?><?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><!-- The Form creation --><section class="content" id="row-form" style="display: none"><div class="container-fluid"><div class="row"><div class="col-md-12 col-sm-12 col-12"><div class="panel"><div class="panel-body"><?php$form = $this->form;$form->setAttributes(['method' => 'post','name' => 'form','id' => 'form']);$form->prepare();echo $this->form()->openTag($form);?><div class="row"><div class="col-md-4 col-sm-12 col-12"><div class="from-group"><?php$element = $form->get('competency_type_id');$element->setOptions(['label' => 'LABEL_TYPE']);echo $this->formLabel($element);echo $this->formSelect($element);?></div></div><div class="col-md-4 col-sm-12 col-12"><div class="from-group"><?php$element = $form->get('name');$element->setOptions(['label' => 'LABEL_NAME']);$element->setAttributes(['class' => 'form-control']);echo $this->formLabel($element);echo $this->formText($element);?></div></div><div class="col-md-4 col-sm-12 col-12"><div class="from-group"><label>LABEL_STATUS</label><br /><?php$element = $form->get('status');$element->setOptions(['label' => 'LABEL_STATUS']);// echo $this->formLabel($element);echo $this->formCheckbox($element);?></div></div><div class="col-md col-sm-12 col-12"><div class="form-group"><?php$element = $form->get('description');$element->setOptions(['label' => 'LABEL_DESCRIPTION']);$element->setAttributes(['class' => 'form-control']);echo $this->formLabel($element);echo $this->formTextArea($element);?></div></div><?php echo $this->form()->closeTag($form); ?><div class="col-xs-12 col-md-12 text-right"><button class="btn btn-primary" id="btn-add-conduct" data-toggle="tooltip" title="LABEL_ADD LABEL_CONDUCT"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_CONDUCT</button></div><div class="col-xs-12 col-md-12"><br/><div class="table-responsive"><table class="table table-bordered"><thead><tr><th style="width: 40%;">LABEL_DESCRIPTION</th><th style="width: 20%;">LABEL_LEVEL</th><th style="width: 20%;">LABEL_ACTIONS</th></tr></thead><tbody id="rows"></tbody></table></div><div class="col-xs-12 col-md-12"><div class="form-group"><button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button><button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button></div></div></div></div></div></div></div></section><!---end form---><!--start modal conduct--><div id="modal-conduct" class="modal" tabindex="-1" role="dialog"><div class="modal-dialog modal-lg" role="document"><form action="#" name="form-conduct" id="form-conduct"><input type="hidden" name="conduct-id" id="conduct-id" value="" /><input type="hidden" name="conduct-competencia" id="conduct-competencia" value="" /><div class="modal-content"><div class="modal-header"><h4 class="modal-title">LABEL_ADD LABEL_CONDUCT</h4><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body"><div class="form-group"><label for="conduct-name">LABEL_DESCRIPTION</label><input type="text" name="conduct-description" id="conduct-description" class="form-control" maxlength="95" value="" /></div><div class="form-group"><label for="conduct-value">LABEL_LEVEL</label><select class="form-control" id="conduct-level" name="conduct-level"><option value="0">LABEL_NA</option><option value="1">LABEL_LEVEL_ONE</option><option value="2">LABEL_LEVEL_TWO</option><option value="3">LABEL_LEVEL_THREE</option><option value="4">LABEL_LEVEL_FOUR</option></select></div></div><div class="modal-footer"><button type="button" class="btn btn-primary btn-conduct-submit">LABEL_SAVE</button><button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button></div></div></form></div></div><!---end modal conduct ---><!--start template---><script id="behaviorTemplate" type="text/x-jsrender"><tr><td class="text-left">{{:description}}</td><td>{{if level == '0'}} LABEL_NA {{/if}}{{if level == '1' }} LABEL_LEVEL_ONE {{/if}}{{if level == '2' }} LABEL_LEVEL_TWO {{/if}}{{if level == '3' }} LABEL_LEVEL_THREE {{/if}}{{if level == '4' }} LABEL_LEVEL_FOUR {{/if}}</td><td><button class="btn btn-default btn-edit-conduct" data-conduct="{{:id}}" data-toggle="tooltip" data-original-title="LABEL_EDIT"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT</button><button class="btn btn-default btn-delete-conduct" data-conduct="{{:id}}" data-toggle="tooltip" data-original-title="LABEL_DELETE"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE</button></td></tr></script><!--end template--->