2021-11-29 15:44:55 +01:00
|
|
|
package main;
|
|
|
|
|
2022-01-18 09:46:36 +01:00
|
|
|
import com.jfoenix.controls.*;
|
2022-01-20 13:33:49 +01:00
|
|
|
import helper.HttpRequestException;
|
2021-11-29 15:44:55 +01:00
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.scene.Node;
|
2021-12-20 12:57:18 +01:00
|
|
|
import javafx.scene.control.*;
|
2022-01-13 08:30:56 +01:00
|
|
|
import javafx.scene.layout.GridPane;
|
2021-11-29 15:44:55 +01:00
|
|
|
import javafx.stage.Stage;
|
2022-01-13 11:02:49 +01:00
|
|
|
import javafx.util.StringConverter;
|
|
|
|
import javafx.util.converter.LocalTimeStringConverter;
|
2021-11-29 15:44:55 +01:00
|
|
|
import res.DataController;
|
|
|
|
import res.Event;
|
|
|
|
|
2022-01-13 11:02:49 +01:00
|
|
|
import java.time.LocalTime;
|
|
|
|
import java.time.format.FormatStyle;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2021-11-29 15:44:55 +01:00
|
|
|
public class CreateEventController {
|
|
|
|
|
2022-01-13 08:30:56 +01:00
|
|
|
@FXML
|
2022-01-13 10:11:09 +01:00
|
|
|
public GridPane mainGrid;
|
2021-11-29 15:44:55 +01:00
|
|
|
@FXML
|
2022-01-15 09:14:43 +01:00
|
|
|
public JFXDatePicker datePickerDate;
|
2021-11-29 15:44:55 +01:00
|
|
|
@FXML
|
2022-01-14 21:22:50 +01:00
|
|
|
public JFXTextField textName;
|
2021-11-29 15:44:55 +01:00
|
|
|
@FXML
|
2022-01-15 09:14:43 +01:00
|
|
|
public JFXComboBox<String> ComboBoxPriotity;
|
2021-11-29 15:44:55 +01:00
|
|
|
@FXML
|
2022-01-18 09:46:36 +01:00
|
|
|
public JFXToggleButton toggleBtnIsFullDay;
|
2021-11-29 15:44:55 +01:00
|
|
|
@FXML
|
2022-01-18 09:46:36 +01:00
|
|
|
public JFXToggleButton toggleBtnIsPrivate;
|
2021-12-20 12:57:18 +01:00
|
|
|
@FXML
|
|
|
|
public Label labelError;
|
2022-01-13 08:30:56 +01:00
|
|
|
@FXML
|
|
|
|
public JFXTimePicker timeStart;
|
|
|
|
@FXML
|
|
|
|
public JFXTimePicker timeEnd;
|
2021-12-20 12:57:18 +01:00
|
|
|
|
2021-11-29 15:44:55 +01:00
|
|
|
|
2021-12-20 12:57:18 +01:00
|
|
|
public CreateEventController() {
|
|
|
|
}
|
2021-11-29 15:44:55 +01:00
|
|
|
|
|
|
|
@FXML
|
2021-12-20 12:57:18 +01:00
|
|
|
public void initialize() {
|
2022-01-14 10:14:17 +01:00
|
|
|
StringConverter<LocalTime> defaultConverter = new LocalTimeStringConverter(FormatStyle.SHORT, Locale.GERMANY);
|
2022-01-18 09:46:36 +01:00
|
|
|
timeStart.set24HourView(true);
|
|
|
|
timeStart.setConverter(defaultConverter);
|
2022-01-14 10:14:17 +01:00
|
|
|
|
2022-01-18 09:46:36 +01:00
|
|
|
timeEnd.set24HourView(true);
|
|
|
|
timeEnd.setConverter(defaultConverter);
|
2021-12-20 12:57:18 +01:00
|
|
|
}
|
2021-11-29 15:44:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
@FXML
|
2021-12-20 12:57:18 +01:00
|
|
|
protected void createBtnClick(ActionEvent actionEvent) {
|
|
|
|
try {
|
2021-12-22 15:04:15 +01:00
|
|
|
if (datePickerDate.getValue() == null) {
|
2021-12-20 12:57:18 +01:00
|
|
|
throw new IllegalArgumentException("Bitte w\u00e4hle ein Datum aus");
|
|
|
|
}
|
2021-11-29 15:44:55 +01:00
|
|
|
|
2022-01-23 22:05:23 +01:00
|
|
|
System.out.println(datePickerDate.getValue());
|
|
|
|
|
2021-12-20 12:57:18 +01:00
|
|
|
Event event = new Event(
|
|
|
|
textName.getText(),
|
|
|
|
ComboBoxPriotity.getSelectionModel().getSelectedIndex(),
|
2022-01-18 09:46:36 +01:00
|
|
|
toggleBtnIsFullDay.isSelected(),
|
|
|
|
toggleBtnIsPrivate.isSelected(),
|
2022-01-19 00:30:13 +01:00
|
|
|
timeStart.getValue(),
|
|
|
|
timeEnd.getValue(),
|
2021-12-20 12:57:18 +01:00
|
|
|
datePickerDate.getValue().atStartOfDay(),
|
2021-12-22 15:04:15 +01:00
|
|
|
(int) DataController.USER_ID
|
2021-12-20 12:57:18 +01:00
|
|
|
);
|
2021-11-29 15:44:55 +01:00
|
|
|
|
2021-12-20 12:57:18 +01:00
|
|
|
System.out.println(event.getAsUrlParam());
|
2021-11-29 15:44:55 +01:00
|
|
|
|
2022-01-20 13:33:49 +01:00
|
|
|
sendHttpRequest(event);
|
2021-11-29 15:44:55 +01:00
|
|
|
|
2021-12-20 12:57:18 +01:00
|
|
|
Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
|
|
|
|
stage.close();
|
2022-01-23 22:05:23 +01:00
|
|
|
} catch (Exception e) {
|
2021-12-20 12:57:18 +01:00
|
|
|
labelError.setText(e.getMessage());
|
|
|
|
}
|
2021-11-29 15:44:55 +01:00
|
|
|
}
|
|
|
|
|
2022-01-20 13:33:49 +01:00
|
|
|
protected void sendHttpRequest(Event event) throws HttpRequestException {
|
|
|
|
DataController dataController = new DataController();
|
|
|
|
dataController.createEvent(event);
|
|
|
|
}
|
|
|
|
|
2021-11-29 15:44:55 +01:00
|
|
|
@FXML
|
2021-12-20 12:57:18 +01:00
|
|
|
protected void abortBtnClick(ActionEvent event) {
|
2021-11-29 15:44:55 +01:00
|
|
|
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
|
|
|
stage.close();
|
|
|
|
}
|
|
|
|
}
|