-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Updating descirptng (org_Edit) works.
- Loading branch information
AdrianBalunan
committed
Apr 21, 2026
1 parent
efd31df
commit e64128b
Showing
5 changed files
with
185 additions
and
150 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...n/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgEditController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| package ntnu.systemutvikling.team6.controller.profileCharity; | ||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.event.ActionEvent; | ||
| import javafx.fxml.FXML; | ||
| import javafx.fxml.FXMLLoader; | ||
| import javafx.scene.Parent; | ||
| import javafx.scene.control.Alert; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.TextArea; | ||
| import javafx.scene.control.TextField; | ||
| import javafx.scene.layout.HBox; | ||
| import javafx.stage.Stage; | ||
| import ntnu.systemutvikling.team6.controller.components.BaseController; | ||
| import ntnu.systemutvikling.team6.controller.components.CategoryTagController; | ||
| import ntnu.systemutvikling.team6.controller.components.LoaderScene; | ||
| import ntnu.systemutvikling.team6.controller.components.NavbarController; | ||
| import ntnu.systemutvikling.team6.database.DAO.CharityUserDAO; | ||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.models.Charity; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| public class profileOrgEditController extends BaseController { | ||
| @FXML | ||
| private NavbarController navbarController; | ||
| @FXML private Label charityNameLabel; | ||
| @FXML private TextArea descriptionField; | ||
|
|
||
| @Override | ||
| protected void authTokenisSet() { | ||
| if (!isLoggedin() || authToken.isCharityUser() == null){ | ||
| showAlert(Alert.AlertType.ERROR, "Not logged inn or dont have privileges", "You need to be logged inn an account with Charity User priviliges."); | ||
| Platform.runLater(() -> { | ||
| Stage stage = (Stage) Stage.getWindows().stream() | ||
| .filter(w -> w.isShowing()) | ||
| .findFirst() | ||
| .orElse(null); | ||
| if (stage != null) { | ||
| LoaderScene.LoadScene("loginSite", stage, null, null, authToken); | ||
| } | ||
| }); | ||
| return; | ||
| } | ||
| navbarController.setAuthToken(authToken); | ||
| populateFields(); | ||
| } | ||
|
|
||
| private void populateFields(){ | ||
| Charity usersCharity = authToken.isCharityUser(); | ||
| charityNameLabel.setText(usersCharity.getName()); | ||
| descriptionField.setText(usersCharity.getDescription()); | ||
| } | ||
|
|
||
| @FXML | ||
| private void handleSaveDescription(ActionEvent event){ | ||
| String descriptionFieldText = descriptionField.getText(); | ||
|
|
||
|
|
||
| if (descriptionFieldText.isBlank()) { | ||
| showAlert(Alert.AlertType.ERROR, "Empty input", "Yeah, maybe it was empty before but now it need one"); | ||
| return; | ||
| } | ||
|
|
||
| boolean updateSuccess; | ||
| DatabaseConnection conn = new DatabaseConnection(); | ||
| CharityUserDAO userDataObject = new CharityUserDAO(conn); | ||
| Charity savedCharity = authToken.isCharityUser(); | ||
| Charity minimalCharityWithJustNewDescription = new Charity(savedCharity.getUUID().toString(), savedCharity.getOrg_number(), savedCharity.getName(), null, savedCharity.getStatus(), savedCharity.getPreApproved(),descriptionFieldText, null, null, null); | ||
| try { | ||
| updateSuccess = userDataObject.updateCharityVanityDescription(minimalCharityWithJustNewDescription); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred"); | ||
| return; | ||
| } | ||
| if (updateSuccess) { | ||
| showAlert( | ||
| Alert.AlertType.INFORMATION, | ||
| "Settings updated", | ||
| "You have successfully changed your settings"); | ||
| authToken.isCharityUser().setDescription(descriptionFieldText); | ||
| LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken); | ||
| } else { | ||
| System.out.println("Something went wrong when updating Settings"); | ||
| } | ||
| } | ||
|
|
||
| @FXML | ||
| private void switchToPaymentsPage(ActionEvent event){ | ||
| LoaderScene.LoadScene("profile_org_Payments", event, null, null, authToken); | ||
| } | ||
|
|
||
| @FXML | ||
| private void switchToFeedbackPage(ActionEvent event){ | ||
| LoaderScene.LoadScene("profile_org_Inbox", event, null, null, authToken); | ||
| } | ||
|
|
||
| @FXML | ||
| private void switchToSettingsPage(ActionEvent event){ | ||
| LoaderScene.LoadScene("profile_user_Settings", event, null, null, authToken); | ||
| } | ||
|
|
||
|
|
||
| @FXML | ||
| private void handleLogout(ActionEvent event){ | ||
| authToken.logout(); | ||
| showAlert(Alert.AlertType.INFORMATION, "Logging out", "Logging out..."); | ||
| LoaderScene.LoadScene("FrontPage", event, null, null, authToken); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.