From bcf0b47bc7a1b42db4c9ab934fa4d8e301f52371 Mon Sep 17 00:00:00 2001 From: Elaine Tan Date: Tue, 4 Sep 2012 17:27:04 +0800 Subject: [PATCH] IDEMPIERE-413 zk6: Calculator not working --- .../adempiere/webui/component/NumberBox.java | 22 +++++++++++++++---- org.adempiere.ui.zk/js/calc.js | 17 +++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java index c0220ca175..0664540961 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java @@ -22,12 +22,12 @@ import java.text.NumberFormat; 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; +import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Decimalbox; @@ -106,10 +106,10 @@ public class NumberBox extends Div btnColumn.appendChild(btn); popup = getCalculatorPopup(); + appendChild(popup); LayoutUtils.addSclass("editor-button", btn); btn.setPopup(popup); - btn.setStyle("text-align: center;"); - appendChild(popup); + btn.setStyle("text-align: center;"); LayoutUtils.addSclass(".number-box", this); } @@ -190,13 +190,27 @@ public class NumberBox extends Div private Popup getCalculatorPopup() { - Popup popup = new Popup(); + Popup popup = new Popup() { + @Override + public void onPageAttached(Page newpage, Page oldpage) { + super.onPageAttached(newpage, oldpage); + if (newpage != null) { + if (btn.getPopup() != null) { + btn.setPopup(this); + } + } + } + }; Vbox vbox = new Vbox(); char separatorChar = DisplayType.getNumberFormat(DisplayType.Number, Env.getLanguage(Env.getCtx())).getDecimalFormatSymbols().getDecimalSeparator(); txtCalc = new Textbox(); + + decimalBox.setId(decimalBox.getUuid()); + txtCalc.setId(txtCalc.getUuid()); + txtCalc.setWidgetListener("onKeyPress", "return calc.validate('" + decimalBox.getId() + "','" + txtCalc.getId() + "'," + integral + "," + (int)separatorChar + ", event);"); diff --git a/org.adempiere.ui.zk/js/calc.js b/org.adempiere.ui.zk/js/calc.js index ad9a5072c4..9f10380124 100644 --- a/org.adempiere.ui.zk/js/calc.js +++ b/org.adempiere.ui.zk/js/calc.js @@ -59,7 +59,8 @@ function Calc() { try { - var calcText = document.getElementById(calcTextId); + var id = "$".concat(calcTextId); + var calcText = jq(id)[0]; calcText.value = ""; } catch (err) @@ -71,7 +72,8 @@ function Calc() { try { - var calcText = document.getElementById(calcTextId); + var id = "$".concat(calcTextId); + var calcText = jq(id)[0]; var val = calcText.value; if (val != "") { @@ -89,7 +91,8 @@ function Calc() { try { - var calcText = document.getElementById(calcTextId); + var id = "$".concat(calcTextId); + var calcText = jq(id)[0]; var value = calcText.value; if (separator != '.') { @@ -103,12 +106,13 @@ function Calc() } calcText.value = result; - var displayText = document.getElementById(displayTextId); + id = "$".concat(displayTextId); + var displayText = jq(id)[0]; if (!displayText.readOnly && calcText.value != 'undefined') { displayText.value = calcText.value; - setTimeout("document.getElementById('" + displayTextId + "').focus()", 100); + setTimeout("jq('$" + displayTextId + "')[0].focus()", 100); } } catch (err) @@ -118,7 +122,8 @@ function Calc() function append(calcTextId, val) { - var calcText = document.getElementById(calcTextId); + var id = "$".concat(calcTextId); + var calcText = jq(id)[0]; calcText.value += val; } }