454 lines
13 KiB
JavaScript
454 lines
13 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var id_colFacilidad = 2;
|
|
var CatalogoItem = {};
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_FormaConfigDocLegales", "Cathay_FormaConfigDocLegales", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
ocultar();
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
InsertarItem();
|
|
});
|
|
});
|
|
|
|
//#endregion
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
|
|
var uri = 'api/FormalizacionConfiguracionDocumentosLegalesAPI/Obtener/';
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodConfig]", item.IdConfiguracion, option);
|
|
|
|
var stateIcon = $("#ucItemsIcon").html();
|
|
var especifico = $("#ucIEspecifico").html();
|
|
|
|
if (item.Habilitado == 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);
|
|
}
|
|
|
|
|
|
if (item.EsEspecifico == true) {
|
|
especifico = replaceAll("[$icon]", "fa-check-circle", especifico);
|
|
especifico = replaceAll("[$state_color]", "success", especifico);
|
|
option = replaceAll("[$valueEspecifico]", "1", option);
|
|
}
|
|
else {
|
|
especifico = replaceAll("[$icon]", "fa-check-circle", especifico);
|
|
especifico = replaceAll("[$state_color]", "muted", especifico);
|
|
option = replaceAll("[$valueEspecifico]", "0", option);
|
|
}
|
|
|
|
|
|
TableItems.row.add([stateIcon, item.IdConfiguracion, item.IdEtapa, item.IdTipoDocumento, item.IdVariante, item.ValorVariante, especifico, option]).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.EditarItem = function (idConfiguracion, valueEspecifico) {
|
|
// idEtapa, idTipoDoc, idVariante,
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
|
|
if (CatalogoItem != null) {
|
|
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.IdConfiguracion == idConfiguracion) {
|
|
$('#hiddenEtapa').val(item.IdEtapa)
|
|
$('#hiddenTipoDocumento').val(item.IdTipoDocumento)
|
|
$('#hiddenVariante').val(item.IdVariante)
|
|
|
|
$('#txtEtapa').val(item.Etapas.Descripcio);
|
|
$('#txtTipoDocumento').val(item.TipoDocumento.Descripcion);
|
|
$('#txtVariante').val(item.Variante.Descripcion);
|
|
$('#txtValorVariante').val(item.Variante.Descripcion);
|
|
|
|
if (item.EsEspecifico == false) { valueEspecifico = "0"; } else { valueEspecifico = "1"; }
|
|
|
|
|
|
}
|
|
});
|
|
|
|
if (valueEspecifico == "1") {
|
|
$("#chkEspecifico").prop("checked", true);
|
|
} else {
|
|
$("#chkEspecifico").prop("checked", false);
|
|
}
|
|
|
|
$("#formCatalogo").validateElement("#txtEtapa");
|
|
$("#formCatalogo").validateElement("#txtTipoDocumento");
|
|
$("#formCatalogo").validateElement("#txtVariante");
|
|
$("#formCatalogo").validateElement("#txtValorVariante");
|
|
|
|
$("#formCatalogo").validateElement("#chkEspecifico");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Formalización Configuración Documentos Legales: '+ idConfiguracion);
|
|
|
|
$('#btnInsertar').hide();
|
|
$('#btnGuardar').show();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (idconfiguracion, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar la Formalización Configuración Documentos Legales?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar la Formalización Configuración Documentos Legales?';
|
|
}
|
|
|
|
if (idcategoria == null && idfacilidad == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID la Formalización Configuración Documentos Legales seleccionada.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Item = {
|
|
IdConfiguracion: idconfiguracion,
|
|
Habilitado: value,
|
|
|
|
}
|
|
|
|
var uri = 'api/FormalizacionConfiguracionDocumentosLegalesAPI/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 (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Se guardarán los cambios.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
if ($('#hiddenVariante').val() == "1") {
|
|
Item = {
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $("#hiddenCategoria").val(),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "2") {
|
|
Item = {
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $("#hiddenFacilidad").val(),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "3") {
|
|
Item = {
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $('#chkGarantia').is(":checked"),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var uri = 'api/FormalizacionConfiguracionDocumentosLegalesAPI/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 Formalización Configuración Documentos Legales');
|
|
|
|
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 Formalización Configuración Documentos Legales.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
if ($('#hiddenVariante').val() == "1") {
|
|
FormalizacionConfiguracionDocumentosLegales = {
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $('#hiddenCategoria').val(),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "2") {
|
|
FormalizacionConfiguracionDocumentosLegales = {
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $('#hiddenFacilidad').val(),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "3") {
|
|
FormalizacionConfiguracionDocumentosLegales = {
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $('#chkGarantia').is(":checked"),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var uri = 'api/FormalizacionConfiguracionDocumentosLegalesAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(FormalizacionConfiguracionDocumentosLegales);
|
|
|
|
$.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 Categoría por Facilidad');
|
|
|
|
$('#txtEtapa').val('');
|
|
$("#formCatalogo").validateElement("#txtEtapa");
|
|
|
|
$('#txtTipoDocumento').val('');
|
|
$("#formCatalogo").validateElement("#txtTipoDocumento");
|
|
|
|
$('#txtVariante').val('');
|
|
$("#formCatalogo").validateElement("#txtVariante");
|
|
|
|
$('#txtValorVariante').val('');
|
|
$("#formCatalogo").validateElement("#txtValorVariante");
|
|
|
|
$('#chkEspecifico').prop("checked", false);
|
|
ocultar();
|
|
|
|
}
|
|
|
|
this.ocultar = function () {
|
|
|
|
$('#lblCategoria').hide();
|
|
$('#txtCategoria').hide();
|
|
$('#btn_eliminarCategoria').hide();
|
|
$('#btnCategoria').hide();
|
|
|
|
$('#lblFacilidad').hide();
|
|
$('#txtFacilidad').hide();
|
|
$('#btn_eliminarFacilidad').hide();
|
|
$('#btnFacilidad').hide();
|
|
|
|
$('#lblGarantia').hide();
|
|
$('#chkGarantia').hide();
|
|
|
|
}
|
|
|
|
this.DataCatalogo = function (SelectedCatalog, data) {
|
|
|
|
if (SelectedCatalog == "Variante") {
|
|
if (data.codigo == "1") {
|
|
ocultar();
|
|
$('#lblCategoria').show();
|
|
$('#txtCategoria').show();
|
|
$('#btn_eliminarCategoria').show();
|
|
$('#btnCategoria').show();
|
|
}
|
|
if (data.codigo == "2") {
|
|
ocultar();
|
|
$('#lblFacilidad').show();
|
|
$('#txtFacilidad').show();
|
|
$('#btn_eliminarFacilidad').show();
|
|
$('#btnFacilidad').show();
|
|
}
|
|
if (data.codigo == "3") {
|
|
ocultar();
|
|
$('#lblGarantia').show();
|
|
$('#chkGarantia').show();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|