Author: eckardjf
Date: Fri Jul 24 15:34:02 2009 New Revision: 797535 URL: http://svn.apache.org/viewvc?rev=797535&view=rev Log: refactor of addOrderTerm / removeOrderTerm events and associated web artifacts to work as intended; now sets termValue and termDays parameters Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy ofbiz/trunk/applications/order/webapp/ordermgr/entry/orderterms.ftl Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=797535&r1=797534&r2=797535&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Fri Jul 24 15:34:02 2009 @@ -1168,75 +1168,77 @@ return "success"; } - /** Add order term **/ + /** + * Add an order term * + */ public static String addOrderTerm(HttpServletRequest request, HttpServletResponse response) { - GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); - LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + ShoppingCart cart = getCartObject(request); - ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart); + Locale locale = UtilHttp.getLocale(request); + String termTypeId = request.getParameter("termTypeId"); String termValueStr = request.getParameter("termValue"); String termDaysStr = request.getParameter("termDays"); - String termIndex = request.getParameter("termIndex"); String textValue = request.getParameter("textValue"); - Locale locale = UtilHttp.getLocale(request); + BigDecimal termValue = null; Long termDays = null; - Boolean checkTermValueAndDays = true; - if (termValueStr.trim().equals("")) { - termValue = null; - checkTermValueAndDays = false; - } - if (termDaysStr.trim().equals("")) { - termDays = null; - checkTermValueAndDays = false; - } if (UtilValidate.isEmpty(termTypeId)) { - request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderOrderTermTypeIsRequired", locale)); - return "error"; - } - if (!UtilValidate.isSignedDouble(termValueStr)) { - request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderOrderTermValueError", UtilMisc.toMap("orderTermValue",UtilValidate.isSignedFloatMsg), locale)); + request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); return "error"; } - if (checkTermValueAndDays) { - termValue = new BigDecimal(termValueStr); - } - if (!UtilValidate.isInteger(termDaysStr)) { - request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays",UtilValidate.isLongMsg), locale)); - return "error"; - } - if (checkTermValueAndDays) { - termDays = Long.valueOf(termDaysStr); - } - if ((termIndex != null) && (!"-1".equals(termIndex)) && (UtilValidate.isInteger(termIndex))) { - cartHelper.removeOrderTerm(Integer.parseInt(termIndex)); + + if (UtilValidate.isNotEmpty(termValueStr)) { + try { + termValue = new BigDecimal(termValueStr); + } catch (NumberFormatException e) { + request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); + return "error"; + } } - Map result = cartHelper.addOrderTerm(termTypeId, termValue, termDays, textValue); - if (ServiceUtil.isError(result)) { - request.setAttribute("_ERROR_MESSAGE_", ServiceUtil.getErrorMessage(result)); - return "error"; + if (UtilValidate.isNotEmpty(termDaysStr)) { + try { + termDays = Long.valueOf(termDaysStr); + } catch (NumberFormatException e) { + request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); + return "error"; + } } + + removeOrderTerm(request, response); + + cart.addOrderTerm(termTypeId, termValue, termDays, textValue); + return "success"; } - /** Add order term **/ - public static String removeOrderTerm(HttpServletRequest request, HttpServletResponse response) { - GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); - LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - ShoppingCart cart = getCartObject(request); - ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart); - String index = request.getParameter("termIndex"); - Map result = cartHelper.removeOrderTerm(Integer.parseInt(index)); - if (ServiceUtil.isError(result)) { - request.setAttribute("_ERROR_MESSAGE_", ServiceUtil.getErrorMessage(result)); - return "error"; - } - return "success"; - } + /** + * Remove an order term * + */ + public static String removeOrderTerm(HttpServletRequest request, HttpServletResponse response) { + + ShoppingCart cart = getCartObject(request); + + String termIndexStr = request.getParameter("termIndex"); + if (UtilValidate.isNotEmpty(termIndexStr)) { + try { + Integer termIndex = Integer.parseInt(termIndexStr); + if (termIndex >= 0) { + List orderTerms = cart.getOrderTerms(); + if (orderTerms != null && orderTerms.size() > termIndex) { + cart.removeOrderTerm(termIndex); + } + } + } catch (NumberFormatException e) { + Debug.logWarning(e, "Error parsing termIndex: " + termIndexStr, module); + } + } + + return "success"; + } /** Initialize order entry from a shopping list **/ public static String loadCartFromShoppingList(HttpServletRequest request, HttpServletResponse response) { Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy?rev=797535&r1=797534&r2=797535&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy Fri Jul 24 15:34:02 2009 @@ -17,30 +17,39 @@ * under the License. */ -import org.ofbiz.entity.*; import org.ofbiz.base.util.*; +import org.ofbiz.entity.*; import org.ofbiz.order.shoppingcart.*; -import org.ofbiz.party.contact.*; -import org.ofbiz.product.catalog.*; -cart = session.getAttribute("shoppingCart"); + +cart = ShoppingCartEvents.getCartObject(request); context.cart = cart; orderTerms = cart.getOrderTerms(); context.orderTerms = orderTerms; -termTypes = delegator.findList("TermType", null, null, null, null,false); -context.termTypes = termTypes; -createNew = request.getParameter("createNew"); - -termIndex = request.getParameter("termIndex"); -if ("Y".equals(createNew) && (!"-1".equals(termIndex))) { - context.termIndex = termIndex; - orderTerm = orderTerms[Integer.parseInt(termIndex)]; - if (orderTerm) { - context.termTypeId = orderTerm.termTypeId; - context.termValue = orderTerm.termValue; - context.termDays = orderTerm.termDays; - context.textValue = orderTerm.textValue; +if (request.getParameter('createNew') == 'Y') { + + termIndexStr = request.getParameter('termIndex'); + if (termIndexStr) { + try { + termIndex = Integer.parseInt(termIndexStr); + + orderTerm = orderTerms[termIndex]; + if (orderTerm) { + context.termTypeId = orderTerm.termTypeId; + context.termValue = orderTerm.termValue; + context.termDays = orderTerm.termDays; + context.textValue = orderTerm.textValue; + + context.termIndex = termIndexStr; + } + + } catch (NumberFormatException nfe) { + Debug.log("Error parsing termIndex: ${termIndexStr}"); + } } + } + +context.termTypes = delegator.findList('TermType', null, null, null, null, false); Modified: ofbiz/trunk/applications/order/webapp/ordermgr/entry/orderterms.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/entry/orderterms.ftl?rev=797535&r1=797534&r2=797535&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/entry/orderterms.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/entry/orderterms.ftl Fri Jul 24 15:34:02 2009 @@ -17,114 +17,99 @@ under the License. --> -<table border="0" width="100%" cellspacing='0' cellpadding='0' class='boxoutside'> - <tr> - <td width="100%"> - <table width='100%' border='0' cellspacing='0' cellpadding='0' class='boxbottom'> - <tr> - <td> - <#if orderTerms?has_content && !requestParameters.createNew?exists> - <form method="post" action="<@ofbizUrl>finalizeOrder</@ofbizUrl>" name="checkoutsetupform"> - <input type="hidden" name="finalizeMode" value="term"/> - <table width="100%" border="0" cellpadding="1" cellspacing="0"> - <tr> - <td colspan="5"> - <a href="<@ofbizUrl>setOrderTerm?createNew=Y</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonCreateNew}</a> - </td> - </tr> - <tr> - <td><div><b>${uiLabelMap.OrderOrderTermType}</b></div></td> - <td><div><b>${uiLabelMap.OrderOrderTermValue}</b></div></td> - <td><div><b>${uiLabelMap.OrderOrderTermDays}</b></div></td> - <td><div><b>${uiLabelMap.CommonDescription}</b></div></td> - <td align="right"> </td> - </tr> - <tr><td colspan="5"><hr/></td></tr> - <#assign index=0> - <#list orderTerms as orderTerm> - <tr> - <td><div>${orderTerm.getRelatedOne("TermType").get("description",locale)}</div></td> - <td><div>${orderTerm.termValue?default("")}</div></td> - <td><div>${orderTerm.termDays?default("")}</div></td> - <td><div>${orderTerm.textValue?default("")}</div></td> - <td align="right"> - <a href="<@ofbizUrl>setOrderTerm?termIndex=${index}&createNew=Y</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonUpdate}</a> - - <a href="<@ofbizUrl>removeCartOrderTerm?termIndex=${index}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonRemove}</a> - </td> - </tr> - <#if orderTerms.size()<index > - <tr><td colspan="5"><hr/></td></tr> - </#if> - <#assign index=index+1> - </#list> - </table> - </form> - </td> - </tr> - </table> - <#else> - <#if !orderTerms?has_content || requestParameters.createNew?exists> - <form method="post" action="<@ofbizUrl>finalizeOrder</@ofbizUrl>" name="checkoutsetupform"> - <input type="hidden" name="finalizeMode" value="term"/> - </form> - <form method="post" action="<@ofbizUrl>addOrderTerm</@ofbizUrl>" name="termform"> - <input type="hidden" name="partyId" value="${cart.partyId?default("_NA_")}"/> - <input type="hidden" name="finalizeMode" value="term"/> - <input type="hidden" name="termIndex" value="${termIndex?default(-1)}"/> - <table width="100%" border="0" cellpadding="1" cellspacing="0"> - <tr> - <td width="26%" align="right" valign="top"> - <div>${uiLabelMap.OrderOrderTermType}</div> - </td> - <td width="5"> </td> - <td width="74%"> - <select name="termTypeId"> - <#if termTypes?has_content> - <option value=""/> - <#list termTypes as termType> - <option value="${termType.termTypeId}" <#if termTypeId?default("")==termType.termTypeId> selected</#if>>${termType.get("description",locale)}</option> - </#list> - </#if> - </select> - </td> - </tr> - <tr> - <td width="26%" align="right" valign="top"> - <div>${uiLabelMap.OrderOrderTermValue}</div> - </td> - <td width="5"> </td> - <td width="74%"> - <input type="text" size="30" maxlength="60" name="termValue" value="${termValue?if_exists}"/> - </td> - </tr> - <tr> - <td width="26%" align="right" valign="top"> - <div>${uiLabelMap.OrderOrderTermDays}</div> - </td> - <td width="5"> </td> - <td width="74%"> - <input type="text" size="30" maxlength="60" name="termDays" value="${termDays?if_exists}"/> - </td> - </tr> - <tr> - <td width="26%" align="right" valign="top"> - <div>${uiLabelMap.CommonDescription}</div> - </td> - <td width="5"> </td> - <td width="74%"> - <input type="text" size="30" maxlength="255" name="textValue" value="${textValue?if_exists}"/> - </td> - </tr> - <tr><td colspan="3" align="middle"><input type="submit" class="smallSubmit" value="${uiLabelMap.CommonAdd}"/></td></tr> - </table> - </form> - </#if> - </td> - </tr> - </table> - </#if> - </td> - </tr> +<table border="0" width="100%" cellspacing="0" cellpadding="0" class="boxoutside"> + <tr> + <td width="100%"> + <table width="100%" border="0" cellspacing="0" cellpadding="0" class="boxbottom"> + <tr> + <td> + <#if orderTerms?has_content && parameters.createNew?default('') != 'Y'> + <table class="basic-table hover-bar"> + <tr class="header-row"> + <td>${uiLabelMap.OrderOrderTermType}</td> + <td align="center">${uiLabelMap.OrderOrderTermValue}</td> + <td align="center">${uiLabelMap.OrderOrderTermDays}</td> + <td>${uiLabelMap.CommonDescription}</td> + <td> </td> + </tr> + <#list orderTerms as orderTerm> + <tr <#if orderTerm_index % 2 != 0>class="alternate-row"</#if> > + <td nowrap="nowrap">${orderTerm.getRelatedOne('TermType').get('description', locale)}</td> + <td align="center">${orderTerm.termValue?if_exists}</td> + <td align="center">${orderTerm.termDays?if_exists}</td> + <td nowrap="nowrap">${orderTerm.textValue?if_exists}</td> + <td align="right"> + <a href="<@ofbizUrl>setOrderTerm?termIndex=${orderTerm_index}&createNew=Y</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonUpdate}</a> + <a href="<@ofbizUrl>removeCartOrderTerm?termIndex=${orderTerm_index}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonRemove}</a> + </td> + </tr> + </#list> + <tr> + <td colspan="5"> + <a href="<@ofbizUrl>setOrderTerm?createNew=Y</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonCreateNew}</a> + </td> + </tr> + </table> + <#else> + <form method="post" action="<@ofbizUrl>addOrderTerm</@ofbizUrl>" name="termform"> + <input type="hidden" name="termIndex" value="${termIndex?if_exists}" /> + <table class="basic-table"> + <tr> + <td width="26%" align="right" valign="top"> + ${uiLabelMap.OrderOrderTermType} + </td> + <td width="5"> </td> + <td width="74%"> + <select name="termTypeId"> + <option value=""></option> + <#list termTypes?if_exists as termType> + <option value="${termType.termTypeId}" + <#if termTypeId?default('') == termType.termTypeId>selected="selected"</#if> + >${termType.get('description', locale)}</option> + </#list> + </select> + </td> + </tr> + <tr> + <td width="26%" align="right" valign="top"> + ${uiLabelMap.OrderOrderTermValue} + </td> + <td width="5"> </td> + <td width="74%"> + <input type="text" size="30" maxlength="60" name="termValue" value="${termValue?if_exists}" /> + </td> + </tr> + <tr> + <td width="26%" align="right" valign="top"> + ${uiLabelMap.OrderOrderTermDays} + </td> + <td width="5"> </td> + <td width="74%"> + <input type="text" size="30" maxlength="60" name="termDays" value="${termDays?if_exists}" /> + </td> + </tr> + <tr> + <td width="26%" align="right" valign="top"> + ${uiLabelMap.CommonDescription} + </td> + <td width="5"> </td> + <td width="74%"> + <input type="text" size="30" maxlength="255" name="textValue" value="${textValue?if_exists}" /> + </td> + </tr> + <tr> + <td width="26%" align="right" valign="top"> </td> + <td width="5"> </td> + <td width="74%"> + <input type="submit" class="smallSubmit" value="${uiLabelMap.CommonAdd}" /> + </td> + </tr> + </table> + </form> + </#if> + </td> + </tr> + </table> + </td> + </tr> </table> -<br/> |
Free forum by Nabble | Edit this page |