details:   /erp/devel/pi/rev/3ee5ff3810a8
changeset: 11463:3ee5ff3810a8
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Mon Apr 04 17:22:15 2011 +0200
summary:   Increase robustness of the FIC in case a callout returns an empty 
combo

details:   /erp/devel/pi/rev/ed872a6860b6
changeset: 11464:ed872a6860b6
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Mon Apr 04 17:27:16 2011 +0200
summary:   Fixed issue 14048. Warehouse combo box will depend on the 
organization

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java
 |  31 ++++++---
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
                  |   5 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-user-profile-widget.js
                             |  21 ++++++-
 3 files changed, 43 insertions(+), 14 deletions(-)

diffs (132 lines):

diff -r e8d667bd5e70 -r ed872a6860b6 
modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java
    Mon Apr 04 16:52:51 2011 +0200
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java
    Mon Apr 04 17:27:16 2011 +0200
@@ -42,6 +42,7 @@
 import org.openbravo.client.kernel.StaticResourceComponent;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
 import org.openbravo.erpCommon.obps.ActivationKey;
@@ -149,6 +150,8 @@
     result.put("language", createLanguageFormItemInfo());
     result.put("initialValues", createInitialValues());
     result.put("role", createRoleInfo(parameters));
+    result.put("warehouseOrgMap",
+        getWarehouses(OBContext.getOBContext().getCurrentClient().getId()));
     return result;
   }
 
@@ -180,24 +183,30 @@
         orgValueMap.put(org.getId(), org.getIdentifier());
       }
       jsonRole.put("organizationValueMap", orgValueMap);
-      jsonRole.put("warehouseValueMap", getWarehouses(orgs, 
role.getClient().getId()));
       jsonRoles.put(jsonRole);
     }
     formItemInfo.put("roles", jsonRoles);
     return formItemInfo;
   }
 
-  private JSONObject getWarehouses(List<Organization> orgs, String clientId) 
throws JSONException {
-    if (orgs.isEmpty()) {
-      return new JSONObject();
+  private JSONArray getWarehouses(String clientId) throws JSONException {
+    List<JSONObject> orgWarehouseArray = new ArrayList<JSONObject>();
+    OBCriteria<Organization> orgs = 
OBDal.getInstance().createCriteria(Organization.class);
+    for (Organization org : orgs.list()) {
+      JSONObject orgWarehouse = new JSONObject();
+      orgWarehouse.put("orgId", org.getId());
+      final OBQuery<Warehouse> warehouses = OBDal
+          .getInstance()
+          .createQuery(Warehouse.class,
+              "ad_isorgincluded(organization.id, :orgId, :clientId)<>-1 and 
client.id=:clientId order by name");
+      warehouses.setNamedParameter("orgId", org.getId());
+      warehouses.setNamedParameter("clientId", clientId);
+      warehouses.setFilterOnReadableClients(false);
+      warehouses.setFilterOnReadableOrganization(false);
+      orgWarehouse.put("warehouseMap", 
createValueMapObject(warehouses.list()));
+      orgWarehouseArray.add(orgWarehouse);
     }
-    final OBQuery<Warehouse> warehouses = 
OBDal.getInstance().createQuery(Warehouse.class,
-        "organization in (:orgs) and client.id=:clientId order by name");
-    warehouses.setNamedParameter("orgs", orgs);
-    warehouses.setNamedParameter("clientId", clientId);
-    warehouses.setFilterOnReadableClients(false);
-    warehouses.setFilterOnReadableOrganization(false);
-    return createValueMapObject(warehouses.list());
+    return new JSONArray(orgWarehouseArray);
   }
 
   private List<Organization> getOrganizations(String roleId) throws 
JSONException {
diff -r e8d667bd5e70 -r ed872a6860b6 
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
     Mon Apr 04 16:52:51 2011 +0200
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
     Mon Apr 04 17:27:16 2011 +0200
@@ -937,13 +937,14 @@
                       ArrayList<JSONObject> comboEntries = new 
ArrayList<JSONObject>();
                       for (int j = 0; j < subelements.getLength(); j++) {
                         NativeArray subelement = (NativeArray) 
subelements.get(j, null);
-                        if (subelement.get(2, null) != null) {
+                        if (subelement != null && subelement.get(2, null) != 
null) {
                           JSONObject entry = new JSONObject();
                           entry.put(JsonConstants.ID, subelement.get(0, null));
                           entry.put(JsonConstants.IDENTIFIER, 
subelement.get(1, null));
                           comboEntries.add(entry);
                           if (j == 0 || subelement.get(2, 
null).toString().equalsIgnoreCase("True")) {
-                            // We always initially select the first element 
returned by the callout,
+                            // We always initially select the first element 
returned by the
+                            // callout,
                             // and after that, we select the one which is 
marke as selected "true"
                             UIDefinition uiDef = 
UIDefinitionController.getInstance()
                                 .getUIDefinition(col.getId());
diff -r e8d667bd5e70 -r ed872a6860b6 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-user-profile-widget.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-user-profile-widget.js
        Mon Apr 04 16:52:51 2011 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-user-profile-widget.js
        Mon Apr 04 17:27:16 2011 +0200
@@ -218,6 +218,11 @@
         roleForm.setValue('role', data.initialValues.role);
         roleForm.setValue('client', data.initialValues.client);
         roleForm.setValueMaps();
+        //First we set initial values, but warehouse will not work
+        //as its combo hasn't yet been filled
+        roleForm.setValues(isc.addProperties({}, data.initialValues));
+        roleForm.setWarehouseValueMap();
+        //We set initial values again to set warehouse correctly
         roleForm.setValues(isc.addProperties({}, data.initialValues));
       },
       // updates the dependent combos
@@ -227,6 +232,9 @@
           if (roleForm.getItem('organization').getClientPickListData().length 
> 0) {
             roleForm.getItem('organization').moveToFirstValue();
           }
+        }
+        this.setWarehouseValueMap();
+        if (item.name === 'role' || item.name === 'organization') {
           if (roleForm.getItem('warehouse').getClientPickListData().length > 
0) {
             roleForm.getItem('warehouse').moveToFirstValue();
           }
@@ -237,12 +245,23 @@
         for (var i = 0; i < roleForm.localFormData.role.roles.length; i++) {
           var role = roleForm.localFormData.role.roles[i];
           if (role.id === roleId) {
-            roleForm.setValueMap('warehouse', role.warehouseValueMap);
             roleForm.setValueMap('organization', role.organizationValueMap);
             roleForm.setValue('client', role.client);
           }
         }
       },
+      setWarehouseValueMap: function() {
+        var orgId = roleForm.getItem('organization').getValue();
+        if (!orgId) {
+          return;
+        }
+        for (var j = 0; j < roleForm.localFormData.warehouseOrgMap.length; 
j++) {
+          var warehouseOrg = roleForm.localFormData.warehouseOrgMap[j];
+          if (warehouseOrg.orgId === orgId) {
+            roleForm.setValueMap('warehouse', warehouseOrg.warehouseMap);
+          }
+        }
+      },
       
       // call the server to save the information
       doSave: function(){

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to