#5 Perfil de Empleado - Añadir la funcion de guardado de Información Personal

This commit is contained in:
Melina Gutierrez 2024-08-27 20:39:40 -04:00
parent 29ebc2e4e6
commit 3825d79479

View File

@ -53,14 +53,12 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private H3 fs = null;
private H3 ss = null;
private final Button saveButton = new Button("Save");
private final Button editButton = new Button("Edit");
//private final Button editButton = new Button("Edit");
public EmployeeView(final EmployeeService employeeService) {
super(Employee.class);
this.employeeService = employeeService;
configureButtons();
mt = new H2("Información General del Empleado");
fs = new H3("Información Personal");
@ -139,6 +137,8 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
setSavedHandler((SavedHandler<Employee>) employee -> {
final Employee saved = employeeService.createOrUpdate(employee);
Notification.show("Empleado guardado exitosamente.");
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
setEntityWithEnabledSave(saved);
});
@ -147,23 +147,6 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
}
private void configureButtons() {
editButton.setEnabled(false); // Desactivar el botón de editar inicialmente
saveButton.addClickListener(e -> {
if (isValid()) {
saveButton.setEnabled(false);
} else {
Notification.show("Por favor, complete todos los campos obligatorios.");
}
});
editButton.addClickListener(e -> {
Notification.show("Modo de edición activado.");
setHasChanges(false);
});
}
private VerticalLayout createSidebar() {
VerticalLayout sidebar = new VerticalLayout();
sidebar.setWidth("250px");
@ -187,10 +170,8 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
var employee = employeeService.getEmployee(UUID.fromString(s));
setEntityWithEnabledSave(employee);
editButton.setEnabled(true);
} else {
setEntityWithEnabledSave(new Employee());
editButton.setEnabled(false);
}
}
@ -211,11 +192,8 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
emergencyCName,
emergencyCAddress,
emergencyCPhone,
emergencyCEmail,
saveButton,
editButton
emergencyCEmail
);
}
}
}