340 lines
9 KiB
JavaScript
340 lines
9 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_columnFacilidad = 1;
|
|
var id_comlumSeleccion = 2;
|
|
var CatalogoItem = {};
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_MatrizOferta", "Cathay_MatrizOferta", "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/MatrizOfertaAPI/ObtenerItems/';
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
CatalogoItem = data;
|
|
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdTipoFacilidad, option); //prueba
|
|
|
|
option = replaceAll("[$CodFacilidad]", item.IdTipoFacilidad, option);
|
|
option = replaceAll("[$CodSeleccion]", item.IdTipoSeleccion, 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.DescripcionFacilidad, item.DescripcionSeleccion, item.DescripcionCriterio, item.Porcentaje, 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 (idFacilidad, idSeleccion) {
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
|
|
if (CatalogoItem != null) {
|
|
|
|
$('#hiddenFacilidad').val(idFacilidad)
|
|
$('#hiddenSeleccion').val(idSeleccion)
|
|
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.IdTipoFacilidad == idFacilidad && item.IdTipoSeleccion == idSeleccion) {
|
|
$('#hiddenCriterioSeleccion').val(item.IdCriterioSeleccion);
|
|
$('#txtFacilidad').val(item.DescripcionFacilidad);
|
|
$('#txtSeleccion').val(item.DescripcionSeleccion);
|
|
$('#txtCriterioSeleccion').val(item.DescripcionCriterio);
|
|
$('#txtPorcentaje').val(item.Porcentaje);
|
|
}
|
|
});
|
|
|
|
$("#formCatalogo").validateElement("#txtFacilidad");
|
|
$("#formCatalogo").validateElement("#txtSeleccion");
|
|
$("#formCatalogo").validateElement("#txtCriterioSeleccion");
|
|
$("#formCatalogo").validateElement("#txtPorcentaje");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valores de Matriz Oferta ' );
|
|
|
|
$('#btnInsertar').hide();
|
|
$('#btnGuardar').show();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (idFacilidad, idSeleccion, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar la Matriz Oferta?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar la Matriz Oferta?';
|
|
}
|
|
|
|
if (idFacilidad == null && idSeleccion == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID la Matriz Oferta seleccionada.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Item = {
|
|
IdTipoFacilidad: idFacilidad,
|
|
IdTipoSeleccion: idSeleccion,
|
|
Estado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/MatrizOfertaAPI/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.InsertarItem = function () {
|
|
|
|
|
|
if (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a ingresar una nueva Matriz Oferta.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
MatrizOferta = {
|
|
IdTipoSeleccion: $("#hiddenSeleccion").val(),
|
|
IdTipoFacilidad: $("#hiddenFacilidad").val(),
|
|
IdCriterioSeleccion: $("#hiddenCriterioSeleccion").val(),
|
|
Porcentaje: $("#txtPorcentaje").autoNumeric('get'),
|
|
UsuarioCreador: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/MatrizOfertaAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(MatrizOferta);
|
|
|
|
$.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');
|
|
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.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 = {
|
|
IdTipoFacilidad: $("#hiddenFacilidad").val(),
|
|
IdTipoSeleccion: $("#hiddenSeleccion").val(),
|
|
IdCriterioSeleccion: $("#hiddenCriterioSeleccion").val(),
|
|
Porcentaje: $("#txtPorcentaje").autoNumeric('get'),
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/MatrizOfertaAPI/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 Matriz Oferta');
|
|
|
|
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 Matriz Oferta');
|
|
|
|
$('#txtSeleccion').val('');
|
|
$("#formCatalogo").validateElement("#txtSeleccion");
|
|
|
|
$('#txtFacilidad').val('');
|
|
$("#formCatalogo").validateElement("#txtFacilidad");
|
|
|
|
$('#txtCriterioSeleccion').val('');
|
|
$("#formCatalogo").validateElement("#txtCriterioSeleccion");
|
|
|
|
$('#txtPorcentaje').val('');
|
|
$("#formCatalogo").validateElement("#txtPorcentaje");
|
|
}
|
|
|
|
|
|
|