Commit 7065519a by Antti Tonkyra

Merge branch 'master' of dev.intra.insomnia.fi:/data/bortal

2 parents 5564ec9c 139ae8d2
...@@ -32,6 +32,8 @@ public class Role extends GenericEntity { ...@@ -32,6 +32,8 @@ public class Role extends GenericEntity {
protected static final String EVENT_ID_COLUMN = "event_id"; protected static final String EVENT_ID_COLUMN = "event_id";
public static final Role EMPTY_ROLE = new Role("----");
@Column(name = NAME_COLUMN, nullable = false) @Column(name = NAME_COLUMN, nullable = false)
private String name; private String name;
...@@ -83,6 +85,11 @@ public class Role extends GenericEntity { ...@@ -83,6 +85,11 @@ public class Role extends GenericEntity {
this.name = roleName; this.name = roleName;
} }
private Role(String rolename) {
setId(0);
name = rolename;
}
public String getName() { public String getName() {
return name; return name;
} }
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.product.edit" />
<ui:define name="content"> <ui:define name="content">
<products:manageDiscount commitaction="#{productView.createDiscount()}" commitvalue="#{i18n['discount.create']}" /> <products:manageDiscount commitaction="#{productView.createDiscount()}" commitvalue="#{i18n['discount.create']}" />
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:products="http://java.sun.com/jsf/composite/cditools/products"
xmlns:products="http://java.sun.com/jsf/composite/cditools/products"> >
<h:head> <h:head>
<title></title> <title></title>
...@@ -18,9 +17,72 @@ ...@@ -18,9 +17,72 @@
</f:metadata> </f:metadata>
<ui:param name="thispage" value="page.product.edit" /> <ui:param name="thispage" value="page.product.edit" />
<ui:define name="content"> <ui:define name="content">
<products:edit commitaction="#{productView.saveProduct()}" <products:edit commitaction="#{productView.saveProduct()}" commitvalue="#{i18n['products.save']}" />
commitvalue="#{i18n['products.save']}" />
<h:form id="discounts">
<h:commandButton rendered="#{!empty productView.product.id}" action="#{productView.initCreateDiscount()}"
value="#{i18n['product.createDiscount']}"
>
</h:commandButton>
<h:dataTable border="1" id="discount" value="#{productView.productDiscounts}" var="discount"
rendered="#{!empty productView.product.id and !empty productView.product.discounts}"
>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.percentage']}" />
</f:facet>
<h:outputText value="#{discount.percentage}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.code']}" />
</f:facet>
<h:outputText value="#{discount.code}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.details']}" />
</f:facet>
<h:outputText value="#{discount.details}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.shortdesc']}" />
</f:facet>
<h:outputText value="#{discount.shortdesc}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.amountMin']}" />
</f:facet>
<h:outputText value="#{discount.amountMin}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.amountMax']}" />
</f:facet>
<h:outputText value="#{discount.amountMax}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.maxNum']}" />
</f:facet>
<h:outputText value="#{discount.maxNum}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.perUser']}" />
</f:facet>
<h:outputText value="#{discount.perUser}" />
</h:column>
<h:column>
<h:commandButton action="#{productView.editDiscount()}" value="#{i18n['discount.edit']}" />
</h:column>
</h:dataTable>
</h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:products="http://java.sun.com/jsf/composite/cditools/products"
> >
<h:head> <h:head>
<title></title> <title></title>
...@@ -11,11 +11,8 @@ ...@@ -11,11 +11,8 @@
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.product.edit" />
<ui:define name="content"> <ui:define name="content">
<products:manageDiscount commitaction="#{productView.save()}" commitvalue="#{i18n['discount.save']}" /> <products:manageDiscount commitaction="#{productView.save()}" commitvalue="#{i18n['discount.save']}" />
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:composite="http://java.sun.com/jsf/composite" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:c="http://java.sun.com/jsp/jstl/core"
> >
...@@ -15,105 +15,60 @@ ...@@ -15,105 +15,60 @@
<composite:implementation> <composite:implementation>
<h:form id="productform"> <h:form id="productform">
<h:inputHidden value="#{productView.product.id}" /> <h:panelGrid columns="3">
<h:panelGrid columns="2"> <h:outputLabel for="name" value="#{i18n['product.name']}:" />
<h:outputLabel value="#{i18n['product.name']}:" /> <h:inputText id="name" value="#{productView.product.name}" />
<h:inputText value="#{productView.product.name}" /> <h:message for="name" />
<h:outputLabel value="#{i18n['product.price']}:" /> <h:outputLabel for="price" value="#{i18n['product.price']}:" />
<h:inputText value="#{productView.product.price}" /> <h:inputText id="price" value="#{productView.product.price}" />
<h:message for="price" />
<h:outputLabel value="#{i18n['product.unitName']}:" />
<h:inputText value="#{productView.product.unitName}" /> <h:outputLabel for="unitName" value="#{i18n['product.unitName']}:" />
<h:inputText id="unitName" value="#{productView.product.unitName}" />
<h:message for="unitName" />
<h:outputLabel for="vat" value="#{i18n['product.vat']}:" />
<h:inputText id="vat" value="#{productView.product.vat}" />
<h:message for="vat" />
<h:outputLabel for="sort" value="#{i18n['product.sort']}:" />
<h:inputText id="sort" value="#{productView.product.sort}" />
<h:message for="sort" />
<h:outputLabel for="barcode" value="#{i18n['product.barcode']}:" />
<h:inputText id="barcode" value="#{productView.product.barcode}" />
<h:message for="barcode" />
<h:outputLabel for="prepaid" value="#{i18n['product.prepaid']}" />
<h:selectBooleanCheckbox id="prepaid" value="#{productView.product.prepaid}" />
<h:message for="prepaid" />
<h:outputLabel for="instant" value="#{i18n['product.prepaidInstant']}" />
<h:selectBooleanCheckbox id="instant" value="#{productView.product.prepaidInstant}" />
<h:message for="instant" />
<h:outputLabel for="provides" value="#{i18n['product.providedRole']}" />
<h:selectOneMenu id="provides" layout="pageDirection" value="#{productView.product.provides}"
converter="#{roleConverter}"
>
<f:selectItems var="role" itemLabel="#{role.name}" value="#{roleDataView.rolesWithEmpty}"
noSelectionValue="#{roleDataView.noSelection}"
/>
</h:selectOneMenu>
<h:message for="provides" />
<h:outputLabel value="#{i18n['product.vat']}:" />
<h:inputText value="#{productView.product.vat}" />
<h:outputLabel value="#{i18n['product.sort']}:" /> <h:commandButton id="commitbtn" action="#{cc.attrs.commitaction}" value="#{cc.attrs.commitvalue}" />
<h:inputText value="#{productView.product.sort}" /> </h:panelGrid>
<h:outputLabel value="#{i18n['product.barcode']}:" />
<h:inputText value="#{productView.product.barcode}" />
<h:outputLabel value="#{i18n['product.prepaid']}" />
<h:selectBooleanCheckbox value="#{productView.product.prepaid}" />
<h:outputLabel value="#{i18n['product.prepaidInstant']}" />
<h:selectBooleanCheckbox value="#{productView.product.prepaidInstant}" />
<h:outputLabel value="#{i18n['product.providedRole']}" />
<h:selectOneMenu layout="pageDirection" value="#{productView.product.role}" converter="#{roleConverter}" id="roles">
<f:selectItems var="role" itemLabel="#{role.name}" value="#{roleDataView.roles}" />
</h:selectOneMenu>
<h:commandButton id="commitbtn" action="#{cc.attrs.commitaction}" value="#{cc.attrs.commitvalue}" />
</h:panelGrid>
</h:form> </h:form>
<h:commandButton rendered="#{!empty productView.product.id}" action="#{productView.createDiscount}"
value="#{i18n['product.createDiscount']}"
/>
<h:form id="discounts" rendered="#{!empty productView.product.id and !empty productView.product.discounts}">
<h:dataTable border="1" id="discount" value="#{productView.product.discounts}" var="discount">
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.percentage']}" />
</f:facet>
<h:outputText value="#{discount.percentage}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.code']}" />
</f:facet>
<h:outputText value="#{discount.code}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.details']}" />
</f:facet>
<h:outputText value="#{discount.details}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.shortdesc']}" />
</f:facet>
<h:outputText value="#{discount.shortdesc}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.amountMin']}" />
</f:facet>
<h:outputText value="#{discount.amountMin}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.amountMax']}" />
</f:facet>
<h:outputText value="#{discount.amountMax}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.maxNum']}" />
</f:facet>
<h:outputText value="#{discount.maxNum}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['discount.perUser']}" />
</f:facet>
<h:outputText value="#{discount.perUser}" />
</h:column>
<h:column>
<h:link outcome="/product/editDiscount" value="#{i18n['discount.edit']}">
<f:param name="discountid" value="#{discount.id.id}" />
</h:link>
</h:column>
</h:dataTable>
</h:form>
</composite:implementation> </composite:implementation>
</html> </html>
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
<composite:implementation> <composite:implementation>
<h:form id="discountform"> <h:form id="discountform">
<h:link id="back" outcome="/product/edit" value="#{i18n['product.returnProductEdit']} #{productView.product.name}">
<f:param name="productid" value="#{productView.product.id}" />
</h:link>
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['discount.shortdesc']}:" /> <h:outputLabel value="#{i18n['discount.shortdesc']}:" />
<h:inputText value="#{productView.discount.shortdesc}" /> <h:inputText value="#{productView.discount.shortdesc}" />
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
> >
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.eventorg.list" />
<f:metadata> <f:metadata>
<f:event type="preRenderView" listener="#{productShopView.initView}" /> <f:event type="preRenderView" listener="#{productShopView.initView}" />
</f:metadata> </f:metadata>
......
...@@ -40,6 +40,11 @@ page.product.createBill.pagegroup=shop ...@@ -40,6 +40,11 @@ page.product.createBill.pagegroup=shop
page.product.edit.pagegroup=admin page.product.edit.pagegroup=admin
page.product.list.pagegroup=admin page.product.list.pagegroup=admin
product.providedRole=Tuote tarjoaa roolin
product.createDiscount=Lis mralennus
product.saved=Tuote tallennettu
product.returnProductEdit=Palaa tuotteeseen:
page.role.create.pagegroup=admin page.role.create.pagegroup=admin
......
...@@ -2,8 +2,12 @@ package fi.insomnia.bortal.web.cdiview.shop; ...@@ -2,8 +2,12 @@ package fi.insomnia.bortal.web.cdiview.shop;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named; import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.EventBeanLocal; import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.beans.ProductBeanLocal; import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.enums.apps.ShopPermission; import fi.insomnia.bortal.enums.apps.ShopPermission;
...@@ -27,6 +31,10 @@ public class ProductView extends GenericCDIView { ...@@ -27,6 +31,10 @@ public class ProductView extends GenericCDIView {
private Integer productId; private Integer productId;
private ListDataModel<Discount> productDiscounts;
private static final Logger logger = LoggerFactory.getLogger(ProductView.class);
public void initEditView() { public void initEditView() {
if (super.requirePermissions(ShopPermission.MANAGE_PRODUCTS) && product == null) { if (super.requirePermissions(ShopPermission.MANAGE_PRODUCTS) && product == null) {
product = prodbean.findById(getProductId()); product = prodbean.findById(getProductId());
...@@ -76,4 +84,30 @@ public class ProductView extends GenericCDIView { ...@@ -76,4 +84,30 @@ public class ProductView extends GenericCDIView {
public Discount getDiscount() { public Discount getDiscount() {
return discount; return discount;
} }
public String createDiscount()
{
product = prodbean.mergeChanges(product);
return "/product/edit";
}
public String initCreateDiscount() {
discount = new Discount(product);
product.getDiscounts().add(discount);
return "/product/createDiscount";
}
public String editDiscount()
{
discount = productDiscounts.getRowData();
return "/product/editDiscount";
}
public ListDataModel<Discount> getProductDiscounts()
{
productDiscounts = new ListDataModel<Discount>(product.getDiscounts());
return productDiscounts;
}
} }
package fi.insomnia.bortal.web.cdiview.user; package fi.insomnia.bortal.web.cdiview.user;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import javax.inject.Named; import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.RoleBeanLocal; import fi.insomnia.bortal.beans.RoleBeanLocal;
import fi.insomnia.bortal.model.Role; import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.web.cdiview.GenericCDIView; import fi.insomnia.bortal.web.cdiview.GenericCDIView;
...@@ -20,10 +25,27 @@ public class RoleDataView extends GenericCDIView { ...@@ -20,10 +25,27 @@ public class RoleDataView extends GenericCDIView {
private transient ListDataModel<Role> roles; private transient ListDataModel<Role> roles;
private static final Logger logger = LoggerFactory.getLogger(RoleDataView.class);
public ListDataModel<Role> getRoles() { public ListDataModel<Role> getRoles() {
if (roles == null) { if (roles == null) {
roles = new ListDataModel<Role>(rolebean.listRoles()); roles = new ListDataModel<Role>(rolebean.listRoles());
} }
return roles; return roles;
} }
public Role getNoSelection()
{
return Role.EMPTY_ROLE;
}
public ListDataModel<Role> getRolesWithEmpty() {
if (roles == null) {
List<Role> list = rolebean.listRoles();
list.add(0, Role.EMPTY_ROLE);
roles = new ListDataModel<Role>(list);
logger.info("rolecount {}", roles.getRowCount());
}
return roles;
}
} }
...@@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory; ...@@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.RoleBeanLocal; import fi.insomnia.bortal.beans.RoleBeanLocal;
import fi.insomnia.bortal.model.Role; import fi.insomnia.bortal.model.Role;
@Named @Named("roleConverter")
@RequestScoped @RequestScoped
public class RoleConverter implements Converter { public class RoleConverter implements Converter {
...@@ -25,6 +25,10 @@ public class RoleConverter implements Converter { ...@@ -25,6 +25,10 @@ public class RoleConverter implements Converter {
@Override @Override
public Object getAsObject(FacesContext context, UIComponent component, String value) { public Object getAsObject(FacesContext context, UIComponent component, String value) {
logger.debug("converting string {} to Object", value); logger.debug("converting string {} to Object", value);
if (value == null || value.isEmpty() || value.equals("0"))
{
return null;
}
Role ret = rolebean.find(Integer.parseInt(value)); Role ret = rolebean.find(Integer.parseInt(value));
return ret; return ret;
} }
...@@ -32,11 +36,15 @@ public class RoleConverter implements Converter { ...@@ -32,11 +36,15 @@ public class RoleConverter implements Converter {
@Override @Override
public String getAsString(FacesContext context, UIComponent component, Object value) { public String getAsString(FacesContext context, UIComponent component, Object value) {
String ret = ""; String ret = "";
if (value instanceof Role) { if (value instanceof Role) {
ret = ((Role) value).getId().toString(); Role r = ((Role) value);
if (r.getId() != null)
{
ret = r.getId().toString();
}
} }
logger.debug("converting role {} to string", ret); logger.debug("converting role {} to string", ret);
return ret; return ret;
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!