Commit 1a9af8bc by Antti Tönkyrä

foodwave stuff and fixes

1 parent 7e22d2bb
......@@ -74,7 +74,7 @@ public class FoodWaveBean implements FoodWaveBeanLocal {
@Override
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 {
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 {
public void createFoodWave(FoodWave fw);
FoodWaveTemplate addProductToTemplate(FoodWaveTemplate template, Product currentProduct);
FoodWaveTemplate removeProductFromTemplate(Product product, FoodWaveTemplate template);
}
......@@ -38,84 +38,12 @@
requiredMessage="Description required" />
<h:message for="description" />
</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()}"
value="#{i18n['foodwavetemplate.savetemplate']}">
<f:param value="#{foodWaveView.templateId}" name="id" />
</h:commandButton>>
</h:commandButton>
<!-- </p:tab> -->
<!-- </p:wizard> -->
......
......@@ -49,7 +49,8 @@
<p:commandButton value="#{i18n['foodwavetemplate.addproduct']}"
actionListener="#{foodWaveView.addProductToTemplate}"
update="productTable" />
<!-- <h:panelGrid columns="4">
<h:panelGrid columns="4">
<h:outputText value="#{i18n['foodwavetemplate.productname']}" />
<h:outputText
......@@ -68,11 +69,14 @@
actionListener="#{foodWaveView.addProductToTemplate}"
update="productTable" />
</h:panelGrid>
-->
</h:panelGrid>
<p:dataTable name="productTable" id="productTable"
value="#{foodWaveView.template.products}" var="product"
editable="true">
<p:ajax event="rowEdit" listener="#{foodWaveView.onEdit}" />
<p:column headerText="#{i18n['foodwavetemplate.productname']}">
<p:cellEditor>
<f:facet name="output">
......
......@@ -56,6 +56,10 @@ public class FoodWaveView extends GenericCDIView {
public List<Product> getProducts() {
return productbeanlocal.getProducts();
}
public void onEdit() {
this.foodWaveBean.saveTemplate(template);
}
public void initTemplateList() {
super.requirePermissions(ShopPermission.SHOP_FOODWAVE);
......@@ -100,6 +104,8 @@ public class FoodWaveView extends GenericCDIView {
{
template = foodWaveBean.findTemplate(templateId);
createNewProductSkeleton();
// prepare to make new foodwaves
selectedFoodWave = new FoodWave();
selectedFoodWave.setTemplate(template);
......@@ -202,8 +208,7 @@ public class FoodWaveView extends GenericCDIView {
}
public void removeProductFromList(Product product) {
template.getProducts().remove(product);
template = foodWaveBean.removeProductFromTemplate(product, template);
}
public Date getStartDate() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!