Fix adoption dialog
This commit is contained in:
@@ -59,6 +59,7 @@ public class AdoptionDialogController {
|
||||
private String mode = null;
|
||||
private Adoption selectedAdoption = null;
|
||||
private String selectedPaymentMethod = null;
|
||||
private boolean suppressPaymentDialog = false;
|
||||
|
||||
private ObservableList<String> statusList = FXCollections.observableArrayList(
|
||||
"Pending", "Completed", "Cancelled"
|
||||
@@ -69,7 +70,7 @@ public class AdoptionDialogController {
|
||||
|
||||
cbAdoptionStatus.setItems(statusList);
|
||||
cbAdoptionStatus.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||
if ("Completed".equals(newVal) && !"Completed".equals(oldVal)) {
|
||||
if ("Completed".equals(newVal) && !"Completed".equals(oldVal) && !suppressPaymentDialog) {
|
||||
ChoiceDialog<String> dialog = new ChoiceDialog<>("Cash", "Cash", "Credit Card", "Debit Card", "E-Transfer");
|
||||
dialog.setTitle("Payment Method");
|
||||
dialog.setHeaderText("Confirm payment received");
|
||||
@@ -111,15 +112,11 @@ public class AdoptionDialogController {
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Long storeId = UserSession.getInstance().getStoreId();
|
||||
List<DropdownOption> employees;
|
||||
if (storeId != null && storeId > 0) {
|
||||
employees = DropdownApi.getInstance().getStoreEmployees(storeId);
|
||||
} else {
|
||||
employees = DropdownApi.getInstance().getEmployees();
|
||||
}
|
||||
List<DropdownOption> employees = DropdownApi.getInstance().getEmployees();
|
||||
Platform.runLater(() -> {
|
||||
cbEmployee.setItems(FXCollections.observableArrayList(employees));
|
||||
ObservableList<DropdownOption> employeesObs = FXCollections.observableArrayList(employees);
|
||||
ensureSelectedEmployeeOption(employeesObs);
|
||||
cbEmployee.setItems(employeesObs);
|
||||
applySelectedEmployee();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
@@ -283,12 +280,14 @@ public class AdoptionDialogController {
|
||||
}
|
||||
}
|
||||
|
||||
suppressPaymentDialog = true;
|
||||
for (String status : cbAdoptionStatus.getItems()) {
|
||||
if (status.equals(adoption.getAdoptionStatus())) {
|
||||
cbAdoptionStatus.getSelectionModel().select(status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
suppressPaymentDialog = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +339,19 @@ public class AdoptionDialogController {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ensureSelectedEmployeeOption(ObservableList<DropdownOption> options) {
|
||||
if (selectedAdoption == null || selectedAdoption.getEmployeeId() <= 0 || options == null) {
|
||||
return;
|
||||
}
|
||||
DropdownOption existing = findOptionById(options, (long) selectedAdoption.getEmployeeId());
|
||||
if (existing == null) {
|
||||
DropdownOption option = new DropdownOption();
|
||||
option.setId((long) selectedAdoption.getEmployeeId());
|
||||
option.setLabel(selectedAdoption.getEmployeeName() != null ? selectedAdoption.getEmployeeName() : "Employee #" + selectedAdoption.getEmployeeId());
|
||||
options.add(0, option);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureSelectedPetOption(ObservableList<DropdownOption> options) {
|
||||
if (selectedAdoption == null || selectedAdoption.getPetId() <= 0 || options == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user