179 lines
5.6 KiB
Plaintext
179 lines
5.6 KiB
Plaintext
@inject NavigationManager Navigation
|
|
@layout ConfiguracionLayout
|
|
@using BlazorBootstrap
|
|
@using System.Globalization
|
|
@using bdHerramientaCACOA.db
|
|
|
|
<Toasts class="p-3 font-weight-bold" Style="color:white;" AutoHide="true" Delay="4000" Messages="mensajes" Placement="ToastsPlacement.BottomCenter" />
|
|
|
|
<EditForm EditContext="@editContext" OnValidSubmit="guardarFormulario" FormName="puestoTrabForm">
|
|
<DataAnnotationsValidator></DataAnnotationsValidator>
|
|
<Modal @ref="popupGestionDatos" title="@tituloPopup" IsVerticallyCentered="true" UseStaticBackdrop="true" CloseOnEscape="false">
|
|
<BodyTemplate>
|
|
<div class="row">
|
|
<div class="col-12 formatoCampos pt-2">
|
|
<label class="tituloLbl">Texto:</label>
|
|
<TextAreaInput Style="height:220px; max-height:220px" MaxLength="2000" @bind-Value="@textoItem" Rows="3" TextAlignment="Alignment.Start" />
|
|
</div>
|
|
</div>
|
|
</BodyTemplate>
|
|
<FooterTemplate>
|
|
<Button Color="ButtonColor.Secondary" @onclick="cerrarPopupGestionDatos">Cerrar</Button>
|
|
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary">@(nuevoElemento ? "Añadir" : "Modificar")</Button>
|
|
</FooterTemplate>
|
|
</Modal>
|
|
</EditForm>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<Grid TItem="enumeraciones"
|
|
Class="tablaCACOA table"
|
|
Data="listadoTextosPDF"
|
|
AllowFiltering="false"
|
|
PageSize="10"
|
|
FixedHeader="true"
|
|
Height="750"
|
|
Unit="Unit.Px"
|
|
EmptyText="No hay registros."
|
|
PageSizeSelectorVisible="false"
|
|
Responsive="true">
|
|
<GridColumns>
|
|
<GridColumn TItem="enumeraciones" Class="columna20Ancho" HeaderTextAlignment="Alignment.Center" HeaderText="Descripción">
|
|
<span>@context.Descripcion</span>
|
|
</GridColumn>
|
|
<GridColumn TItem="enumeraciones" HeaderTextAlignment="Alignment.Center" HeaderText="Texto">
|
|
<span>@context.ValorAlfabeticoLargo</span>
|
|
</GridColumn>
|
|
<GridColumn TItem="enumeraciones" Class="botonesTabla" HeaderText="">
|
|
<div class="btnTablasEspaciado">
|
|
<span @onclick="@(() => abrirPopupGestionDatos(@context, false))" class="btnBorrarGuardar">
|
|
<Icon CustomIconName="fas fa-edit"></Icon>
|
|
</span>
|
|
</div>
|
|
</GridColumn>
|
|
</GridColumns>
|
|
</Grid>
|
|
</div>
|
|
|
|
@code {
|
|
|
|
public List<enumeraciones> listadoTextosPDF { get; set; } = new List<enumeraciones>();
|
|
|
|
[SupplyParameterFromForm]
|
|
private enumeraciones itemSeleccionado { get; set; } = new enumeraciones();
|
|
|
|
private string tituloPopup = "";
|
|
private Modal popupGestionDatos = default!;
|
|
private Modal popupConfirmarBorrado = default!;
|
|
|
|
private bool nuevoElemento;
|
|
|
|
private string textoItem = "";
|
|
|
|
List<ToastMessage> mensajes = new List<ToastMessage>();
|
|
|
|
private EditContext? editContext;
|
|
private ValidationMessageStore? messageStore;
|
|
public tsHerramientasCACOA bd;
|
|
private string codigoEnumeracion = "VARPDF";
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
|
|
|
|
editContext = new EditContext(itemSeleccionado);
|
|
messageStore = new ValidationMessageStore(editContext);
|
|
|
|
listadoTextosPDF = UtilidadesCASA.devolverListadoOrdenadoEnumeracion(bd, codigoEnumeracion);
|
|
}
|
|
|
|
|
|
private async Task abrirPopupGestionDatos(enumeraciones objeto, bool esNuevo)
|
|
{
|
|
itemSeleccionado = objeto;
|
|
|
|
nuevoElemento = false;
|
|
textoItem = objeto.ValorAlfabeticoLargo;
|
|
|
|
tituloPopup = "Modificar texto";
|
|
|
|
await popupGestionDatos.ShowAsync();
|
|
}
|
|
private async Task cerrarPopupGestionDatos()
|
|
{
|
|
await popupGestionDatos.HideAsync();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task GestionarDatos(string accion)
|
|
{
|
|
|
|
var enumObtenido = bd.enumeraciones.Where(x => x.idEnumeracion == itemSeleccionado.idEnumeracion).FirstOrDefault();
|
|
|
|
itemSeleccionado.ValorAlfabeticoLargo = textoItem;
|
|
|
|
switch (accion)
|
|
{
|
|
case "update":
|
|
UtilidadesCASA.guardarEnumeracion(bd, itemSeleccionado, codigoEnumeracion, nuevoElemento, enumObtenido);
|
|
|
|
await cerrarPopupGestionDatos();
|
|
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Primary,
|
|
Message = $"Actualizado correctamente.",
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
bd.SaveChanges();
|
|
listadoTextosPDF = UtilidadesCASA.devolverListadoOrdenadoEnumeracion(bd, codigoEnumeracion);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task cerrarPopupConfirmarBorrado()
|
|
{
|
|
await popupConfirmarBorrado.HideAsync();
|
|
}
|
|
|
|
// GUARDAR
|
|
private async Task guardarFormulario()
|
|
{
|
|
try
|
|
{
|
|
if (!editContext!.GetValidationMessages().Any())
|
|
{
|
|
string accion = nuevoElemento ? "create" : "update";
|
|
await GestionarDatos(accion);
|
|
}
|
|
else
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Warning,
|
|
Message = $"Debe rellenar los campos obligatorios.",
|
|
});
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Danger,
|
|
Message = $"Error al guardar.",
|
|
});
|
|
}
|
|
|
|
}
|
|
} |