#4-Registrar-empleado #15
@ -38,10 +38,10 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
|
|
||||||
private final TextField firstName;
|
private final TextField firstName;
|
||||||
private final TextField lastName;
|
private final TextField lastName;
|
||||||
private final ComboBox<String> status;
|
private final ComboBox<Employee.Status> status;
|
||||||
private final VDatePicker birthday;
|
private final VDatePicker birthday;
|
||||||
private final TextField birthCity;
|
private final TextField birthCity;
|
||||||
private final ComboBox<String> maritalStatus;
|
private final ComboBox<Employee.MaritalStatus> maritalStatus;
|
||||||
private final TextField residenceAddress;
|
private final TextField residenceAddress;
|
||||||
private final TextField phoneNumber;
|
private final TextField phoneNumber;
|
||||||
private final EmailField personalEmail;
|
private final EmailField personalEmail;
|
||||||
@ -79,9 +79,9 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
lastName.setRequired(true);
|
lastName.setRequired(true);
|
||||||
|
|
||||||
status = new ComboBox<>("Estado");
|
status = new ComboBox<>("Estado");
|
||||||
status.setItems(List.of("ACTIVE", "INACTIVE"));
|
status.setItems(Employee.Status.values());
|
||||||
lastName.setWidthFull();
|
status.setItemLabelGenerator(Employee.Status::name);
|
||||||
lastName.setMaxLength(30);
|
status.setWidthFull();
|
||||||
status.setRequired(true);
|
status.setRequired(true);
|
||||||
|
|
||||||
birthday = new VDatePicker("Fecha de Nacimiento");
|
birthday = new VDatePicker("Fecha de Nacimiento");
|
||||||
@ -92,7 +92,8 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
birthCity.setMaxLength(20);
|
birthCity.setMaxLength(20);
|
||||||
|
|
||||||
maritalStatus = new ComboBox<>("Estado Civil");
|
maritalStatus = new ComboBox<>("Estado Civil");
|
||||||
maritalStatus.setItems(List.of("Soltero", "Casado", "Viudo", "Divorciado"));
|
maritalStatus.setItems(Employee.MaritalStatus.values());
|
||||||
|
maritalStatus.setItemLabelGenerator(Employee.MaritalStatus::name);
|
||||||
maritalStatus.setWidthFull();
|
maritalStatus.setWidthFull();
|
||||||
|
|
||||||
residenceAddress = new TextField("Dirección de Residencia");
|
residenceAddress = new TextField("Dirección de Residencia");
|
||||||
@ -144,6 +145,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
|
|
||||||
setSavedHandler((SavedHandler<Employee>) employee -> {
|
setSavedHandler((SavedHandler<Employee>) employee -> {
|
||||||
if (validateForm()) {
|
if (validateForm()) {
|
||||||
|
employee.setStatus(status.getValue()); // Actualiza el estado del empleado antes de guardar
|
||||||
final Employee saved = employeeService.createOrUpdate(employee);
|
final Employee saved = employeeService.createOrUpdate(employee);
|
||||||
Notification.show("Employee saved successfully.");
|
Notification.show("Employee saved successfully.");
|
||||||
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
|
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
|
||||||
@ -184,6 +186,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
|||||||
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
|
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
|
||||||
var employee = employeeService.getEmployee(UUID.fromString(s));
|
var employee = employeeService.getEmployee(UUID.fromString(s));
|
||||||
setEntityWithEnabledSave(employee);
|
setEntityWithEnabledSave(employee);
|
||||||
|
status.setValue(employee.getStatus()); // Asegúrate de que el ComboBox esté sincronizado con el estado del empleado
|
||||||
} else {
|
} else {
|
||||||
setEntityWithEnabledSave(new Employee());
|
setEntityWithEnabledSave(new Employee());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user