377 lines
9.6 KiB
JavaScript
377 lines
9.6 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var CatalogoItem = {};
|
|
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_MatrizBeneficiarioSBD", "Cathay_MatrizBeneficiarioSBD", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
});
|
|
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
InsertarItem();
|
|
});
|
|
obtenerItems();
|
|
});
|
|
|
|
//#endregion
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
|
|
var uri = 'api/MatrizBeneficiarioSBDAPI/ObtenerItems';
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
if (data != null) {
|
|
CatalogoItem = data;
|
|
|
|
|
|
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
TableItems.clear().draw();
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
var stateIcon = $("#ucItemsIcon").html();
|
|
|
|
option = replaceAll("[$CodLey]", item.IdLey8262, option);
|
|
option = replaceAll("[$CodSector]", item.IdSector, option);
|
|
option = replaceAll("[$CodSBD]", item.IdBeneficiarioSBD, option);
|
|
|
|
|
|
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.DescripcionLey, item.DescripcionSector, item.DescripcionBeneficiarioSBD, option]).draw();
|
|
|
|
});
|
|
|
|
|
|
}
|
|
else {
|
|
$('#btnCompletarTarea').enable();
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde", Message_Error);
|
|
}
|
|
|
|
|
|
}).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 (CodLey, CodSector, CodSBD) {
|
|
|
|
|
|
// if (CatalogoItem != null) {
|
|
|
|
|
|
// $.each(CatalogoItem, function (key, item) {
|
|
// if (item.IdLey8262 == CodLey && item.IdSector == CodSector && item.IdBeneficiarioSBD == CodSBD) {
|
|
// $("#hiddenLey8262").val(item.IdLey8262);
|
|
// $("#hiddenSector").val(item.IdSector);
|
|
// $("#hiddenBeneficiarioSBD").val(item.IdBeneficiarioSBD);
|
|
|
|
// $('#txtLey8262').val(item.DescripcionLey);
|
|
// $('#txtSector').val(item.DescripcionSector);
|
|
// $('#txtBeneficiarioSBD').val(item.DescripcionBeneficiarioSBD);
|
|
// }
|
|
// });
|
|
|
|
|
|
|
|
|
|
// $("#formCatalogo").validateElement("#txtLey8262");
|
|
// $("#formCatalogo").validateElement("#txtSector");
|
|
// $("#formCatalogo").validateElement("#txtBeneficiarioSBD");
|
|
|
|
// $('#btnGuardar').show();
|
|
// $('#btnInsertar').hide();
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
this.toggleEnabledItem = function (CodLey, CodSector, CodSBD, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar la Opción?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar la Opción?';
|
|
}
|
|
|
|
if (CodLey == null || value == null || CodSector == null || CodSBD == null) {
|
|
toastr.warning("No se pudo obtener el ID de la Opción seleccionado.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Item = {
|
|
IdLey8262: CodLey,
|
|
IdSector: CodSector,
|
|
IdBeneficiarioSBD: CodSBD,
|
|
Estado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/MatrizBeneficiarioSBDAPI/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');
|
|
TableItems.clear().draw();
|
|
obtenerItems();
|
|
ENDREQUEST();
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
ENDREQUEST();
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
ENDREQUEST();
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
|
|
});
|
|
}
|
|
|
|
this.InsertarItem = function () {
|
|
|
|
|
|
var Existe = false;
|
|
|
|
|
|
if (CatalogoItem != null) {
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.IdLey8262 == $("#hiddenLey8262").val() && item.IdSector == $("#hiddenSector").val() && item.IdBeneficiarioSBD == $("#hiddenBeneficiarioSBD").val()) {
|
|
Existe = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (Existe == true) {
|
|
toastr.error("Estea Opción ya ha sido Ingresado.");
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
if (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a ingresar una nueva Opción.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Matriz = {
|
|
IdLey8262: $("#hiddenLey8262").val(),
|
|
IdSector: $("#hiddenSector").val(),
|
|
IdBeneficiarioSBD: $("#hiddenBeneficiarioSBD").val(),
|
|
UsuarioCreador: $("#hiddenUserID").val(),
|
|
|
|
}
|
|
|
|
var uri = 'api/MatrizBeneficiarioSBDAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(Matriz);
|
|
|
|
$.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 éxito', 'Completado');
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
TableItems.clear().draw();
|
|
obtenerItems();
|
|
limpiar();
|
|
ENDREQUEST();
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
ENDREQUEST();
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
ENDREQUEST();
|
|
|
|
}).then(function (value) {
|
|
ENDREQUEST();
|
|
});
|
|
}
|
|
|
|
//this.ActualizarItem = function () {
|
|
|
|
|
|
|
|
// var Existe = false;
|
|
|
|
|
|
// if (CatalogoItem != null) {
|
|
// $.each(CatalogoItem, function (key, item) {
|
|
// if (item.IdLey8262 == $("#hiddenLey8262").val() && item.IdSector == $("#hiddenSector").val() && item.IdBeneficiarioSBD == $("#hiddenBeneficiarioSBD").val()) {
|
|
// Existe = true;
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
// if (Existe == true) {
|
|
// toastr.error("Estea Opción ya ha sido Ingresado.");
|
|
// return;
|
|
|
|
// }
|
|
// 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 = {
|
|
// IdLey8262: $("#hiddenLey8262").val(),
|
|
// IdSector: $("#hiddenSector").val(),
|
|
// IdBeneficiarioSBD: $("#hiddenBeneficiarioSBD").val(),
|
|
// UsuarioModificado: $("#hiddenUserID").val(),
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var uri = 'api/MatrizBeneficiarioSBDAPI/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');
|
|
|
|
// TableItems.clear().draw();
|
|
// obtenerItems();
|
|
// ENDREQUEST();
|
|
// }
|
|
// else {
|
|
// toastr.error("Ha ocurrido un error.");
|
|
// ENDREQUEST();
|
|
// }
|
|
|
|
// }
|
|
// }).fail(function (jqxhr, textStatus, error) {
|
|
|
|
// toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
// ENDREQUEST();
|
|
// }).then(function (value) {
|
|
// ENDREQUEST();
|
|
// });
|
|
//}
|
|
|
|
this.limpiar = function () {
|
|
|
|
|
|
$('#txtLey8262').val('');
|
|
$("#formCatalogo").validateElement("#txtLey8262");
|
|
|
|
$('#txtSector').val('');
|
|
$("#formCatalogo").validateElement("#txtSector");
|
|
|
|
$('#txtBeneficiarioSBD').val('');
|
|
$("#formCatalogo").validateElement("#txtBeneficiarioSBD");
|
|
|
|
$("#hiddenLey8262").val("");
|
|
$("#hiddenSector").val("");
|
|
$("#hiddenBeneficiarioSBD").val("");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|