Skip to content

Commit

Permalink
Feat: DonationPageController added and developed
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 13, 2026
1 parent c0679ce commit f43ab2a
Showing 1 changed file with 67 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,91 @@

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
import ntnu.systemutvikling.team6.HmHApplication;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import ntnu.systemutvikling.team6.DAO.DonationDAO;
import ntnu.systemutvikling.team6.models.Charity;

import javax.swing.text.html.ImageView;
import java.io.IOException;
import java.util.Optional;

public class DonationPageController {
@FXML
private FlowPane charityPage;
private Charity charity;

@FXML
private ImageView logoImage;
private TextField donatioAmount;

@FXML
private Label CharityName;

@FXML
public void initialize() {
}

@FXML
public void setCharity(Charity charity) {
this.charity = charity;

CharityName.setText(charity.getName());
Alert a = new Alert(Alert.AlertType.CONFIRMATION);
}

public void switchToFrontPage(ActionEvent event) {
LoaderScene.LoadScene("FrontPage", event, null);
}

public void Donate(ActionEvent event){
String input = donatioAmount.getText().trim();

if (input.isEmpty()) {
showAlert(Alert.AlertType.ERROR, "Invalid input", "Please enter a donation amount.");
return;
}
double amount;

try {
amount = Double.parseDouble(input);
} catch (NumberFormatException e) {
showAlert(Alert.AlertType.ERROR, "Invalid input", "Please enter a valid number.");
return;
}

if (amount <= 0) {
showAlert(Alert.AlertType.ERROR, "Invalid amount", "Donation must be greater than 0.");
return;
}

if (amount > 100_000) {
showAlert(Alert.AlertType.WARNING, "Amount too high", "Maximum donation is 100,000.");
return;
}

Alert confirm = new Alert(Alert.AlertType.CONFIRMATION);
confirm.setTitle("Confirm Donation");
confirm.setHeaderText("You're about to donate " + amount + " to " + charity.getName());
confirm.setContentText("Are you sure?");
Optional<ButtonType> result = confirm.showAndWait();

if (result.isPresent() && result.get() == ButtonType.OK) {
// Process donation
processDonation(charity,amount);
showAlert(Alert.AlertType.INFORMATION, "Thank you!", "You have donated " + amount + " to " + charity.getName());
donatioAmount.clear();
LoaderScene.LoadScene("FrontPage", event, null);
}
}

public void processDonation(Charity charity, double amount){
DonationDAO.addDonation(charity, amount);
}

private void showAlert(Alert.AlertType type, String title, String message){
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
}

0 comments on commit f43ab2a

Please sign in to comment.