Update UI and remove staff creation from login
This commit is contained in:
@@ -29,9 +29,6 @@ public class LoginController {
|
||||
@FXML
|
||||
private Label lblError;
|
||||
|
||||
@FXML
|
||||
private Button btnCreateStaff;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
lblError.setText("");
|
||||
@@ -93,24 +90,6 @@ public class LoginController {
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
void btnCreateStaffClicked(ActionEvent event) {
|
||||
lblError.setText("");
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/example/petshopdesktop/dialogviews/staff-register-dialog-view.fxml"));
|
||||
Stage dialog = new Stage();
|
||||
dialog.initOwner(txtUsername.getScene().getWindow());
|
||||
dialog.initModality(Modality.APPLICATION_MODAL);
|
||||
dialog.setTitle("Create Staff Account");
|
||||
dialog.setScene(new Scene(loader.load()));
|
||||
dialog.setResizable(false);
|
||||
dialog.showAndWait();
|
||||
} catch (Exception e) {
|
||||
ActivityLogger.getInstance().logException("LoginController.btnCreateStaffClicked", e, "Opening staff register dialog");
|
||||
lblError.setText("Could not open staff account creation.");
|
||||
}
|
||||
}
|
||||
|
||||
private void openMainLayout() {
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(
|
||||
|
||||
@@ -8,6 +8,7 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Separator;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
import org.example.petshopdesktop.auth.UserSession;
|
||||
@@ -69,12 +70,21 @@ public class MainLayoutController {
|
||||
@FXML
|
||||
private Button btnAnalytics;
|
||||
|
||||
@FXML
|
||||
private Button btnChat;
|
||||
|
||||
@FXML
|
||||
private Label lblUsername;
|
||||
|
||||
@FXML
|
||||
private Label lblRole;
|
||||
|
||||
@FXML
|
||||
private Label lblAdminSection;
|
||||
|
||||
@FXML
|
||||
private Separator separatorAdmin;
|
||||
|
||||
@FXML
|
||||
private StackPane spContentArea;
|
||||
|
||||
@@ -150,6 +160,12 @@ public class MainLayoutController {
|
||||
updateButtons(btnSuppliers);
|
||||
}
|
||||
|
||||
@FXML
|
||||
void btnChatClicked(ActionEvent event) {
|
||||
loadView("chat-view.fxml");
|
||||
updateButtons(btnChat);
|
||||
}
|
||||
|
||||
@FXML
|
||||
void btnLogoutClicked(ActionEvent event) {
|
||||
UserSession.getInstance().logout();
|
||||
@@ -204,6 +220,16 @@ public class MainLayoutController {
|
||||
btnStaffAccounts.setManaged(isAdmin);
|
||||
}
|
||||
|
||||
if (lblAdminSection != null) {
|
||||
lblAdminSection.setVisible(isAdmin);
|
||||
lblAdminSection.setManaged(isAdmin);
|
||||
}
|
||||
|
||||
if (separatorAdmin != null) {
|
||||
separatorAdmin.setVisible(isAdmin);
|
||||
separatorAdmin.setManaged(isAdmin);
|
||||
}
|
||||
|
||||
btnSalesHistory.setText(isAdmin ? "Sales History" : "Sales");
|
||||
|
||||
|
||||
@@ -244,7 +270,8 @@ public class MainLayoutController {
|
||||
btnProducts,
|
||||
btnPurchaseOrders,
|
||||
btnStaffAccounts,
|
||||
btnAnalytics
|
||||
btnAnalytics,
|
||||
btnChat
|
||||
};
|
||||
|
||||
for (Button button : buttons) {
|
||||
|
||||
@@ -5,11 +5,16 @@ import javafx.collections.ObservableList;
|
||||
import javafx.collections.transformation.FilteredList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import org.example.petshopdesktop.auth.UserSession;
|
||||
import org.example.petshopdesktop.database.UserDB;
|
||||
import org.example.petshopdesktop.models.StaffAccount;
|
||||
@@ -46,6 +51,9 @@ public class StaffAccountsController {
|
||||
@FXML
|
||||
private Label lblError;
|
||||
|
||||
@FXML
|
||||
private Button btnCreateAccount;
|
||||
|
||||
private final ObservableList<StaffAccount> staffAccounts = FXCollections.observableArrayList();
|
||||
private FilteredList<StaffAccount> filtered;
|
||||
|
||||
@@ -66,6 +74,7 @@ public class StaffAccountsController {
|
||||
if (!UserSession.getInstance().isAdmin()) {
|
||||
lblError.setText("Access restricted.");
|
||||
tvStaff.setDisable(true);
|
||||
btnCreateAccount.setDisable(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,6 +86,25 @@ public class StaffAccountsController {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@FXML
|
||||
void btnCreateAccountClicked(ActionEvent event) {
|
||||
lblError.setText("");
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/example/petshopdesktop/dialogviews/staff-register-dialog-view.fxml"));
|
||||
Stage dialog = new Stage();
|
||||
dialog.initOwner(tvStaff.getScene().getWindow());
|
||||
dialog.initModality(Modality.APPLICATION_MODAL);
|
||||
dialog.setTitle("Create Staff Account");
|
||||
dialog.setScene(new Scene(loader.load()));
|
||||
dialog.setResizable(false);
|
||||
dialog.showAndWait();
|
||||
refresh();
|
||||
} catch (Exception e) {
|
||||
ActivityLogger.getInstance().logException("StaffAccountsController.btnCreateAccountClicked", e, "Opening staff register dialog");
|
||||
lblError.setText("Could not open staff account creation.");
|
||||
}
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
lblError.setText("");
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user