Commit 1a9af8bc by Antti Tönkyrä

foodwave stuff and fixes

1 parent 7e22d2bb
...@@ -74,7 +74,7 @@ public class FoodWaveBean implements FoodWaveBeanLocal { ...@@ -74,7 +74,7 @@ public class FoodWaveBean implements FoodWaveBeanLocal {
@Override @Override
public FoodWaveTemplate saveTemplate(FoodWaveTemplate waveTemplate) { public FoodWaveTemplate saveTemplate(FoodWaveTemplate waveTemplate) {
throw new UnsupportedOperationException("would you mind to implement this method?"); return fwtFacade.merge(waveTemplate);
} }
...@@ -117,4 +117,14 @@ public class FoodWaveBean implements FoodWaveBeanLocal { ...@@ -117,4 +117,14 @@ public class FoodWaveBean implements FoodWaveBeanLocal {
return template; return template;
} }
@Override
public FoodWaveTemplate removeProductFromTemplate(Product product, FoodWaveTemplate template) {
template = fwtFacade.merge(template);
product = productfacade.merge(product);
template.getProducts().remove(product);
product.getFoodWaveTemplates().remove(template);
return template;
}
} }
...@@ -32,4 +32,6 @@ public interface FoodWaveBeanLocal { ...@@ -32,4 +32,6 @@ public interface FoodWaveBeanLocal {
public void createFoodWave(FoodWave fw); public void createFoodWave(FoodWave fw);
FoodWaveTemplate addProductToTemplate(FoodWaveTemplate template, Product currentProduct); FoodWaveTemplate addProductToTemplate(FoodWaveTemplate template, Product currentProduct);
FoodWaveTemplate removeProductFromTemplate(Product product, FoodWaveTemplate template);
} }
...@@ -38,84 +38,12 @@ ...@@ -38,84 +38,12 @@
requiredMessage="Description required" /> requiredMessage="Description required" />
<h:message for="description" /> <h:message for="description" />
</h:panelGrid> </h:panelGrid>
<!-- </p:tab>
<p:tab id="selectproducts"
title="#{i18n['foodwavetemplate.selectproducts']}"> -->
<h:messages />
<h:panelGrid columns="4">
<h:outputText value="#{i18n['foodwavetemplate.productname']}" />
<h:outputText
value="#{i18n['foodwavetemplate.productdescription']}" />
<h:outputText value="#{i18n['foodwavetemplate.price']}" />
<h:outputText value="&nbsp;" />
<h:inputText id="productname"
value="#{foodWaveView.currentProduct.name}" />
<h:inputText id="productdescription"
value="#{foodWaveView.currentProduct.description}" />
<h:inputText id="price"
value="#{foodWaveView.currentProduct.price}" />
<p:commandButton value="#{i18n['foodwavetemplate.addproduct']}"
actionListener="#{foodWaveView.addProductToTemplate}"
update="productTable" />
</h:panelGrid>
<p:dataTable name="productTable" id="productTable"
value="#{foodWaveView.template.products}" var="product"
editable="true">
<p:column headerText="#{i18n['foodwavetemplate.productname']}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{product.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{product.name}" style="width:100%"
required="true" requiredMessage="Name required" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column
headerText="#{i18n['foodwavetemplate.productdescription']}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{product.description}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{product.description}" style="width:100%"
required="true" requiredMessage="Description required" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{i18n['foodwavetemplate.price']}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{product.price}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{product.price}" style="width:100%"
required="true" requiredMessage="Price required" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{i18n['foodwavetemplate.editRow']}"
style="width:20px">
<p:rowEditor />
</p:column>
<p:column headerText="#{i18n['foodwavetemplate.actions']}"
style="width:20px;">
<p:commandButton
value="#{i18n['foodwavetemplate.removeFromList']}"
action="#{foodWaveView.removeProductFromList(product)}"
update="productTable" />
</p:column>
</p:dataTable>
<h:commandButton action="#{foodWaveView.saveTemplate()}" <h:commandButton action="#{foodWaveView.saveTemplate()}"
value="#{i18n['foodwavetemplate.savetemplate']}"> value="#{i18n['foodwavetemplate.savetemplate']}">
<f:param value="#{foodWaveView.templateId}" name="id" /> <f:param value="#{foodWaveView.templateId}" name="id" />
</h:commandButton>> </h:commandButton>
<!-- </p:tab> --> <!-- </p:tab> -->
<!-- </p:wizard> --> <!-- </p:wizard> -->
......
...@@ -49,7 +49,8 @@ ...@@ -49,7 +49,8 @@
<p:commandButton value="#{i18n['foodwavetemplate.addproduct']}" <p:commandButton value="#{i18n['foodwavetemplate.addproduct']}"
actionListener="#{foodWaveView.addProductToTemplate}" actionListener="#{foodWaveView.addProductToTemplate}"
update="productTable" /> update="productTable" />
<!-- <h:panelGrid columns="4">
<h:panelGrid columns="4">
<h:outputText value="#{i18n['foodwavetemplate.productname']}" /> <h:outputText value="#{i18n['foodwavetemplate.productname']}" />
<h:outputText <h:outputText
...@@ -68,11 +69,14 @@ ...@@ -68,11 +69,14 @@
actionListener="#{foodWaveView.addProductToTemplate}" actionListener="#{foodWaveView.addProductToTemplate}"
update="productTable" /> update="productTable" />
</h:panelGrid> </h:panelGrid>
-->
<p:dataTable name="productTable" id="productTable" <p:dataTable name="productTable" id="productTable"
value="#{foodWaveView.template.products}" var="product" value="#{foodWaveView.template.products}" var="product"
editable="true"> editable="true">
<p:ajax event="rowEdit" listener="#{foodWaveView.onEdit}" />
<p:column headerText="#{i18n['foodwavetemplate.productname']}"> <p:column headerText="#{i18n['foodwavetemplate.productname']}">
<p:cellEditor> <p:cellEditor>
<f:facet name="output"> <f:facet name="output">
......
...@@ -56,6 +56,10 @@ public class FoodWaveView extends GenericCDIView { ...@@ -56,6 +56,10 @@ public class FoodWaveView extends GenericCDIView {
public List<Product> getProducts() { public List<Product> getProducts() {
return productbeanlocal.getProducts(); return productbeanlocal.getProducts();
} }
public void onEdit() {
this.foodWaveBean.saveTemplate(template);
}
public void initTemplateList() { public void initTemplateList() {
super.requirePermissions(ShopPermission.SHOP_FOODWAVE); super.requirePermissions(ShopPermission.SHOP_FOODWAVE);
...@@ -100,6 +104,8 @@ public class FoodWaveView extends GenericCDIView { ...@@ -100,6 +104,8 @@ public class FoodWaveView extends GenericCDIView {
{ {
template = foodWaveBean.findTemplate(templateId); template = foodWaveBean.findTemplate(templateId);
createNewProductSkeleton();
// prepare to make new foodwaves // prepare to make new foodwaves
selectedFoodWave = new FoodWave(); selectedFoodWave = new FoodWave();
selectedFoodWave.setTemplate(template); selectedFoodWave.setTemplate(template);
...@@ -202,8 +208,7 @@ public class FoodWaveView extends GenericCDIView { ...@@ -202,8 +208,7 @@ public class FoodWaveView extends GenericCDIView {
} }
public void removeProductFromList(Product product) { public void removeProductFromList(Product product) {
template = foodWaveBean.removeProductFromTemplate(product, template);
template.getProducts().remove(product);
} }
public Date getStartDate() { public Date getStartDate() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!