|
From: <sim...@us...> - 2007-05-14 21:54:50
|
Revision: 292
http://svn.sourceforge.net/zkforge/?rev=292&view=rev
Author: simon_massey
Date: 2007-05-14 14:53:46 -0700 (Mon, 14 May 2007)
Log Message:
-----------
added validation to the Add Menu Item button.
Modified Paths:
--------------
trunk/foodToGo/src/main/webapp/zul/add-menu-item.zul
trunk/foodToGo/src/main/webapp/zul/index.zul
Modified: trunk/foodToGo/src/main/webapp/zul/add-menu-item.zul
===================================================================
--- trunk/foodToGo/src/main/webapp/zul/add-menu-item.zul 2007-05-14 21:20:39 UTC (rev 291)
+++ trunk/foodToGo/src/main/webapp/zul/add-menu-item.zul 2007-05-14 21:53:46 UTC (rev 292)
@@ -20,22 +20,43 @@
<zscript>
<![CDATA[
doAdd(String name, java.math.BigDecimal price){
- // locate the save button on the main page where the restaurant is stored
- saveRestaurantButton = Path.getComponent("//main-page/main-window/saveRestaurantButton");
- restaurant = saveRestaurantButton.getAttribute("restaurant", Component.DESKTOP_SCOPE);
- // create the new menu item and add it to the restaurant
- menuItem = new net.chrisrichardson.foodToGo.domain.MenuItem();
- menuItem.price = price.doubleValue();
- menuItem.name = name;
- restaurant.menuItems.add(menuItem);
-
- // reload the include that renders the menu items. use a timestamp to skip the page cache
- menuItemInclude = Path.getComponent("//main-page/main-window/menuItemInclude");
- menuItemInclude.setSrc("./menu-items.zul?restaurantId="+(new java.util.Date()).getTime());
+ if( name != "" && price != null ) {
+ // locate the save button on the main page where the restaurant is stored
+ saveRestaurantButton = Path.getComponent("//main-page/main-window/saveRestaurantButton");
+ restaurant = saveRestaurantButton.getAttribute("restaurant", Component.DESKTOP_SCOPE);
+
+ // create the new menu item and add it to the restaurant
+ menuItem = new net.chrisrichardson.foodToGo.domain.MenuItem();
+ menuItem.price = price.doubleValue();
+ menuItem.name = name;
+ restaurant.menuItems.add(menuItem);
+
+ // reload the include that renders the menu items. use a timestamp to skip the page cache
+ menuItemInclude = Path.getComponent("//main-page/main-window/menuItemInclude");
+ menuItemInclude.setSrc("./menu-items.zul?restaurantId="+(new java.util.Date()).getTime());
+
+ win.detach();
+ }
}
]]>
</zscript>
- <vbox>Name:<textbox id="name" value=""/> Price:<decimalbox id="price" format="#,##0.##"/></vbox>
- <button label="Add" onClick="doAdd(name.value,price.value);win.detach()"/> <button label="Cancel" onClick="win.detach()"/>
+ <vbox>
+ <label id="nameLabel" value="Name:"/><textbox id="name" value="" constraint="no empty"/>
+ <label id="priceLabel" value="Price:"/><decimalbox id="price" format="#,##0.##" constraint="no zero, no empty"/></vbox>
+ <button label="Add">
+ <attribute name="onClick"><![CDATA[
+ if( !price.isValid() ) {
+ // not sure why the no zero, no empty constraint is not working so set the label red....
+ priceLabel.style = "color: red";
+ } else {
+ priceLabel.style = "color: black";
+ }
+
+ if( name.isValid() && price.isValid() ) {
+ doAdd(name.value,price.value);
+ }
+ ]]></attribute>
+ </button>
+ <button label="Cancel" onClick="win.detach()"/>
</window>
\ No newline at end of file
Modified: trunk/foodToGo/src/main/webapp/zul/index.zul
===================================================================
--- trunk/foodToGo/src/main/webapp/zul/index.zul 2007-05-14 21:20:39 UTC (rev 291)
+++ trunk/foodToGo/src/main/webapp/zul/index.zul 2007-05-14 21:53:46 UTC (rev 292)
@@ -142,9 +142,14 @@
<button label="Add Menu Item">
<attribute name="onClick">
<![CDATA[
- Window win = (Window) Executions.createComponents(
- "add-menu-item.zul", null, null);
- win.doModal();
+ restaurant = saveRestaurantButton.getAttribute("restaurant", Component.DESKTOP_SCOPE);
+ if( null != restaurant ) {
+ Window win = (Window) Executions.createComponents(
+ "add-menu-item.zul", null, null);
+ win.doModal();
+ } else {
+ alert("Please select a restaurant.");
+ }
]]>
</attribute>
</button>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|