399 lines
9.9 KiB
JavaScript
399 lines
9.9 KiB
JavaScript
$("#formVehiculo").EnableValidationToolTip();
|
|
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
var IdVehic;
|
|
var TableItems = null;
|
|
|
|
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_Vehiculo", "Cathay_Vehiculo", "formVehiculo", true);
|
|
});
|
|
|
|
|
|
this.getDataModel = function () {
|
|
|
|
|
|
$('#btnGuardarVehiculo').hide();
|
|
$('#btnInsertarVehiculo').show();
|
|
|
|
|
|
$('#btnLimpiarVehiculo').click(function () {
|
|
|
|
limpiar();
|
|
|
|
$('#btnGuardarVehiculo').hide();
|
|
|
|
$('#btnInsertarVehiculo').show();
|
|
});
|
|
|
|
$('#btnGuardarVehiculo').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertarVehiculo').click(function () {
|
|
InsertarItem();
|
|
});
|
|
|
|
|
|
$('#btn_eliminarFuncionario').unbind('click');
|
|
$('#btn_eliminarFuncionario').click(function () {
|
|
|
|
$('#hiddenFuncionario').val('');
|
|
$('#txtFuncionario').val('');
|
|
|
|
TableItems.clear().draw();
|
|
limpiar();
|
|
});
|
|
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
ENDREQUEST();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.DataCatalogo = function (SelectedCatalog, dato) {
|
|
|
|
if (SelectedCatalog == "Funcionario")
|
|
{
|
|
obtenerItems();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
var uri = 'api/VehiculoAPI/ObtenerItems?UserId=' + $('#hiddenFuncionario').val();
|
|
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
TableItems.clear().draw();
|
|
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdVehiculo, 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.IdVehiculo, item.UserId, item.Marca, item.TipoVehiculo, item.MotorCC, item.Ano, item.Placa, item.ValorKilometro, (item.Default != true? "No": "Sí"), option]).draw();
|
|
$('#btnGuardarVehiculo').hide();
|
|
|
|
});
|
|
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde");
|
|
}).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)
|
|
IdVehic = id
|
|
$('#txtMarca').val(TableItems.cell(indexes, 3).data());
|
|
$('#txtTipoVehiculo').val(TableItems.cell(indexes, 4).data());
|
|
$('#txtMotor').val(TableItems.cell(indexes, 5).data());
|
|
$('#txtAno').val(TableItems.cell(indexes, 6).data());
|
|
$('#txtPlaca').val(TableItems.cell(indexes, 7).data());
|
|
$('#txtValorKilometro').val(TableItems.cell(indexes, 8).data());
|
|
|
|
$("#chkDefault").prop("checked", (TableItems.cell(indexes, 9).data() != "Sí"? false: true));
|
|
|
|
|
|
|
|
$("#formVehiculo").validateElement("#txtMarca");
|
|
$("#formVehiculo").validateElement("#txtTipoVehiculo");
|
|
$("#formVehiculo").validateElement("#txtMotor");
|
|
$("#formVehiculo").validateElement("#txtAno");
|
|
$("#formVehiculo").validateElement("#txtPlaca");
|
|
$("#formVehiculo").validateElement("#txtValorKilometro");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valor de Campo ID: ' + id);
|
|
|
|
|
|
$('#btnInsertarVehiculo').hide();
|
|
$('#btnGuardarVehiculo').show();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (IdVehiculo, Estado) {
|
|
|
|
var msg = 'Está seguro que desea habilitar el Vechículo?';
|
|
|
|
if (Estado == 0) {
|
|
msg = 'Está seguro que desea deshabilitar el Vehículo?';
|
|
}
|
|
|
|
if (IdVehiculo == null || Estado == null) {
|
|
toastr.warning("No se pudo obtener el ID de el Vehículo seleccionado.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
Item = {
|
|
Estado: Estado,
|
|
IdVehiculo: IdVehiculo,
|
|
UserId: $("#hiddenFuncionario").val(),
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/VehiculoAPI/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 éxito', 'Completado');
|
|
limpiar();
|
|
|
|
$('#btnGuardarVehiculo').hide();
|
|
|
|
|
|
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 (!$("#formVehiculo").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 = {
|
|
IdVehiculo: IdVehic,
|
|
Marca: $('#txtMarca').val(),
|
|
MotorCC: $('#txtMotor').val(),
|
|
Ano: $('#txtAno').val(),
|
|
Placa: $('#txtPlaca').val(),
|
|
UserId: $("#hiddenFuncionario").val(),
|
|
TipoVehiculo: $('#txtTipoVehiculo').val(),
|
|
UsuarioModificado: $("#hiddenUserID").val(),
|
|
ValorKilometro: $('#txtValorKilometro').autoNumeric('get'),
|
|
Default: $('#chkDefault').is(":checked"),
|
|
}
|
|
|
|
var uri = 'api/VehiculoAPI/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();
|
|
|
|
$('#btnGuardarVehiculo').hide();
|
|
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Ingresar Nuevo Vehículo');
|
|
|
|
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 (!$("#formVehiculo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a ingresar un nuevo Vehículo.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
Vehiculo = {
|
|
Ano: $('#txtAno').val(),
|
|
Placa: $('#txtPlaca').val(),
|
|
Marca: $('#txtMarca').val(),
|
|
MotorCC: $('#txtMotor').val(),
|
|
UserId: $("#hiddenFuncionario").val(),
|
|
UsuarioCreador: $("#hiddenUserID").val(),
|
|
TipoVehiculo: $('#txtTipoVehiculo').val(),
|
|
ValorKilometro: $('#txtValorKilometro').autoNumeric('get'),
|
|
Default: $('#chkDefault').is(":checked"),
|
|
}
|
|
|
|
var uri = 'api/VehiculoAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(Vehiculo);
|
|
|
|
|
|
$.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();
|
|
$('#btnGuardarVehiculo').hide();
|
|
|
|
|
|
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 Vehiculo');
|
|
|
|
|
|
|
|
|
|
$('#txtMarca').val('');
|
|
$('#txtTipoVehiculo').val('');
|
|
$('#txtMotor').val('');
|
|
$('#txtAno').val('');
|
|
$('#txtPlaca').val('');
|
|
$('#txtValorKilometro').val('');
|
|
$("#chkDefault").prop("checked", false);
|
|
|
|
|
|
|
|
$("#formVehiculo").validateElement("#txtMarca");
|
|
$("#formVehiculo").validateElement("#txtTipoVehiculo");
|
|
$("#formVehiculo").validateElement("#txtMotor");
|
|
$("#formVehiculo").validateElement("#txtAno");
|
|
$("#formVehiculo").validateElement("#txtPlaca");
|
|
$("#formVehiculo").validateElement("#txtValorKilometro");
|
|
$("#formVehiculo").validateElement("#chkDefault");
|
|
|
|
|
|
}
|