365 lines
9.3 KiB
JavaScript
365 lines
9.3 KiB
JavaScript
$("#formGrupoCIIU").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
var IdSeccionCIIU = getUrlParameter('IdSeccionCIIU');
|
|
var IdDivisionCIIU = getUrlParameter('IdDivisionCIIU');
|
|
var IDGrupo;
|
|
|
|
|
|
|
|
jQuery(document).ready(function () {
|
|
$('#txtDescripcionGrupoCIIU').attr('size', 50);
|
|
|
|
|
|
GetControlsSettings("Cathay_GrupoCIIU", "Cathay_GrupoCIIU", "formGrupoCIIU");
|
|
|
|
$('#btnGuardarGrupoCIIU').hide();
|
|
$('#btnInsertarGrupoCIIU').show();
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiarGrupoCIIU').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardarGrupoCIIU').hide();
|
|
$('#btnInsertarGrupoCIIU').show();
|
|
});
|
|
|
|
$('#btnGuardarGrupoCIIU').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertarGrupoCIIU').click(function () {
|
|
InsertarItem();
|
|
});
|
|
});
|
|
|
|
$('#btnVolver').click(function () {
|
|
url = $("#hiddenHref").val();
|
|
url = url.replace("[$CodSeccion]", IdSeccionCIIU);
|
|
document.location.href = url;
|
|
});
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
Item =
|
|
{
|
|
IdSeccionCIIU: IdSeccionCIIU,
|
|
IdDivisionCIIU: IdDivisionCIIU,
|
|
}
|
|
|
|
var uri = 'api/GrupoCIIUAPI/ObtenerItems?IDSeccionCIIU=' + (IdSeccionCIIU) + '&IDDivisionCIIU=' + (IdDivisionCIIU);
|
|
|
|
$.getJSON(server + uri).done(function (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.IdGrupoCIIU, option);
|
|
option = replaceAll("[$CodSeccion]", item.IdSeccionCIIU, option);
|
|
option = replaceAll("[$CodDivision]", item.IdDivisionCIIU, 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.IdGrupoCIIU, item.IdSeccionCIIU, item.IdDivisionCIIU, item.Descripcion, item.Sector != null ? item.Sector.IdSector+"-"+ item.Sector.Descripcion : "", 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) {
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
var indexes = getRowIndex(TableItems, id_column, id);
|
|
|
|
|
|
if (indexes != null) {
|
|
|
|
$('#hiddenId').val(id)
|
|
|
|
IDGrupo = id
|
|
$('#txtCodigoGrupoCIIU').val(id);
|
|
$('#txtDescripcionGrupoCIIU').val(TableItems.cell(indexes, 4).data());
|
|
|
|
$("#formGrupoCIIU").validateElement("#txtDescripcionGrupoCIIU");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valor de Campo ID: ' + id);
|
|
|
|
$('#lblCodigoGrupoCIIU').hide();
|
|
$('#txtCodigoGrupoCIIU').hide();
|
|
|
|
$('#btnInsertarGrupoCIIU').hide();
|
|
$('#btnGuardarGrupoCIIU').show();
|
|
|
|
var Sector = TableItems.cell(indexes, 5).data();
|
|
var mtzSector = Sector.split('-');
|
|
$('#txtSector').val(mtzSector[1]);
|
|
$('#hiddenSector').val(mtzSector[0]);
|
|
$("#formGrupoCIIU").validateElement("#txtSector");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (id, idSeccion, idDivic, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar el CIIU Nivel?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar CIIU Nivel?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID de el CIIU Nivel seleccionado.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
Item = {
|
|
IdGrupoCIIU: id,
|
|
IdSeccionCIIU: idSeccion,
|
|
IdDivisionCIIU: idDivic,
|
|
Estado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/GrupoCIIUAPI/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();
|
|
|
|
$('#btnGuardarGrupoCIIU').hide();
|
|
$('#btnInsertarGrupoCIIU').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 (!$("#formGrupoCIIU").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 = {
|
|
IdGrupoCIIU: IDGrupo,
|
|
IdSeccionCIIU: IdSeccionCIIU,
|
|
IdDivisionCIIU: IdDivisionCIIU,
|
|
Descripcion: $('#txtDescripcionGrupoCIIU').val(),
|
|
IdSector: $('#hiddenSector').val(),
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/GrupoCIIUAPI/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();
|
|
|
|
$('#btnGuardarGrupoCIIU').hide();
|
|
$('#btnInsertarGrupoCIIU').show();
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Ingresar Nuevo CIIU Nivel');
|
|
|
|
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 (!$("#formGrupoCIIU").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a ingresar un nuevo CIIU Nivel.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
GrupoCIIU = {
|
|
IdGrupoCIIU: $("#txtCodigoGrupoCIIU").val(),
|
|
IdSeccionCIIU: IdSeccionCIIU,
|
|
IdDivisionCIIU: IdDivisionCIIU,
|
|
Descripcion: $('#txtDescripcionGrupoCIIU').val(),
|
|
IdSector: $('#hiddenSector').val(),
|
|
UsuarioCreador: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/GrupoCIIUAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(GrupoCIIU);
|
|
|
|
$.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();
|
|
$('#btnGuardarGrupoCIIU').hide();
|
|
$('#btnInsertarGrupoCIIU').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 Nuevo CIIU Nivel');
|
|
$('#lblCodigoGrupoCIIU').show();
|
|
|
|
$('#txtCodigoGrupoCIIU').val('');
|
|
$('#txtCodigoGrupoCIIU').show();
|
|
|
|
|
|
$('#txtDescripcionGrupoCIIU').val('');
|
|
$("#formGrupoCIIU").validateElement("#txtDescripcionGrupoCIIU");
|
|
$("#formGrupoCIIU").validateElement("#txtCodigoGrupoCIIU");
|
|
|
|
|
|
$('#txtSector').val('');
|
|
$('#hiddenSector').val('');
|
|
$("#formGrupoCIIU").validateElement("#txtSector");
|
|
}
|