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