510 lines
13 KiB
JavaScript
510 lines
13 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
var CatalogoItem = {};
|
|
var CatalogoRoles = {};
|
|
|
|
jQuery(document).ready(function () {
|
|
$('#txtDescripcionEstruct').attr('size', 50);
|
|
|
|
|
|
GetControlsSettings("Cathay_EstructuraOrgChart", "Cathay_EstructuraOrgChart", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertarRol').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
$('#btnInsertar').show();
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
InsertarItem();
|
|
});
|
|
|
|
|
|
$('#btnInsertarRol').click(function () {
|
|
LeerExistente();
|
|
});
|
|
|
|
|
|
});
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
var uri = 'api/EstructuraOrgChartAPI/ObtenerItems/';
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
CatalogoItem = data;
|
|
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdEstructuraOrgChart, option);
|
|
|
|
var stateIcon = $("#ucItemsIcon").html();
|
|
|
|
if (item.Estado == false) {
|
|
stateIcon = replaceAll("[$icon]", "fa-check-circle", stateIcon);
|
|
stateIcon = replaceAll("[$state_color]", "muted", stateIcon);
|
|
|
|
option = replaceAll("[$opcion]", "Habilitar", option);
|
|
option = replaceAll("[$icon]", "fa-check", option);
|
|
option = replaceAll("[$value]", "1", option);
|
|
}
|
|
else {
|
|
stateIcon = replaceAll("[$icon]", "fa-check-circle", stateIcon);
|
|
stateIcon = replaceAll("[$state_color]", "success", stateIcon);
|
|
|
|
option = replaceAll("[$opcion]", "Deshabilitar", option);
|
|
option = replaceAll("[$icon]", "fa-times", option);
|
|
option = replaceAll("[$value]", "0", option);
|
|
}
|
|
TableItems.row.add([stateIcon, item.IdEstructuraOrgChart, item.Name, item.TipoEstructuraOrgChart.Descripcion, option]).draw();// item.RolFuncional[0].Descripcion
|
|
|
|
document.getElementById('panelRol').style.display = 'block'
|
|
});
|
|
|
|
//if (data != null) {
|
|
// ObtenerRol(data[0].IdEstructuraOrgChart)
|
|
//}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde");
|
|
|
|
console.log("Request Failed: " + textStatus + ', ' + error);
|
|
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|
|
this.EditarItem = function (id) {
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
var indexes = getRowIndex(TableItems, id_column, id);
|
|
|
|
if (indexes != null) {
|
|
|
|
$('#hiddenId').val(id)
|
|
$('#txtDescripcionEstruct').val(TableItems.cell(indexes,2).data());
|
|
$('#txtTipoEstructuraOrgChart').val(TableItems.cell(indexes,3).data());
|
|
|
|
$("#formCatalogo").validateElement("#txtDescripcionEstruct");
|
|
$("#formCatalogo").validateElement("#txtTipoEstructuraOrgChart");
|
|
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.IdEstructuraOrgChart == id) {
|
|
$('#hiddenTipoEstructuraOrgChart').val(item.IdTipoEstructuraOrgChart);
|
|
}
|
|
});
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valor de Campo ID: ' + id);
|
|
$('#btnInsertar').hide();
|
|
$('#btnGuardar').show();
|
|
}
|
|
$('#btnInsertarRol').show();
|
|
ObtenerRol(id)
|
|
}
|
|
|
|
this.toggleEnabledItem = function (id, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar la Estructura OrgChart?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar la Estructura OrgChart?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID de la Estructura OrgChart seleccionada.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Item = {
|
|
IdEstructuraOrgChart: id,
|
|
Estado: value
|
|
}
|
|
|
|
var uri = 'api/EstructuraOrgChartAPI/toggleStateItem/';
|
|
var DTO = JSON.stringify(Item);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
|
|
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información actualizada con exito', 'Completado');
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
TableItems.clear().draw();
|
|
obtenerItems();
|
|
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
this.ActualizarItem = function () {
|
|
|
|
if (!$("#txtTipoEstructuraOrgChart").valid()) {
|
|
toastr.warning("Favor Seleccionar el Rol Funcional.");
|
|
return false;
|
|
}
|
|
if (!$("#txtDescripcionEstruct").valid()) {
|
|
toastr.warning("Favor Ingresar la Descripción.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Se guardarán los cambios.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Item = {
|
|
IdEstructuraOrgChart: $("#hiddenId").val(),
|
|
Name: $('#txtDescripcionEstruct').val(),
|
|
IdTipoEstructuraOrgChart: $("#hiddenTipoEstructuraOrgChart").val(),
|
|
}
|
|
|
|
var uri = 'api/EstructuraOrgChartAPI/ModificarItem/';
|
|
var DTO = JSON.stringify(Item);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información guardada con exito', 'Completado');
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Ingresar Nueva Estructura OrgChart');
|
|
|
|
TableItems.clear().draw();
|
|
|
|
obtenerItems();
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
}
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
});
|
|
}
|
|
|
|
this.InsertarItem = function () {
|
|
|
|
if (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
if (!confirm("Va a Ingresar una Nueva Estructura OrgChart.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
EstructuraOrgChart = {
|
|
|
|
Name: $('#txtDescripcionEstruct').val(),
|
|
IdTipoEstructuraOrgChart: $("#hiddenTipoEstructuraOrgChart").val(),
|
|
RolFuncionalEstructuraOrgChart:[
|
|
{
|
|
IdRolFuncional: $("#hiddenRolFuncional").val(),
|
|
}
|
|
]
|
|
|
|
}
|
|
|
|
var uri = 'api/EstructuraOrgChartAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(EstructuraOrgChart);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información guardada con exito', 'Completado');
|
|
limpiar();
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
TableItems.clear().draw();
|
|
obtenerItems();
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
|
|
});
|
|
}
|
|
|
|
this.limpiar = function () {
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Ingresar Nueva EstructuraOrgChart');
|
|
|
|
$('#txtDescripcionEstruct').val('');
|
|
$("#formCatalogo").validateElement("#txtDescripcionEstruct");
|
|
|
|
$("#txtTipoEstructuraOrgChart").val('');
|
|
$("#formCatalogo").validateElement("#txtTipoEstructuraOrgChart");
|
|
|
|
$("#txtRolFuncional").val('');
|
|
$("#formCatalogo").validateElement("#txtRolFuncional");
|
|
|
|
$('#lbTitulRol').empty();
|
|
$('#lbTitulRol').append('Ingresar Rol Funcional');
|
|
|
|
$('#btnInsertarRol').hide();
|
|
|
|
var TableRoles = $('#TableRoles').DataTable();
|
|
TableRoles.clear().draw();
|
|
|
|
}
|
|
|
|
this.ObtenerRol = function (idestrutura) {
|
|
|
|
|
|
$('#lbTitulRol').empty();
|
|
$('#lbTitulRol').append('Roles Funcionales de la Estructura Id: '+ idestrutura );
|
|
|
|
var uri = 'api/EstructuraOrgChartAPI/ObtenerRol?idestructura=' + (idestrutura);
|
|
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
CatalogoRoles = data;
|
|
|
|
|
|
var TableRoles = $('#TableRoles').DataTable();
|
|
TableRoles.clear().draw();
|
|
|
|
$.each(data[0].RolFuncionalEstructuraOrgChart, function (key, item) {
|
|
|
|
var optionRol = $("#ucItemsRol").html();
|
|
|
|
optionRol = replaceAll("[$CodItem]", item.IdEstructuraOrgChart, optionRol);
|
|
|
|
optionRol = replaceAll("[$CodEstructura]", item.IdEstructuraOrgChart, optionRol);
|
|
optionRol = replaceAll("[$CodRol]", item.IdRolFuncional, optionRol);
|
|
|
|
|
|
TableRoles.row.add([item.IdRolFuncional, item.RolFuncional.Descripcion, optionRol]).draw();
|
|
|
|
});
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde");
|
|
|
|
console.log("Request Failed: " + textStatus + ', ' + error);
|
|
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|
|
this.InsertarRoles = function () {
|
|
|
|
if (!$("#txtRolFuncional").valid()) {
|
|
toastr.warning("Favor Seleccionar el Rol Funcional.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a asignarle este Rol Funcional a esta Estructura.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableRoles = $('#TableRoles').DataTable();
|
|
|
|
RolFuncionalEstructuraOrgChart = {
|
|
IdEstructuraOrgChart: $("#hiddenId").val(),
|
|
IdRolFuncional: $("#hiddenRolFuncional").val(),
|
|
}
|
|
|
|
var uri = 'api/EstructuraOrgChartAPI/InsertarRol/';
|
|
var DTO = JSON.stringify(RolFuncionalEstructuraOrgChart);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
|
|
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información guardada con exito', 'Completado');
|
|
|
|
ObtenerRol($("#hiddenId").val());
|
|
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.EliminarRol = function (CodEstructura, CodRol) {
|
|
|
|
|
|
if (!confirm("Se Eliminara el Rol Funcional.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableRoles = $('#TableRoles').DataTable();
|
|
|
|
|
|
Item = {
|
|
IdRolFuncional: CodRol,
|
|
IdEstructuraOrgChart: CodEstructura
|
|
}
|
|
|
|
var uri = 'api/EstructuraOrgChartAPI/EliminarRol/';
|
|
var DTO = JSON.stringify(Item);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información guardada con exito', 'Completado');
|
|
limpiar();
|
|
|
|
TableRoles.clear().draw();
|
|
ObtenerRol(CodEstructura);
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
}
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
this.LeerExistente = function () {
|
|
|
|
var IdRol = 0;
|
|
var Existe = false;
|
|
TableRoles = $('#TableRoles').DataTable();
|
|
IdRol = $("#hiddenRolFuncional").val();
|
|
|
|
$.each(CatalogoRoles[0].RolFuncionalEstructuraOrgChart, function (key, item) {
|
|
if (item.IdRolFuncional == IdRol)
|
|
{
|
|
Existe = true;
|
|
}
|
|
});
|
|
|
|
if (Existe == true) {
|
|
toastr.error("Este Rol Funcional ya ha sido Ingresado a esta Estructura.");
|
|
}
|
|
else
|
|
{
|
|
InsertarRoles();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|