details: /erp/devel/pi/rev/38523b042486
changeset: 11805:38523b042486
user: Iván Perdomo <ivan.perdomo <at> openbravo.com>
date: Fri Apr 29 12:23:04 2011 +0200
summary: Fixes issue 16492: Added JSEXECUTE command to callouts
- Added the feature JSEXECUTE to execute eval() code in the client
- Added sample callout with a hello world message
diffstat:
modules/org.openbravo.client.application/src/org/openbravo/client/application/example/JSExecuteCalloutExample.java
| 40 ++++++++++
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
| 27 ++++--
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
| 6 +
3 files changed, 64 insertions(+), 9 deletions(-)
diffs (158 lines):
diff -r 86dd7a035971 -r 38523b042486
modules/org.openbravo.client.application/src/org/openbravo/client/application/example/JSExecuteCalloutExample.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/example/JSExecuteCalloutExample.java
Fri Apr 29 12:23:04 2011 +0200
@@ -0,0 +1,40 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.1 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.application.example;
+
+import javax.servlet.ServletException;
+
+import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
+
+/**
+ *
+ * @author iperdomo
+ */
+public class JSExecuteCalloutExample extends SimpleCallout {
+
+ private static final long serialVersionUID = 1L;
+ private static final String JSEXECUTE = "JSEXECUTE";
+
+ @Override
+ protected void execute(CalloutInfo info) throws ServletException {
+ // info.addResult(JSEXECUTE, "debugger;isc.say('hello world');");
+ info.addResult(JSEXECUTE, "isc.say('hello world');");
+ }
+
+}
diff -r 86dd7a035971 -r 38523b042486
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
---
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
Fri Apr 29 12:10:42 2011 +0200
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
Fri Apr 29 12:23:04 2011 +0200
@@ -123,6 +123,7 @@
List<String> changeEventCols = new ArrayList<String>();
Map<String, List<String>> columnsInValidation = new HashMap<String,
List<String>>();
List<String> calloutMessages = new ArrayList<String>();
+ List<String> jsExcuteCode = new ArrayList<String>();
log.debug("Form Initialization Component Execution. Tab Name: " +
tab.getWindow().getName()
+ "." + tab.getName() + " Tab Id:" + tab.getId());
@@ -201,7 +202,7 @@
// Execution of callouts
long t6 = System.currentTimeMillis();
List<String> changedCols = executeCallouts(mode, tab, columnValues,
changedColumn,
- calloutsToCall, lastfieldChanged, calloutMessages, changeEventCols);
+ calloutsToCall, lastfieldChanged, calloutMessages, changeEventCols,
jsExcuteCode);
if (changedCols.size() > 0) {
RequestContext.get().setRequestParameter("donotaddcurrentelement",
"true");
@@ -216,7 +217,7 @@
// Construction of the final JSONObject
long t7 = System.currentTimeMillis();
JSONObject finalObject = buildJSONObject(mode, tab, columnValues, row,
changeEventCols,
- calloutMessages);
+ calloutMessages, jsExcuteCode);
long t8 = System.currentTimeMillis();
log.debug("Elapsed time: " + (System.currentTimeMillis() - iniTime) +
"(" + (t2 - t1) + ","
+ (t3 - t2) + "," + (t4 - t3) + "," + (t5 - t4) + "," + (t6 - t5) +
"," + (t7 - t6) + ","
@@ -237,7 +238,8 @@
}
private JSONObject buildJSONObject(String mode, Tab tab, Map<String,
JSONObject> columnValues,
- BaseOBObject row, List<String> changeEventCols, List<String>
calloutMessages) {
+ BaseOBObject row, List<String> changeEventCols, List<String>
calloutMessages,
+ List<String> jsExcuteCode) {
JSONObject finalObject = new JSONObject();
try {
if (mode.equals("NEW") || mode.equals("CHANGE")) {
@@ -325,7 +327,9 @@
}
}
}
-
+ if (!jsExcuteCode.isEmpty()) {
+ finalObject.put("jscode", new JSONArray(jsExcuteCode));
+ }
log.debug(finalObject.toString(1));
return finalObject;
} catch (JSONException e) {
@@ -833,7 +837,7 @@
private List<String> executeCallouts(String mode, Tab tab, Map<String,
JSONObject> columnValues,
String changedColumn, List<String> calloutsToCall, List<String>
lastfieldChanged,
- List<String> messages, List<String> dynamicCols) {
+ List<String> messages, List<String> dynamicCols, List<String>
jsExecuteCode) {
// In CHANGE mode, we will add the initial callout call for the changed
column, if there is
// one
@@ -855,13 +859,13 @@
return new ArrayList<String>();
}
return runCallouts(columnValues, tab, calledCallouts, calloutsToCall,
lastfieldChanged,
- messages, dynamicCols);
+ messages, dynamicCols, jsExecuteCode);
}
private List<String> runCallouts(Map<String, JSONObject> columnValues, Tab
tab,
List<String> calledCallouts, List<String> calloutsToCall, List<String>
lastfieldChangedList,
- List<String> messages, List<String> dynamicCols) {
+ List<String> messages, List<String> dynamicCols, List<String>
jsExecuteCode) {
// flush&commit to release lock in db which otherwise interfere with
callouts which run in their
// own jdbc connection (i.e. lock on AD_Sequence when using with Sales
Invoice window)
@@ -938,6 +942,12 @@
if (name.equals("MESSAGE")) {
log.debug("Callout message: " + element.get(1, null));
messages.add(element.get(1, null).toString());
+ } else if (name.equals("JSEXECUTE")) {
+ // The code on a JSEXECUTE command is sent directly to the
client for eval()
+ String code = (String) element.get(1, null);
+ if (code != null) {
+ jsExecuteCode.add(code);
+ }
} else if (name.equals("EXECUTE")) {
String js = element.get(1, null) == null ? null :
element.get(1, null).toString();
if (js != null && !js.equals("")) {
@@ -1025,8 +1035,7 @@
rq.setRequestParameter(colId,
jsonobj.getString("classicValue"));
}
} else {
- log
- .debug("Column value didn't change. We do not
attempt to execute any additional callout");
+ log.debug("Column value didn't change. We do not
attempt to execute any additional callout");
}
}
if (changed && col.getCallout() != null) {
diff -r 86dd7a035971 -r 38523b042486
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
---
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
Fri Apr 29 12:10:42 2011 +0200
+++
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
Fri Apr 29 12:23:04 2011 +0200
@@ -588,6 +588,12 @@
OB.Utilities.callAction(editValues.actionAfterFicReturn);
delete editValues.actionAfterFicReturn;
}
+
+ if(data.jscode) {
+ for(i = 0; i < data.jscode.length; i++) {
+ eval(data.jscode[i]);
+ }
+ }
},
setDisabled: function(state) {
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits