443 lines
13 KiB
JavaScript
443 lines
13 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo = null;
|
|
var CatalogoItem = {};
|
|
var TableItems = null;
|
|
|
|
var id_columnDocumento = 1;
|
|
var id_columnCategoria = 2;
|
|
var id_comlumCliente = 3;
|
|
var id_comlumClasificacion = 4;
|
|
var id_comlumIngreso = 5;
|
|
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_DocumentosEtapa", "Cathay_DocumentosEtapa", "formCatalogo");
|
|
|
|
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
Limpiar(1);
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
|
|
if ($('#hiddenIdDocumentosEtapa').val() != "")
|
|
ActualizarItem();
|
|
else
|
|
InsertarItem();
|
|
});
|
|
|
|
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
//$('#btnInsertar').click(function () {
|
|
// InsertarItem();
|
|
//});
|
|
|
|
//$(':checkbox').on('change', function () {
|
|
// $(':checkbox').not(this).prop('checked', false);
|
|
//});
|
|
|
|
|
|
});
|
|
|
|
//#endregion
|
|
|
|
|
|
this.DataCatalogo = function (SelectedCatalog, dato) {
|
|
|
|
if (SelectedCatalog == "Etapa")
|
|
ObtenerItems();
|
|
|
|
}
|
|
|
|
|
|
this.ObtenerItems = function () {
|
|
|
|
DocumentosEtapa = {
|
|
IdEtapa: $("#hiddenEtapa").val()
|
|
}
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + "api/DocumentosEtapaAPI/ObtenerItems",
|
|
cache: false,
|
|
data: JSON.stringify(DocumentosEtapa),
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
async: true,
|
|
success: function (data) {
|
|
|
|
if (data != null && data.CodigoRespuesta == "EXITOSO") {
|
|
CatalogoItem = data.ListaDocumentosEtapa;
|
|
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
var TableItems = $('#TableItems').DataTable();
|
|
TableItems.clear().draw();
|
|
|
|
|
|
$.each(data.ListaDocumentosEtapa, function (key, item) {
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
var linea = $("#ucItemsLinea").html();
|
|
var especifico = $("#ucItemsEspecifico").html();
|
|
|
|
|
|
if (item.esLinea) {
|
|
linea = replaceAll("[$icon]", "fa-check-circle", linea);
|
|
linea = replaceAll("[$state_color]", "success", linea);
|
|
option = replaceAll("[$Linea]", "1", option);
|
|
}
|
|
else {
|
|
linea = replaceAll("[$icon]", "fa-check-circle", linea);
|
|
linea = replaceAll("[$state_color]", "muted", linea);
|
|
option = replaceAll("[$Linea]", "0", option);
|
|
}
|
|
|
|
if (item.esEspecifico) {
|
|
especifico = replaceAll("[$icon]", "fa-check-circle", especifico);
|
|
especifico = replaceAll("[$state_color]", "success", especifico);
|
|
option = replaceAll("[$Especifico]", "1", option);
|
|
}
|
|
else {
|
|
especifico = replaceAll("[$icon]", "fa-check-circle", especifico);
|
|
especifico = replaceAll("[$state_color]", "muted", especifico);
|
|
option = replaceAll("[$Especifico]", "0", option);
|
|
}
|
|
|
|
option = replaceAll("[$IdDocumentoEtapa]", item.IdDocumentosEtapa, 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.IdDocumentosEtapa,
|
|
item.TipoDocumento.Descripcion,
|
|
item.Etapas.DescripcionEtapa,
|
|
item.TipoFacilidad != null ? item.TipoFacilidad.Descripcion : "",
|
|
linea,
|
|
especifico,
|
|
option]).draw();
|
|
ENDREQUEST();
|
|
|
|
});
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde", Message_Error);
|
|
ENDREQUEST();
|
|
}
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
if (typeof AjaxFailEvent !== 'undefined' && $.isFunction(AjaxFailEvent) && !AjaxFailEvent(jqxhr, textStatus, error))
|
|
return;
|
|
$('#btnCompletarTarea').enable();
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde", Message_Error);
|
|
ENDREQUEST();
|
|
}).then(function (value) {
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.EditarItem = function (idDocumentosEtapa,esLinea,esEspecifico) {
|
|
|
|
|
|
|
|
var esrequerido = true;
|
|
if (CatalogoItem != null) {
|
|
|
|
$('#hiddenIdDocumentosEtapa').val(idDocumentosEtapa);
|
|
|
|
var registro = $.grep(CatalogoItem, function (item, id) {
|
|
return item.IdDocumentosEtapa == idDocumentosEtapa;
|
|
})[0];
|
|
|
|
if (registro != undefined && registro !== null) {
|
|
$("#hiddenTipoDocumento").val(registro.IdTipoDocumento);
|
|
$('#txtTipoDocumento').val(registro.TipoDocumento.Descripcion);
|
|
|
|
$("#hiddenEtapa").val(registro.IdEtapa);
|
|
$('#txtEtapa').val(registro.Etapas.DescripcionEtapa);
|
|
|
|
$("#hiddenFacilidad").val(registro.IdTipoFacilidad != null ? registro.IdTipoFacilidad : "");
|
|
$('#txtFacilidad').val(registro.TipoFacilidad != null ? registro.TipoFacilidad.Descripcion : "");
|
|
|
|
$("#chkesLinea").prop("checked", esLinea);
|
|
$("#chkesEspecifico").prop("checked", esEspecifico);
|
|
}
|
|
|
|
|
|
//$.each(CatalogoItem, function (key, item) {
|
|
// if (item.IdDocumentosEtapa == idDocumentosEtapa) {
|
|
|
|
// $("#hiddenTipoDocumento").val(item.IdTipoDocumento);
|
|
// $('#txtTipoDocumento').val(item.TipoDocumento.Descripcion);
|
|
|
|
// $("#hiddenEtapa").val(item.IdEtapa);
|
|
// $('#txtEtapa').val(item.Etapas.DescripcionEtapa);
|
|
|
|
// $("#hiddenFacilidad").val(item.IdTipoFacilidad != null ? item.IdTipoFacilidad : "");
|
|
// $('#txtFacilidad').val(item.TipoFacilidad != null ? item.TipoFacilidad.Descripcion : "");
|
|
|
|
// $("#chkRequisitoBasico").prop("checked", valueRequisito);
|
|
// $("#chkAutoGenerable").prop("checked", valueGenerable);
|
|
|
|
// }
|
|
//});
|
|
|
|
$("#formCatalogo").valid();
|
|
|
|
$('#btnEtapa').hide();
|
|
$('#btnTipoDocumento').hide();
|
|
//$('#btnFacilidad').hide();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (idDocumentosEtapa, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar el documento para la etapa?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar el documento para la etapa?';
|
|
}
|
|
|
|
//if ($("#hiddenEtapa").val() == "" || value == null) {
|
|
// toastr.warning("No se pudo obtener el ID de la Etapa seleccionado.");
|
|
// return;
|
|
//}
|
|
|
|
//if ($("#hiddenTipoDocumento").val() == "" || value == null) {
|
|
// toastr.warning("No se pudo obtener el ID del documento seleccionado.");
|
|
// return;
|
|
//}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
|
|
|
|
Item = {
|
|
IdDocumentosEtapa: idDocumentosEtapa,
|
|
Estado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/DocumentosEtapaAPI/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.CodigoRespuesta == "EXITOSO") {
|
|
toastr.info('Información actualizada con exito', 'Completado');
|
|
TableItems.clear().draw();
|
|
ObtenerItems();
|
|
ENDREQUEST();
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error al intentar cambiar el estado del documento para la etapa.");
|
|
ENDREQUEST();
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado al intentar cambiar el estado del documento para la etapa. Vuela a intentarlo.");
|
|
ENDREQUEST();
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
|
|
});
|
|
}
|
|
|
|
this.InsertarItem = function () {
|
|
|
|
if (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a ingresar una nueva configuración de Documento por Etapa.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
DocumentosEtapa = {
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoFacilidad: $("#hiddenFacilidad").val() == "" ? null : $("#hiddenFacilidad").val(),
|
|
UsuarioCreador: $("#hiddenUserID").val(),
|
|
esLinea: $('#chkesLinea').is(":checked"),
|
|
esEspecifico: $('#chkesEspecifico').is(":checked")
|
|
}
|
|
|
|
var uri = 'api/DocumentosEtapaAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(DocumentosEtapa);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
if (data.CodigoRespuesta == "EXITOSO") {
|
|
toastr.info('Información guardada con éxito', 'Completado');
|
|
|
|
Limpiar();
|
|
|
|
TableItems.clear().draw();
|
|
ObtenerItems();
|
|
ENDREQUEST();
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error al intentar guardar la configuración de Documento por Etapa.");
|
|
ENDREQUEST();
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado al intentar guardar la configuración de Documento por Etapa. Vuela a intentarlo.");
|
|
ENDREQUEST();
|
|
|
|
}).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();
|
|
|
|
|
|
Item = {
|
|
IdDocumentosEtapa: $('#hiddenIdDocumentosEtapa').val(),
|
|
IdEtapa: $("#hiddenEtapa").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdTipoFacilidad: $("#hiddenFacilidad").val() == "" ? null : $("#hiddenFacilidad").val(),
|
|
UsuarioModificado: $("#hiddenUserID").val(),
|
|
esLinea: $('#chkesLinea').is(":checked"),
|
|
esEspecifico: $('#chkesEspecifico').is(":checked")
|
|
}
|
|
|
|
|
|
|
|
var uri = 'api/DocumentosEtapaAPI/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.CodigoRespuesta == "EXITOSO") {
|
|
toastr.info('Información guardada con exito', 'Completado');
|
|
Limpiar();
|
|
|
|
TableItems.clear().draw();
|
|
ObtenerItems();
|
|
ENDREQUEST();
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error al intentar actualizar la configuración de documento por etapa.");
|
|
ENDREQUEST();
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
ENDREQUEST();
|
|
}).then(function (value) {
|
|
ENDREQUEST();
|
|
});
|
|
}
|
|
|
|
this.Limpiar = function (mode) {
|
|
|
|
///IdPivot
|
|
$("#hiddenIdDocumentosEtapa").val("");
|
|
|
|
$('#btnEtapa').show();
|
|
$('#btnTipoDocumento').show();
|
|
$('#btnFacilidad').show();
|
|
|
|
|
|
//Controles
|
|
$("#txtTipoDocumento").val("");
|
|
$("#hiddenTipoDocumento").val("");
|
|
|
|
$("#txtFacilidad").val("");
|
|
$("#hiddenFacilidad").val("");
|
|
|
|
$("#chkesLinea").prop("checked", false);
|
|
$("#chkesEspecifico").prop("checked", false);
|
|
|
|
switch (mode) {
|
|
case 1:
|
|
$("#txtEtapa").val("");
|
|
$("#hiddenEtapa").val("");
|
|
|
|
TableItems.clear().draw();
|
|
break;
|
|
default:
|
|
|
|
}
|
|
|
|
$("#formCatalogo").valid();
|
|
}
|
|
|
|
|