From 61a018f5f5faf6ab0d1e88f3c17cefc6f9f0c00d Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 30 Dec 2008 07:51:23 +0000 Subject: [PATCH] [ 2165298 ] Calculator manage different decimal point than numeric field --- .../adempiere/webui/component/NumberBox.java | 13 +++++++++---- .../adempiere/webui/editor/WNumberEditor.java | 3 ++- .../webui/session/SessionContextListener.java | 8 ++++++++ zkwebui/js/calc.js | 19 +++++++++++++++---- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java index a28c327402..844d8986c5 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java @@ -23,6 +23,8 @@ import java.text.ParseException; import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; import org.zkoss.zhtml.Table; import org.zkoss.zhtml.Td; import org.zkoss.zhtml.Tr; @@ -191,10 +193,12 @@ public class NumberBox extends Div Vbox vbox = new Vbox(); + char separatorChar = DisplayType.getNumberFormat(DisplayType.Number, Env.getLanguage(Env.getCtx())).getDecimalFormatSymbols().getDecimalSeparator(); + txtCalc = new Textbox(); txtCalc.setAction("onKeyPress : return calc.validate('" + decimalBox.getId() + "','" + txtCalc.getId() - + "'," + integral + ", event);"); + + "'," + integral + "," + (int)separatorChar + ", event);"); txtCalc.setMaxlength(250); txtCalc.setCols(30); @@ -312,17 +316,18 @@ public class NumberBox extends Div btn0.setLabel("0"); btn0.setAction("onClick : calc.append('" + txtCalcId + "', '0')"); + String separator = Character.toString(separatorChar); Button btnDot = new Button(); btnDot.setWidth("30px"); - btnDot.setLabel("."); + btnDot.setLabel(separator); btnDot.setDisabled(integral); - btnDot.setAction("onClick : calc.append('" + txtCalcId + "', '.')"); + btnDot.setAction("onClick : calc.append('" + txtCalcId + "', '" + separator + "')"); Button btnEqual = new Button(); btnEqual.setWidth("30px"); btnEqual.setLabel("="); btnEqual.setAction("onClick : calc.evaluate('" + decimalBox.getId() + "','" - + txtCalcId + "')"); + + txtCalcId + "','" + separator + "')"); Button btnAdd = new Button(); btnAdd.setWidth("30px"); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java index f55c22db78..6106a9c8ae 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java @@ -27,6 +27,7 @@ import org.adempiere.webui.event.ValueChangeEvent; import org.compiere.model.GridField; import org.compiere.model.MRole; import org.compiere.util.DisplayType; +import org.compiere.util.Env; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; @@ -106,7 +107,7 @@ public class WNumberEditor extends WEditor if (!DisplayType.isNumeric(displayType)) displayType = DisplayType.Number; - DecimalFormat format = DisplayType.getNumberFormat(displayType); + DecimalFormat format = DisplayType.getNumberFormat(displayType, Env.getLanguage(Env.getCtx())); getComponent().getDecimalbox().setFormat(format.toPattern()); } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java b/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java index 2929e1236e..646a59cfd1 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java @@ -19,6 +19,8 @@ package org.adempiere.webui.session; import java.util.List; +import org.compiere.util.Env; +import org.zkoss.util.Locales; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Executions; @@ -54,6 +56,9 @@ public class SessionContextListener implements ExecutionInit, ServerContext.setCurrentInstance(ctx); } exec.setAttribute(SESSION_CTX, ctx); + + //set locale + Locales.setThreadLocal(Env.getLanguage(ctx).getLocale()); } } @@ -76,6 +81,9 @@ public class SessionContextListener implements ExecutionInit, SESSION_CTX); ServerContext.setCurrentInstance(ctx); + // set locale + Locales.setThreadLocal(Env.getLanguage(ctx).getLocale()); + return true; } diff --git a/zkwebui/js/calc.js b/zkwebui/js/calc.js index c14ce3cfb5..a1cb8cc2bd 100644 --- a/zkwebui/js/calc.js +++ b/zkwebui/js/calc.js @@ -7,7 +7,7 @@ function Calc() this.evaluate = evaluate; this.append = append; - function validate(displayTextId, calcTextId, integral, e) + function validate(displayTextId, calcTextId, integral, separatorKey, e) { var key; @@ -45,7 +45,7 @@ function Calc() { return true; } - else if ( key == 46 && !integral) + else if ( key == separatorKey && !integral) { return true; } @@ -85,12 +85,23 @@ function Calc() } - function evaluate(displayTextId, calcTextId) + function evaluate(displayTextId, calcTextId, separator) { try { var calcText = document.getElementById(calcTextId); - calcText.value = eval(calcText.value); + var value = calcText.value; + if (separator != '.') + { + var re = new RegExp("[" + separator + "]"); + value = value.replace(re,'.'); + } + var result = "" + eval(value); + if (separator != '.') + { + result = result.replace(/\./, separator); + } + calcText.value = result; var displayText = document.getElementById(displayTextId);