594 lines
16 KiB
JavaScript
594 lines
16 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
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/FormalizacionConfigPruebaAPI/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.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.DescripcionEtapa, item.DescripcionTipoDoc, item.DescripcionVariante, 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 (id,especifico) {
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
|
|
var valorvariante;
|
|
|
|
if (CatalogoItem != null) {
|
|
|
|
$('#hiddenId').val(id)
|
|
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.IdConfiguracion == id) {
|
|
$('#hiddenEtapa').val(item.IdEtapa)
|
|
$('#hiddenTipoDocumento').val(item.IdTipoDocumento)
|
|
$('#hiddenVariante').val(item.IdVariante)
|
|
valorvariante = item.ValorVariante
|
|
|
|
$('#txtEtapa').val(item.DescripcionEtapa);
|
|
$('#txtTipoDocumento').val(item.DescripcionTipoDoc);
|
|
$('#txtVariante').val(item.DescripcionVariante);
|
|
|
|
if (item.EsEspecifico == false) { valueEspecifico = "0"; } else { valueEspecifico = "1"; }
|
|
}
|
|
});
|
|
if (valueEspecifico == "1") {
|
|
$("#chkEspecifico").prop("checked", true);
|
|
} else {
|
|
$("#chkEspecifico").prop("checked", false);
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "1") {
|
|
ocultar();
|
|
$('#lblCategoria').show();
|
|
$('#txtCategoria').show();
|
|
$('#txtCategoria').val('');
|
|
$('#btn_eliminarCategoria').show();
|
|
$('#btnCategoria').show();
|
|
obtenerCategoria(valorvariante);
|
|
$("#txtCategoria").noRequired();
|
|
}
|
|
if ($('#hiddenVariante').val() == "2") {
|
|
ocultar();
|
|
$('#lblFacilidad').show();
|
|
$('#txtFacilidad').show();
|
|
$('#txtFacilidad').val('');
|
|
$('#btn_eliminarFacilidad').show();
|
|
$('#btnFacilidad').show();
|
|
obtenerFacilidad(valorvariante);
|
|
$("#txtFacilidad").noRequired();
|
|
}
|
|
if ($('#hiddenVariante').val() == "3") {
|
|
ocultar();
|
|
$('#lblGarantia').show();
|
|
$('#chkGarantia').show();
|
|
$('#chkGarantia').prop("checked", false);
|
|
|
|
if (valorvariante == "1") {
|
|
$("#chkGarantia").prop("checked", true);
|
|
} else {
|
|
$("#chkGarantia").prop("checked", false);
|
|
}
|
|
|
|
}
|
|
|
|
$("#formCatalogo").validateElement("#txtEtapa");
|
|
$("#formCatalogo").validateElement("#txtTipoDocumento");
|
|
$("#formCatalogo").validateElement("#txtVariante");
|
|
|
|
$("#formCatalogo").validateElement("#chkEspecifico");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Formalización Configuración : ' + id);
|
|
|
|
$('#btnInsertar').hide();
|
|
$('#btnGuardar').show();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (id, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar la Configuración Documentos Legales?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar la Configuración Documentos Legales?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID de la Configuración Documentos Legales?.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
if (value == '1')
|
|
{
|
|
value = true
|
|
}
|
|
else
|
|
{
|
|
value = false
|
|
}
|
|
|
|
FormalizacionConfiguracionDocumentosLegales = {
|
|
IdConfiguracion: id,
|
|
Habilitado: value,
|
|
|
|
}
|
|
|
|
var uri = 'api/FormalizacionConfigPruebaAPI/toggleStateItem/';
|
|
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 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 (!$("#txtEtapa").valid()) {
|
|
toastr.warning("Favor Seleccionar la Etapa.");
|
|
return false;
|
|
}
|
|
|
|
if (!$("#txtTipoDocumento").valid()) {
|
|
toastr.warning("Favor Seleccionar el Tipo Documento.");
|
|
return false;
|
|
}
|
|
|
|
if (!$("#txtVariante").valid()) {
|
|
toastr.warning("Favor Seleccionar la Variante.");
|
|
return false;
|
|
}
|
|
|
|
|
|
if ($('#hiddenVariante').val() == "1") {
|
|
if (!$("#txtCategoria").length < 1) {
|
|
toastr.warning("Favor Seleccionar la Categoría.");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "2") {
|
|
|
|
if (!$("#txtFacilidad").length < 1) {
|
|
toastr.warning("Favor Seleccionar la Facilidad.");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
if (!confirm("Se guardarán los cambios.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
if ($('#hiddenVariante').val() == "1") {
|
|
Item = {
|
|
IdConfiguracion: $("#hiddenId").val(),
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $("#hiddenCategoria").val(),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "2") {
|
|
Item = {
|
|
IdConfiguracion: $("#hiddenId").val(),
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $("#hiddenFacilidad").val(),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
if ($('#hiddenVariante').val() == "3") {
|
|
Item = {
|
|
IdConfiguracion: $("#hiddenId").val(),
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdVariante: $('#hiddenVariante').val(),
|
|
ValorVariante: $('#chkGarantia').is(":checked"),
|
|
EsEspecifico: $('#chkEspecifico').is(":checked")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var uri = 'api/FormalizacionConfigPruebaAPI/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 (!$("#txtEtapa").valid()) {
|
|
toastr.warning("Favor Seleccionar la Etapa.");
|
|
return false;
|
|
}
|
|
|
|
if (!$("#txtTipoDocumento").valid()) {
|
|
toastr.warning("Favor Seleccionar el Tipo Documento.");
|
|
return false;
|
|
}
|
|
|
|
if (!$("#txtVariante").valid()) {
|
|
toastr.warning("Favor Seleccionar la Variante.");
|
|
return false;
|
|
}
|
|
|
|
|
|
if ($('#hiddenVariante').val() == "1") {
|
|
if (!$("#txtVariante").valid()) {
|
|
toastr.warning("Favor Seleccionar la Categoría.");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
if ($('#hiddenVariante').val() == "2") {
|
|
|
|
if (!$("#txtVariante").valid()) {
|
|
toastr.warning("Favor Seleccionar la Facilidad.");
|
|
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/FormalizacionConfigPruebaAPI/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('Nueva Formalización Configuración Documentos Legales');
|
|
|
|
$('#txtEtapa').val('');
|
|
$("#formCatalogo").validateElement("#txtEtapa");
|
|
|
|
$('#txtTipoDocumento').val('');
|
|
$("#formCatalogo").validateElement("#txtTipoDocumento");
|
|
|
|
$('#txtVariante').val('');
|
|
$("#formCatalogo").validateElement("#txtVariante");
|
|
|
|
$('#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();
|
|
$('#txtCategoria').val('');
|
|
$('#btn_eliminarCategoria').show();
|
|
$('#btnCategoria').show();
|
|
}
|
|
if (data.codigo == "2") {
|
|
ocultar();
|
|
$('#lblFacilidad').show();
|
|
$('#txtFacilidad').show();
|
|
$('#txtFacilidad').val('');
|
|
$('#btn_eliminarFacilidad').show();
|
|
$('#btnFacilidad').show();
|
|
}
|
|
if (data.codigo == "3") {
|
|
ocultar();
|
|
$('#lblGarantia').show();
|
|
$('#chkGarantia').show();
|
|
$('#chkGarantia').prop("checked", false);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
this.obtenerCategoria = function(id){
|
|
|
|
var uri = 'api/FormalizacionConfigPruebaAPI/ObtenerCategoria?idtipocategoria=' + (id);
|
|
var descripcion;
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
$.each(data, function (key, item) {
|
|
$('#txtCategoria').val(item.Descripcion);
|
|
});
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde");
|
|
}).then(function (value) {
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|
|
|
|
this.obtenerFacilidad = function (id) {
|
|
|
|
var uri = 'api/FormalizacionConfigPruebaAPI/ObtenerFacilidad?idfacilidad=' + (id);
|
|
var descripcion;
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
$.each(data, function (key, item) {
|
|
$('#txtFacilidad').val(item.Descripcion);
|
|
});
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde");
|
|
}).then(function (value) {
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|