diff --git a/src/main/java/info/bukova/isspst/CommonUrlResolver.java b/src/main/java/info/bukova/isspst/CommonUrlResolver.java new file mode 100644 index 00000000..ffa975ba --- /dev/null +++ b/src/main/java/info/bukova/isspst/CommonUrlResolver.java @@ -0,0 +1,39 @@ +package info.bukova.isspst; + +import info.bukova.isspst.data.DataModel; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; + +public class CommonUrlResolver implements EntityUrlResolver { + + @Autowired + private HttpServletRequest request; + protected String defaultUrl; + + public CommonUrlResolver() { + + } + + @Override + public String entityUrl(Object entity) { + if (defaultUrl == null) { + this.defaultUrl = request.getRequestURL().toString(); + this.defaultUrl = defaultUrl.substring(0, defaultUrl.indexOf(request.getServletPath())); + } + + if (!DataModel.class.isAssignableFrom(entity.getClass())) { + return defaultUrl + "/app"; + } + + String url = Constants.URL_MAP.get(entity.getClass()); + + if (url == null) { + return defaultUrl + "/app"; + } + + return defaultUrl + url + "?select=" + String.valueOf(((DataModel)entity).getId()); + } + +} diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 9578e056..a26cf875 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -1,9 +1,15 @@ package info.bukova.isspst; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import info.bukova.isspst.data.Permission; import info.bukova.isspst.data.PermissionType; +import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.RequirementType; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.TripRequirement; import info.bukova.isspst.reporting.Report; import info.bukova.isspst.reporting.ReportMapping; import info.bukova.isspst.services.addressbook.AdbService; @@ -129,4 +135,10 @@ public class Constants { public final static long REQ_TYPE_MATERIAL = 1; public final static long REQ_TYPE_SERVICES = 2; + + @SuppressWarnings("serial") + public final static Map, String> URL_MAP = Collections.unmodifiableMap(new HashMap, String>() {{ + put(Requirement.class, "/main/orders/"); + put(TripRequirement.class, "/main/trips/requirements/"); + }} ); } diff --git a/src/main/java/info/bukova/isspst/EntityUrlResolver.java b/src/main/java/info/bukova/isspst/EntityUrlResolver.java new file mode 100644 index 00000000..745f0e71 --- /dev/null +++ b/src/main/java/info/bukova/isspst/EntityUrlResolver.java @@ -0,0 +1,7 @@ +package info.bukova.isspst; + +public interface EntityUrlResolver { + + public String entityUrl(Object entity); + +} diff --git a/src/main/java/info/bukova/isspst/RequirementUrlResolver.java b/src/main/java/info/bukova/isspst/RequirementUrlResolver.java new file mode 100644 index 00000000..f427c103 --- /dev/null +++ b/src/main/java/info/bukova/isspst/RequirementUrlResolver.java @@ -0,0 +1,39 @@ +package info.bukova.isspst; + +import info.bukova.isspst.data.Requirement; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; + +public class RequirementUrlResolver implements EntityUrlResolver { + + private String defaultUrl; + @Autowired + private HttpServletRequest request; + + public RequirementUrlResolver() { + + } + + @Override + public String entityUrl(Object entity) { + if (!(entity instanceof Requirement)) { + return defaultUrl + "/app"; + } + + if (defaultUrl == null) { + this.defaultUrl = request.getRequestURL().toString(); + this.defaultUrl = defaultUrl.substring(0, defaultUrl.indexOf(request.getServletPath())); + } + + Requirement req = (Requirement)entity; + + if (req.getKind() == Constants.REQ_TYPE_MATERIAL) { + return defaultUrl + Constants.URL_MAP.get(req) + "material/?select=" + String.valueOf(req.getId()); + } else { + return defaultUrl + Constants.URL_MAP.get(req) + "services/?select=" + String.valueOf(req.getId()); + } + } + +} diff --git a/src/main/java/info/bukova/isspst/UrlResolverHolder.java b/src/main/java/info/bukova/isspst/UrlResolverHolder.java new file mode 100644 index 00000000..0244549c --- /dev/null +++ b/src/main/java/info/bukova/isspst/UrlResolverHolder.java @@ -0,0 +1,30 @@ +package info.bukova.isspst; + +import java.util.HashMap; +import java.util.Map; + +public class UrlResolverHolder { + + private EntityUrlResolver commonResolver; + private Map, EntityUrlResolver> resolvers; + + public UrlResolverHolder(EntityUrlResolver common) { + this.commonResolver = common; + resolvers = new HashMap, EntityUrlResolver>(); + } + + public void setResolvers(Map, EntityUrlResolver> resolvers) { + this.resolvers = resolvers; + } + + public EntityUrlResolver resolverFor(Class clazz) { + EntityUrlResolver res = resolvers.get(clazz); + + if (res == null) { + return commonResolver; + } + + return res; + } + +} diff --git a/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java b/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java index a441714d..74eadf36 100644 --- a/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java +++ b/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java @@ -1,5 +1,8 @@ package info.bukova.isspst.mail; +import info.bukova.isspst.EntityUrlResolver; +import info.bukova.isspst.UrlResolverHolder; + import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; @@ -12,6 +15,7 @@ public class EntityMessageBuilder implements MessageBuilder { private final static Logger logger = LoggerFactory.getLogger(EntityMessageBuilder.class); private boolean html; + private UrlResolverHolder urlResolverHolder; public void setHtml(boolean html) { this.html = html; @@ -53,7 +57,11 @@ public class EntityMessageBuilder implements MessageBuilder { for (String p : properties) { try { - ret = ret.replaceAll("\\[" + p + "\\]", BeanUtils.getProperty(data, p)); + if (p.equals("-url-")) { + ret = ret.replaceAll("\\[" + p + "\\]", getUrl(data)); + } else { + ret = ret.replaceAll("\\[" + p + "\\]", BeanUtils.getProperty(data, p)); + } } catch (IllegalAccessException e) { logger.error(e.getMessage()); } catch (InvocationTargetException e) { @@ -67,5 +75,18 @@ public class EntityMessageBuilder implements MessageBuilder { return ret; } + + private String getUrl(Object data) { + if (urlResolverHolder == null) { + return ""; + } + + EntityUrlResolver res = urlResolverHolder.resolverFor(data.getClass()); + return res.entityUrl(data); + } + + public void setUrlResolverHolder(UrlResolverHolder urlResolverHolder) { + this.urlResolverHolder = urlResolverHolder; + } } diff --git a/src/main/java/info/bukova/isspst/mail/MailerWithAttachement.java b/src/main/java/info/bukova/isspst/mail/MailerWithAttachement.java index 16ab9a80..58abe507 100644 --- a/src/main/java/info/bukova/isspst/mail/MailerWithAttachement.java +++ b/src/main/java/info/bukova/isspst/mail/MailerWithAttachement.java @@ -42,6 +42,10 @@ public class MailerWithAttachement implements Mailer { message.setFrom(from); } } + + if (message.getReplyTo() == null) { + message.setReplyTo(message.getFrom()); + } helper.setFrom(message.getFrom()); helper.setReplyTo(message.getReplyTo()); @@ -63,6 +67,7 @@ public class MailerWithAttachement implements Mailer { } try { sender.send(mimeMessage); + logger.info("Mail queued for send"); } catch (MailAuthenticationException e) { logger.error("Authentication error"); } catch (MailSendException e) { diff --git a/src/main/java/info/bukova/isspst/ui/BindingForm.java b/src/main/java/info/bukova/isspst/ui/BindingForm.java index 2c84623b..118729da 100644 --- a/src/main/java/info/bukova/isspst/ui/BindingForm.java +++ b/src/main/java/info/bukova/isspst/ui/BindingForm.java @@ -44,7 +44,15 @@ public class BindingForm extends SimpleForm { // } try { - PropertyUtils.setProperty(object, key, getField(key)); + if (PropertyUtils.getPropertyType(object, key).isPrimitive() + && (getField(key) == null)) + { + PropertyUtils.setProperty(object, key, 0); + } + else + { + PropertyUtils.setProperty(object, key, getField(key)); + } } catch (NoSuchMethodException e) { diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index 98056f43..0fb8b86d 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -300,11 +300,16 @@ public class ListViewModel extends DocumentViewModel if (selIndex > -1) { this.setDataBean(dataList.get(selIndex)); + afterSelect(); } } protected void beforeSelectViaUrl() { + } + + protected void afterSelect() { + } @Command diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java index b374199a..a2773232 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java @@ -4,14 +4,18 @@ import info.bukova.isspst.data.Address; import info.bukova.isspst.data.AddressEmb; import info.bukova.isspst.data.Order; import info.bukova.isspst.data.OrderItem; +import info.bukova.isspst.services.IsspstException; import info.bukova.isspst.services.addressbook.AdbService; +import info.bukova.isspst.services.addressbook.AddressFinder; import info.bukova.isspst.services.orders.OrderService; import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.ui.FormViewModel; import info.bukova.isspst.validators.OrderFormValidator; import java.math.BigDecimal; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,9 +23,13 @@ import org.zkoss.bind.BindUtils; import org.zkoss.bind.SimpleForm; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.GlobalCommand; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.select.annotation.WireVariable; +import org.zkoss.zul.Messagebox; +import org.zkoss.zul.Window; import org.zkoss.zul.impl.InputElement; public class OrderForm extends FormViewModel @@ -29,8 +37,12 @@ public class OrderForm extends FormViewModel private final static Logger log = LoggerFactory.getLogger(OrderForm.class.getName()); @WireVariable - protected AdbService adbService; - + private AdbService adbService; + @WireVariable + private AddressFinder addressFinderAres; + @WireVariable + private AddressFinder addressFinderTaxID; + @WireVariable protected GlobalSettingsService settingsService; @@ -61,14 +73,19 @@ public class OrderForm extends FormViewModel { this.orderFormValidator = new OrderFormValidator(); - if (this.getDataBean().getSuplier() == null) + if (getDataBean().getSuplier() != null) + { + if (getDataBean().getSuplier().getAddress().getId() != 0) + { + this.selectedSuppAddrItem = this.getDataBean().getSuplier().getAddress(); + } + this.suppCompany = getDataBean().getSuplier().getCompany(); + } + else { this.getDataBean().setSuplier(new AddressEmb()); } - this.selectedSuppAddrItem = this.getDataBean().getSuplier().getAddress(); - this.suppCompany = this.selectedSuppAddrItem.getCompany(); - if (this.getDataBean().getDeliveryAddress() == null) { this.getDataBean().setDeliveryAddress(new AddressEmb()); @@ -289,4 +306,60 @@ public class OrderForm extends FormViewModel // jiných objednávek orderService.updateApprovedItems(this.getDataBean(), orderedChanged); } + + @Command + @NotifyChange({"dataBean", "suppCompany"}) + public void searchAddress() + { + getDataForm().bind(); + + Address adr = getDataBean().getSuplier().getAddress(); + + if (adr.getIc() != 0) + { + try + { + adbService.fillFoundData(addressFinderTaxID, adr); + getDataBean().setSuplier(new AddressEmb(adr)); + suppCompany = adr.getCompany(); + } + catch (IsspstException e) + { + Messagebox.show("Chyba při hledání adresy", "Chyba", Messagebox.OK, Messagebox.ERROR); + return; + } + + } + else + { + Map> arg = new HashMap>(); + try { + arg.put("result", adbService.lookForAddr(addressFinderAres, adr)); + } catch (IsspstException e) { + Messagebox.show("Chyba při hledání adresy", "Chyba", Messagebox.OK, Messagebox.ERROR); + return; + } + + Window resWin = (Window) Executions.createComponents("/lists/addressbook/addrFindResult.zul", null, arg); + resWin.doModal(); + } + } + + @GlobalCommand + @NotifyChange({"dataBean", "suppCompany"}) + public void selectAddress(@BindingParam("selected") Address selected, @BindingParam("window") Window window) { + try { + adbService.fillFoundData(addressFinderTaxID, selected); + } catch (IsspstException e) { + e.printStackTrace(); + } + + Address adr = getDataBean().getSuplier().getAddress(); + adbService.mergeAddress(adr, selected, true); + getDataBean().setSuplier(new AddressEmb(adr)); + suppCompany = adr.getCompany(); + + if (window != null) + window.detach(); + } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java b/src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java index a49bb956..780b41d8 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java @@ -82,4 +82,9 @@ public class RequirementSubpage extends ListViewModel { this.requirementsItemRenderer = requirementsItemRenderer; } + + @Override + protected void afterSelect() { + BindUtils.postNotifyChange(null, null, this, "canApprove"); + } } diff --git a/src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java b/src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java index b085b676..62389f38 100644 --- a/src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java +++ b/src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java @@ -94,6 +94,12 @@ public class GlobalSettingsVM { message.setText(message.getText() + "[" + field + "]"); } + @Command + @NotifyChange("settings") + public void insertUrl(@BindingParam("message") MailMessage message) { + message.setText(message.getText() + "[-url-]"); + } + @Command @NotifyChange("settings") public void addAddress() { diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 1c4075f7..2cc2ee12 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -172,6 +172,7 @@ GlobalSettingsHours=Hodin GlobalSettingsUploadStamp=Nahrát obrázek razítka GlobalSettingsStamp=Razítko GlobalSettingsReqEnable=Povolení požadavků +GlobalSettingsInsertUrl=Vložit URL záznamu UserSettings=Uživatelské nastavení diff --git a/src/main/webapp/WEB-INF/spring/mail-services.xml b/src/main/webapp/WEB-INF/spring/mail-services.xml index ebf1bb71..7115106e 100644 --- a/src/main/webapp/WEB-INF/spring/mail-services.xml +++ b/src/main/webapp/WEB-INF/spring/mail-services.xml @@ -30,6 +30,20 @@ + + + + + + + + + + + + + + diff --git a/src/main/webapp/app/template.zhtml b/src/main/webapp/app/template.zhtml index 38f80528..bca9beb4 100644 --- a/src/main/webapp/app/template.zhtml +++ b/src/main/webapp/app/template.zhtml @@ -51,6 +51,6 @@
- + \ No newline at end of file diff --git a/src/main/webapp/main/orders/created/orderForm.zul b/src/main/webapp/main/orders/created/orderForm.zul index f11d9b9d..9c97d689 100644 --- a/src/main/webapp/main/orders/created/orderForm.zul +++ b/src/main/webapp/main/orders/created/orderForm.zul @@ -146,19 +146,29 @@ ${labels.SuppliersFormCompany} : - - - + + + + + +