323 lines
7.9 KiB
JavaScript
323 lines
7.9 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
var CatalogoItem = {};
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
$('#txtDescripcionCondicion').attr('size', 50);
|
|
|
|
|
|
GetControlsSettings("Cathay_CondicionesGeneralesCredito", "Cathay_CondicionesGeneralesCredito", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
InsertarItem();
|
|
});
|
|
});
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
var uri = 'api/CondicionesVariasAPI/ObtenerItems/';
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdSecuencia, option);
|
|
|
|
var stateIcon = $("#ucItemsIcon").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);
|
|
}
|
|
|
|
TableItems.row.add([stateIcon, item.IdSecuencia, item.Descripcion, option]).draw();
|
|
|
|
});
|
|
|
|
if (data != null) {
|
|
|
|
$('#TableItems').TableInitSpanish(0, false, true, true, true, null);
|
|
|
|
if ($.fn.DataTable.isDataTable('#TableItems')) {
|
|
LoadMessage();
|
|
$('#tableMantenimiento').DataTable().search('').draw();
|
|
ENDREQUEST();
|
|
}
|
|
}
|
|
|
|
else {
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva 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 (id) {
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
var indexes = getRowIndex(TableItems, id_column, id);
|
|
|
|
|
|
if (indexes != null) {
|
|
|
|
$('#hiddenId').val(id)
|
|
$('#txtDescripcionCondicion').val(TableItems.cell(indexes, 2).data());
|
|
|
|
$("#formCatalogo").validateElement("#txtDescripcionCondicion");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valor de Campo ID: ' + id);
|
|
|
|
$('#btnInsertar').hide();
|
|
$('#btnGuardar').show();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (id, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar esta condición?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar esta condición?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID de la condición seleccionada.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Item = {
|
|
IdSecuencia: id,
|
|
Habilitado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/CondicionesVariasAPI/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();
|
|
|
|
Item = {
|
|
IdSecuencia: $("#hiddenId").val(),
|
|
Descripcion: $("#txtDescripcionCondicion").val(),
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/CondicionesVariasAPI/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 Condición');
|
|
|
|
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 Condición.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
CondicionesVarias = {
|
|
Descripcion: $("#txtDescripcionCondicion").val(),
|
|
UsuarioCreador: $("#hiddenUserID").val()
|
|
};
|
|
|
|
var uri = 'api/CondicionesVariasAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(CondicionesVarias);
|
|
|
|
$.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 Condición');
|
|
|
|
$("#txtDescripcionCondicion").val('');
|
|
$("#formCatalogo").validateElement("#txtDescripcionCondicion");
|
|
|
|
}
|
|
|
|
|
|
|