avatar on staff register (#315)
This commit was merged in pull request #315.
This commit is contained in:
@@ -11,15 +11,21 @@ import javafx.scene.control.Label;
|
|||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
import javafx.scene.control.PasswordField;
|
import javafx.scene.control.PasswordField;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.example.petshopdesktop.Validator;
|
import org.example.petshopdesktop.Validator;
|
||||||
import org.example.petshopdesktop.api.dto.common.DropdownOption;
|
import org.example.petshopdesktop.api.dto.common.DropdownOption;
|
||||||
import org.example.petshopdesktop.api.dto.employee.EmployeeRequest;
|
import org.example.petshopdesktop.api.dto.employee.EmployeeRequest;
|
||||||
|
import org.example.petshopdesktop.api.dto.employee.EmployeeResponse;
|
||||||
import org.example.petshopdesktop.api.endpoints.DropdownApi;
|
import org.example.petshopdesktop.api.endpoints.DropdownApi;
|
||||||
import org.example.petshopdesktop.api.endpoints.EmployeeApi;
|
import org.example.petshopdesktop.api.endpoints.EmployeeApi;
|
||||||
|
import org.example.petshopdesktop.api.endpoints.UserApi;
|
||||||
import org.example.petshopdesktop.util.ActivityLogger;
|
import org.example.petshopdesktop.util.ActivityLogger;
|
||||||
|
import org.example.petshopdesktop.util.DesktopImageSupport;
|
||||||
|
import org.example.petshopdesktop.util.FilePickerSupport;
|
||||||
import org.example.petshopdesktop.util.TextFieldFormatSupport;
|
import org.example.petshopdesktop.util.TextFieldFormatSupport;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StaffRegisterDialogController {
|
public class StaffRegisterDialogController {
|
||||||
@@ -38,6 +44,13 @@ public class StaffRegisterDialogController {
|
|||||||
@FXML private Label lblError;
|
@FXML private Label lblError;
|
||||||
@FXML private Button btnCreate;
|
@FXML private Button btnCreate;
|
||||||
|
|
||||||
|
@FXML private ImageView imgAvatarPreview;
|
||||||
|
@FXML private Label lblAvatarStatus;
|
||||||
|
@FXML private Button btnChangeAvatar;
|
||||||
|
@FXML private Button btnRemoveAvatar;
|
||||||
|
|
||||||
|
private File selectedAvatarFile;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void initialize() {
|
void initialize() {
|
||||||
TextFieldFormatSupport.applyPhoneNumberFormat(txtPhone);
|
TextFieldFormatSupport.applyPhoneNumberFormat(txtPhone);
|
||||||
@@ -65,6 +78,10 @@ public class StaffRegisterDialogController {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
btnChangeAvatar.setOnMouseClicked(e -> handleChangeAvatar());
|
||||||
|
btnRemoveAvatar.setOnMouseClicked(e -> handleRemoveAvatar());
|
||||||
|
btnRemoveAvatar.setDisable(true);
|
||||||
|
|
||||||
loadStores();
|
loadStores();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +100,22 @@ public class StaffRegisterDialogController {
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleChangeAvatar() {
|
||||||
|
File file = FilePickerSupport.pickImageFile(btnCreate.getScene().getWindow());
|
||||||
|
if (file == null) return;
|
||||||
|
selectedAvatarFile = file;
|
||||||
|
lblAvatarStatus.setText("Selected: " + file.getName());
|
||||||
|
DesktopImageSupport.loadImageInto(imgAvatarPreview, file.toURI().toString(), 90, 90);
|
||||||
|
btnRemoveAvatar.setDisable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleRemoveAvatar() {
|
||||||
|
selectedAvatarFile = null;
|
||||||
|
imgAvatarPreview.setImage(null);
|
||||||
|
lblAvatarStatus.setText("No avatar");
|
||||||
|
btnRemoveAvatar.setDisable(true);
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void btnCreateClicked(ActionEvent event) {
|
void btnCreateClicked(ActionEvent event) {
|
||||||
lblError.setText("");
|
lblError.setText("");
|
||||||
@@ -147,6 +180,7 @@ public class StaffRegisterDialogController {
|
|||||||
String staffRole = cbStaffRole.getValue();
|
String staffRole = cbStaffRole.getValue();
|
||||||
boolean active = "Active".equals(cbActive.getValue());
|
boolean active = "Active".equals(cbActive.getValue());
|
||||||
Long storeId = cbStore.getValue().getId();
|
Long storeId = cbStore.getValue().getId();
|
||||||
|
File avatarFile = selectedAvatarFile;
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@@ -163,7 +197,14 @@ public class StaffRegisterDialogController {
|
|||||||
request.setActive(active);
|
request.setActive(active);
|
||||||
request.setPrimaryStoreId(storeId);
|
request.setPrimaryStoreId(storeId);
|
||||||
|
|
||||||
EmployeeApi.getInstance().createEmployee(request);
|
EmployeeResponse created = EmployeeApi.getInstance().createEmployee(request);
|
||||||
|
|
||||||
|
if (avatarFile != null && created.getUserId() != null) {
|
||||||
|
try {
|
||||||
|
UserApi.getInstance().uploadUserAvatar(created.getUserId(), avatarFile.toPath());
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.PasswordField?>
|
<?import javafx.scene.control.PasswordField?>
|
||||||
<?import javafx.scene.control.TextField?>
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
<?import javafx.scene.layout.HBox?>
|
<?import javafx.scene.layout.HBox?>
|
||||||
<?import javafx.scene.layout.Region?>
|
<?import javafx.scene.layout.Region?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
@@ -24,6 +25,23 @@
|
|||||||
|
|
||||||
<Label fx:id="lblError" text="" textFill="#FF6B6B" wrapText="true" />
|
<Label fx:id="lblError" text="" textFill="#FF6B6B" wrapText="true" />
|
||||||
|
|
||||||
|
<HBox alignment="CENTER_LEFT" spacing="15.0">
|
||||||
|
<children>
|
||||||
|
<ImageView fx:id="imgAvatarPreview" fitHeight="90.0" fitWidth="90.0" pickOnBounds="true" preserveRatio="true" />
|
||||||
|
<VBox spacing="8.0">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="lblAvatarStatus" text="No avatar" textFill="#2c3e50" />
|
||||||
|
<HBox spacing="8.0">
|
||||||
|
<children>
|
||||||
|
<Button fx:id="btnChangeAvatar" mnemonicParsing="false" text="Change Avatar" />
|
||||||
|
<Button fx:id="btnRemoveAvatar" mnemonicParsing="false" text="Remove Avatar" />
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
|
||||||
<HBox spacing="10.0">
|
<HBox spacing="10.0">
|
||||||
<children>
|
<children>
|
||||||
<VBox spacing="6.0" HBox.hgrow="ALWAYS">
|
<VBox spacing="6.0" HBox.hgrow="ALWAYS">
|
||||||
|
|||||||
Reference in New Issue
Block a user