Fixed issue 20870: Admin others works well when adding a widget with params
authorMiguel de Juana <miguel.dejuana@openbravo.com>
Fri, 27 Jul 2012 12:23:55 +0200
changeset 17562 7d6793ea45f1
parent 17561 4f51e963ebbe
child 17563 f119181062af
Fixed issue 20870: Admin others works well when adding a widget with params
In Admin others, it is not supported to add widgets with at least one parameter which is mandatory and DefaultValue==null. If we try to save parameters when we are adding widgets in admin others, the widget have to be in the database to update its parameters, but the widget won't be in database until we press Publish button.
In order to avoid this problem, widgets with parameters are displayed in content_mode and the widget to add list does not show widgets with at least one parameter which is mandatory and DefaultValue==null.
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponent.java
modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-widget.js
modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml
--- a/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponent.java	Fri Jul 27 11:42:07 2012 +0200
+++ b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponent.java	Fri Jul 27 12:23:55 2012 +0200
@@ -36,6 +36,7 @@
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.client.application.ApplicationUtils;
+import org.openbravo.client.application.Parameter;
 import org.openbravo.client.kernel.BaseTemplateComponent;
 import org.openbravo.client.kernel.Template;
 import org.openbravo.dal.core.DalUtil;
@@ -99,6 +100,7 @@
       final List<JSONObject> definitions = new ArrayList<JSONObject>();
       final List<String> tmp = new ArrayList<String>();
       String classDef = "";
+      boolean hasNullMandatory = false;
       final OBQuery<WidgetClass> widgetClassesQry = OBDal.getInstance().createQuery(
           WidgetClass.class, WidgetClass.PROPERTY_SUPERCLASS + " is false");
       for (WidgetClass widgetClass : widgetClassesQry.list()) {
@@ -107,7 +109,18 @@
           if (!widgetProvider.validate()) {
             continue;
           }
-          definitions.add(widgetProvider.getWidgetClassDefinition());
+          for (Parameter p : widgetClass.getOBUIAPPParameterEMObkmoWidgetClassIDList()) {
+            if (p.isMandatory() && p.getDefaultValue() == null) {
+              hasNullMandatory = true;
+              break;
+            }
+          }
+          if (!hasNullMandatory) {
+            definitions.add(widgetProvider.getWidgetClassDefinition());
+          } else {
+            hasNullMandatory = false;
+          }
+
           try {
             classDef = widgetProvider.generate();
             classDef = classDef.substring(0, classDef.length() - 1);
--- a/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-widget.js	Fri Jul 27 11:42:07 2012 +0200
+++ b/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-widget.js	Fri Jul 27 12:23:55 2012 +0200
@@ -467,7 +467,10 @@
     if (isc.isA.emptyObject(this.parameters)) {
       return;
     }
-
+    if (OB.MyOB.adminMode && !this.dbInstanceId) {
+      this.switchMode();
+      return;
+    }
     post = {
       ID: this.ID,
       dbInstanceId: this.dbInstanceId,
@@ -491,7 +494,6 @@
         }
       }
     }
-
     OB.RemoteCallManager.call('org.openbravo.client.application.ParametersActionHandler', post, {}, function (rpcResponse, data, rpcRequest) {
       if (data && data.ID && window[data.ID]) {
         window[data.ID].saveParametersResponseHandler(rpcResponse, data, rpcRequest);
--- a/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml	Fri Jul 27 11:42:07 2012 +0200
+++ b/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml	Fri Jul 27 12:23:55 2012 +0200
@@ -572,6 +572,7 @@
 <!--B9096C5B26D54130B7DD5E6DC2FFCE35-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
 <!--B9096C5B26D54130B7DD5E6DC2FFCE35-->  <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH>
 <!--B9096C5B26D54130B7DD5E6DC2FFCE35-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--B9096C5B26D54130B7DD5E6DC2FFCE35-->  <DEFAULTVALUE><![CDATA[10]]></DEFAULTVALUE>
 <!--B9096C5B26D54130B7DD5E6DC2FFCE35-->  <AD_ELEMENT_ID><![CDATA[9A0C92898CF17AC8E040007F01003160]]></AD_ELEMENT_ID>
 <!--B9096C5B26D54130B7DD5E6DC2FFCE35-->  <ISFIXED><![CDATA[N]]></ISFIXED>
 <!--B9096C5B26D54130B7DD5E6DC2FFCE35-->  <EVALUATEFIXEDVALUE><![CDATA[N]]></EVALUATEFIXEDVALUE>