diff --git a/src/main/java/info/bukova/isspst/services/AbstractService.java b/src/main/java/info/bukova/isspst/services/AbstractService.java index 163873f6..4119d093 100644 --- a/src/main/java/info/bukova/isspst/services/AbstractService.java +++ b/src/main/java/info/bukova/isspst/services/AbstractService.java @@ -1,6 +1,9 @@ package info.bukova.isspst.services; import static ch.lambdaj.Lambda.filter; +import info.bukova.isspst.dao.BaseDao; +import info.bukova.isspst.data.DataModel; +import info.bukova.isspst.filters.Filter; import java.util.Date; import java.util.List; @@ -9,16 +12,10 @@ import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.Validator; -import org.hibernate.HibernateException; import org.hibernate.NonUniqueResultException; import org.hibernate.Query; import org.springframework.transaction.annotation.Transactional; -import info.bukova.isspst.dao.BaseDao; -import info.bukova.isspst.dao.IntegrityException; -import info.bukova.isspst.data.DataModel; -import info.bukova.isspst.filters.Filter; - public abstract class AbstractService implements Service { protected BaseDao dao; @@ -34,22 +31,22 @@ public abstract class AbstractService implements Service entity.setCreated(new Date()); dao.add(entity); } - + @Override @Transactional public void update(T entity) { - entity.setModified(new Date()); - dao.modify(entity); + if (entity.getCreated() == null) { + add(entity); + } else { + entity.setModified(new Date()); + dao.modify(entity); + } } @Override @Transactional public void delete(T entity) { - try { - dao.delete(entity); - } catch (HibernateException e) { - throw new IntegrityException(e); - } + dao.delete(entity); } @Override diff --git a/src/main/java/info/bukova/isspst/ui/FormViewModel.java b/src/main/java/info/bukova/isspst/ui/FormViewModel.java index 48e01e56..c4bd0e8e 100644 --- a/src/main/java/info/bukova/isspst/ui/FormViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/FormViewModel.java @@ -1,11 +1,12 @@ package info.bukova.isspst.ui; -import info.bukova.isspst.dao.IntegrityException; +import info.bukova.isspst.data.DataModel; import info.bukova.isspst.services.Service; import info.bukova.isspst.services.ValidationException; import java.util.Map; +import org.springframework.dao.DataIntegrityViolationException; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.ExecutionArgParam; @@ -14,7 +15,7 @@ import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Window; -public class FormViewModel { +public class FormViewModel { private T dataBean; private Map errMessages; @@ -34,7 +35,7 @@ public class FormViewModel { @NotifyChange("errMessages") public void save(@BindingParam("window") Window win) { try { - service.update(dataBean); + doSave(); win.detach(); } catch (ValidationException e) { errMessages = e.getMessages(); @@ -44,9 +45,11 @@ public class FormViewModel { classErr = ""; } - Messagebox.show("Chyba validace", "Error", Messagebox.OK, Messagebox.ERROR); - } catch (IntegrityException e) { + Messagebox.show("Chyba validace", "Chyba", Messagebox.OK, Messagebox.ERROR); + } catch (DataIntegrityViolationException e) { + dataBean.setCreated(null); e.printStackTrace(); + Messagebox.show("Chyba při ukládání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR); } } @@ -57,5 +60,13 @@ public class FormViewModel { protected void setErrMesages(Map msgs) { this.errMessages = msgs; } + + protected void doSave() { + service.update(dataBean); + } + + public boolean isCanSave() { + return true; + } } diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index bdc32a95..bdfbff3a 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -1,6 +1,5 @@ package info.bukova.isspst.ui; -import info.bukova.isspst.dao.IntegrityException; import info.bukova.isspst.data.DataModel; import info.bukova.isspst.filters.Filter; import info.bukova.isspst.services.Service; @@ -10,11 +9,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.dao.DataIntegrityViolationException; +import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.GlobalCommand; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Window; @@ -125,6 +128,7 @@ public class ListViewModel { @Command public void edit() { int index = dataList.indexOf(dataBean); + newRec = false; if (index != -1) { selIndex = index; } @@ -141,20 +145,46 @@ public class ListViewModel { @Command @NotifyChange({"dataList", "dataBean"}) public void delete() { + Messagebox.show("Opravdu smazat?", "Smazat záznam", Messagebox.YES|Messagebox.NO, + Messagebox.QUESTION, new EventListener() { + + @Override + public void onEvent(Event evt) throws Exception { + if (((Integer)evt.getData()).intValue() == Messagebox.YES) { + try { + service.delete(dataBean); + dataList.remove(dataBean); + dataBean = null; + BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataList"); + BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataBean"); + } catch (DataIntegrityViolationException e) { + Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR); + } + } + } + }); + + confirmDelete = false; + } + + @NotifyChange({"dataList", "dataBean"}) + private void onDelete() { try { service.delete(dataBean); dataList.remove(dataBean); dataBean = null; - } catch (IntegrityException e) { - Messagebox.show("Error while deleting object", "Error", Messagebox.OK, Messagebox.ERROR); + } catch (DataIntegrityViolationException e) { + Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR); } - confirmDelete = false; } @GlobalCommand @NotifyChange({"dataList", "dataBean"}) public void refresh() { - if (editBean != null && !editBean.isValid()) { + /*if (editBean != null && !editBean.isValid()) { + return; + }*/ + if (editBean.getCreated() == null) { return; } if (!filter && newRec) { @@ -220,28 +250,29 @@ public class ListViewModel { } } - private void loadFromDb() { - Thread fillThread = new Thread(new Runnable() { - - @Override - public void run() { - tmpList = service.getAll(); - - try { - Thread.sleep(200); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - fullFill = true; - } - }); - - fillThread.start(); - } +// private void loadFromDb() { +// Thread fillThread = new Thread(new Runnable() { +// +// @Override +// public void run() { +// tmpList = service.getAll(); +// +// try { +// Thread.sleep(200); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// fullFill = true; +// } +// }); +// +// fillThread.start(); +// } private void loadFromDbSync() { dataList.addAll(service.getAll()); + fullList = dataList; } protected void showForm() { diff --git a/src/main/webapp/WEB-INF/jdbc.properties b/src/main/webapp/WEB-INF/jdbc.properties index 3483bc97..658408f0 100644 --- a/src/main/webapp/WEB-INF/jdbc.properties +++ b/src/main/webapp/WEB-INF/jdbc.properties @@ -1,5 +1,5 @@ jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.dialect=org.hibernate.dialect.MySQLDialect -jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst +jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst?characterEncoding=utf8 jdbc.username=root jdbc.password=xsacfgd \ No newline at end of file diff --git a/src/main/webapp/app/form.css b/src/main/webapp/app/form.css new file mode 100644 index 00000000..4bd4c0c0 --- /dev/null +++ b/src/main/webapp/app/form.css @@ -0,0 +1,51 @@ +.nicebutton { +font-family: Arial; +color: #050005; +font-size: 12px; +padding-top: 3px; +padding-right: 10px; +padding-bottom: 3px; +padding-left: 10px; +margin: 4px; +text-decoration: none; +-webkit-border-radius: 5px; +-moz-border-radius: 5px; +border-radius: 5px; +-webkit-box-shadow: 0px 1px 3px #666666; +-moz-box-shadow: 0px 1px 3px #666666; +box-shadow: 0px 1px 3px #666666; +text-shadow: 1px 1px 2px #666666; +border: solid #8abaed 1px; +background: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#efefef)); +background: -moz-linear-gradient(top, #ffffff, #efefef); +-ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ffffff, endColorStr=#efefef); +filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ffffff, endColorStr=#efefef); +display:inline-block; /* IE is so silly */ +} +.nicebutton:hover { +background: #c5e8fa; +} +.nicebutton:disabled { +font-family: Arial; +color: #c4c4c4; +font-size: 12px; +padding-top: 3px; +padding-right: 10px; +padding-bottom: 3px; +padding-left: 10px; +margin: 5px; +text-decoration: none; +-webkit-border-radius: 5px; +-moz-border-radius: 5px; +border-radius: 5px; +-webkit-box-shadow: 0px 1px 3px #666666; +-moz-box-shadow: 0px 1px 3px #666666; +text-shadow: 0px 0px 0px #9e9e9e; +box-shadow: 0px 1px 3px #666666; +border: solid #d91c71 0px; +background: #ebebeb; +} + +.error { + color: red; +} \ No newline at end of file diff --git a/src/main/webapp/app/toolbar.zul b/src/main/webapp/app/toolbar.zul index 7c4684e0..2c0497d1 100644 --- a/src/main/webapp/app/toolbar.zul +++ b/src/main/webapp/app/toolbar.zul @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/src/main/webapp/img/save.png b/src/main/webapp/img/save.png new file mode 100644 index 00000000..024475d5 Binary files /dev/null and b/src/main/webapp/img/save.png differ