diff --git a/src/main/java/info/bukova/isspst/storage/FileStorage.java b/src/main/java/info/bukova/isspst/storage/FileStorage.java
new file mode 100644
index 00000000..f631ac2b
--- /dev/null
+++ b/src/main/java/info/bukova/isspst/storage/FileStorage.java
@@ -0,0 +1,18 @@
+package info.bukova.isspst.storage;
+
+import java.io.File;
+
+public interface FileStorage {
+
+// public String getRootPath();
+ public void saveFile(byte[] data, String fileName);
+ public void saveFile(File file, String path);
+ public void removeFile(String fileName);
+ public void moveFile(String source, String destination);
+ public void createDirectory(String dir);
+ public byte[] fileData(String fileName);
+ public File file(String fileName);
+ public boolean dirExists(String path);
+ public String serverPath(String fileName);
+
+}
diff --git a/src/main/java/info/bukova/isspst/storage/LocalFileStorage.java b/src/main/java/info/bukova/isspst/storage/LocalFileStorage.java
new file mode 100644
index 00000000..dc5d3150
--- /dev/null
+++ b/src/main/java/info/bukova/isspst/storage/LocalFileStorage.java
@@ -0,0 +1,146 @@
+package info.bukova.isspst.storage;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+
+public class LocalFileStorage implements FileStorage {
+
+ private String rootPath;
+ private ServletContext context;
+
+ public void setRootPath(String rootPath) {
+ this.rootPath = rootPath;
+ }
+
+ public void setContext(ServletContext ctx) {
+ this.context = ctx;
+ }
+
+ private String getFullPath() {
+ return context.getRealPath(rootPath) + File.separator;
+ }
+
+ @Override
+ public void saveFile(byte[] data, String fileName) {
+
+ File file = new File(getFullPath() + fileName);
+ FileOutputStream os = null;
+ try {
+ os = new FileOutputStream(file);
+ os.write(data);
+ os.flush();
+ os.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (os != null) {
+ os.flush();
+ os.close();
+ }
+ } catch (IOException e) {
+ throw new StorageException("Cannot close stream", e.getCause());
+ }
+ }
+ }
+
+ @Override
+ public void saveFile(File file, String path) {
+ File dest = new File(getFullPath() + path + File.pathSeparator + file.getName());
+ FileOutputStream fos = null;
+
+ try {
+ fos = new FileOutputStream(dest);
+ fos.write(fileData(file.getName()));
+ fos.flush();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ throw new StorageException("Cannot move file: " + file.getName(), e.getCause());
+ } catch (IOException e) {
+ throw new StorageException("Cannot move file: " + file.getName(), e.getCause());
+ } finally {
+ if (fos != null) {
+ try {
+ fos.flush();
+ fos.close();
+ } catch (IOException e) {
+ throw new StorageException("Cannot close stream", e.getCause());
+ }
+ }
+ }
+ }
+
+ @Override
+ public void removeFile(String fileName) {
+ File f = new File(getFullPath() + fileName);
+ if (!f.delete()) {
+ throw new StorageException("Cannot delete file: " + getFullPath()
+ + fileName);
+ }
+ }
+
+ @Override
+ public byte[] fileData(String fileName) {
+ File f = new File(getFullPath() + fileName);
+ byte[] out = new byte[(int) f.length()];
+
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(f);
+ fis.read(out);
+ fis.close();
+ } catch (FileNotFoundException e) {
+ throw new StorageException("File cannot be found: " + fileName, e.getCause());
+ } catch (IOException e) {
+ throw new StorageException("Cannot read file: " + fileName, e.getCause());
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ throw new StorageException("Cannot close stream", e.getCause());
+ }
+ }
+ }
+
+ return out;
+ }
+
+ @Override
+ public File file(String fileName) {
+ return new File(getFullPath() + fileName);
+ }
+
+ @Override
+ public void moveFile(String source, String destination) {
+ saveFile(new File(getFullPath() + source), destination);
+ }
+
+ @Override
+ public void createDirectory(String dir) {
+ File f = new File(getFullPath() + dir);
+ if (!f.mkdir()) {
+ throw new StorageException("Cannot create directory: "
+ + getFullPath() + dir);
+ }
+ }
+
+ @Override
+ public boolean dirExists(String path) {
+ File f = new File(getFullPath() + path);
+ return f.exists() && f.isDirectory();
+ }
+
+ @Override
+ public String serverPath(String fileName) {
+ return context.getRealPath(rootPath + File.separator + fileName);
+ }
+
+}
diff --git a/src/main/java/info/bukova/isspst/storage/StorageException.java b/src/main/java/info/bukova/isspst/storage/StorageException.java
new file mode 100644
index 00000000..6538e4bf
--- /dev/null
+++ b/src/main/java/info/bukova/isspst/storage/StorageException.java
@@ -0,0 +1,17 @@
+package info.bukova.isspst.storage;
+
+import info.bukova.isspst.services.IsspstException;
+
+public class StorageException extends IsspstException {
+
+ private static final long serialVersionUID = -1303880908451845756L;
+
+ public StorageException(String reason) {
+ super(reason);
+ }
+
+ public StorageException(String reason, Throwable cause) {
+ super(reason, cause);
+ }
+
+}
diff --git a/src/main/java/info/bukova/isspst/ui/MainMenu.java b/src/main/java/info/bukova/isspst/ui/MainMenu.java
index 5b710e25..e5454e35 100644
--- a/src/main/java/info/bukova/isspst/ui/MainMenu.java
+++ b/src/main/java/info/bukova/isspst/ui/MainMenu.java
@@ -48,4 +48,11 @@ public class MainMenu
Window window = (Window) Executions.createComponents("/settings/globalSettings.zul", null, null);
window.doModal();
}
+
+ @Command
+ public void userSettings()
+ {
+ Window window = (Window) Executions.createComponents("/settings/userSettings.zul", null, null);
+ window.doModal();
+ }
}
diff --git a/src/main/java/info/bukova/isspst/ui/settings/UserSettingsVM.java b/src/main/java/info/bukova/isspst/ui/settings/UserSettingsVM.java
new file mode 100644
index 00000000..536261e2
--- /dev/null
+++ b/src/main/java/info/bukova/isspst/ui/settings/UserSettingsVM.java
@@ -0,0 +1,86 @@
+package info.bukova.isspst.ui.settings;
+
+import info.bukova.isspst.data.UserSettingsData;
+import info.bukova.isspst.services.users.UserService;
+import info.bukova.isspst.storage.FileStorage;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import org.zkoss.bind.annotation.BindingParam;
+import org.zkoss.bind.annotation.Command;
+import org.zkoss.bind.annotation.ContextParam;
+import org.zkoss.bind.annotation.ContextType;
+import org.zkoss.bind.annotation.Init;
+import org.zkoss.bind.annotation.NotifyChange;
+import org.zkoss.zk.ui.event.UploadEvent;
+import org.zkoss.zk.ui.select.annotation.WireVariable;
+import org.zkoss.zul.Window;
+
+public class UserSettingsVM {
+
+ @WireVariable
+ private UserService userService;
+ @WireVariable
+ private FileStorage storage;
+ private UserSettingsData settings;
+
+ @Init
+ public void init() {
+ settings = userService.getUserSettings();
+ }
+
+ public UserSettingsData getSettings() {
+ return settings;
+ }
+
+ @Command
+ @NotifyChange({"settings", "signatureImg"})
+ public void uploadSignature(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent upEvent) {
+ int i = upEvent.getMedia().getName().lastIndexOf(".");
+ String fileName = "SignatureImageFile_" + userService.getCurrent().getUsername() + upEvent.getMedia().getName().substring(i);
+
+ storage.saveFile(upEvent.getMedia().getByteData(), fileName);
+ settings.setSignatureFile(fileName);
+ }
+
+ @Command
+ @NotifyChange("signatureImg")
+ public void removeSignature() {
+ settings.setSignatureFile(null);
+ }
+
+ @Command
+ public void save(@BindingParam("window") Window window) {
+ userService.setUserSettings(settings);
+ userService.update(userService.getCurrent());
+ onClose();
+ window.detach();
+ }
+
+ @Command
+ public void onClose() {
+ if (userService.getUserSettings().getSignatureFile() == null && settings.getSignatureFile() != null) {
+ storage.removeFile(settings.getSignatureFile());
+ }
+ }
+
+ public boolean isCanSave() {
+ return true;
+ }
+
+ public RenderedImage getSignatureImg() {
+ if (settings.getSignatureFile() == null || settings.getSignatureFile().isEmpty()) {
+ return null;
+ }
+
+ try {
+ return ImageIO.read(storage.file(settings.getSignatureFile()));
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+}
diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties
index 0dcbb8ae..cf5ac7d0 100644
--- a/src/main/webapp/WEB-INF/locales/zk-label.properties
+++ b/src/main/webapp/WEB-INF/locales/zk-label.properties
@@ -165,6 +165,8 @@ GlobalSettingsRefunds=Náhrady
GlobalSettingsFreeMealsCount=Počet jídel zdarma
GlobalSettingsHours=Hodin
+UserSettings=Uživatelské nastavení
+
TravelOrdersFormTitle=Vyúčtování služební cesty
TravelOrdersGridNumser=Číslo
TravelOrdersGridReqDate=Datum požadavku
diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml
index 46ba55ef..4289d52e 100644
--- a/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -159,6 +159,12 @@
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/upload/upload.dir b/src/main/webapp/WEB-INF/upload/upload.dir
new file mode 100644
index 00000000..3c546eb2
--- /dev/null
+++ b/src/main/webapp/WEB-INF/upload/upload.dir
@@ -0,0 +1 @@
+dummy file
\ No newline at end of file
diff --git a/src/main/webapp/app/mainMenu.zul b/src/main/webapp/app/mainMenu.zul
index a987b05f..c7987158 100644
--- a/src/main/webapp/app/mainMenu.zul
+++ b/src/main/webapp/app/mainMenu.zul
@@ -74,6 +74,9 @@
image="/img/global-setting-016.png"
label="${labels.GlobalSettings}…"
onClick="@command('globalSettings')" />
+