adding Davids org perm store caching with some slight modification. using existing...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 29 May 2008 22:23:31 +0000 (22:23 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 29 May 2008 22:23:31 +0000 (22:23 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@9730 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/User.js

index 4157e87..cb04539 100644 (file)
@@ -42,6 +42,7 @@ if(!dojo._hasResource["openils.User"]) {
             this.login_type = kwargs.login_type;
             this.location = kwargs.location;
             this.authcookie = kwargs.authcookie || openils.User.authcookie;
+            this.permOrgStoreCache = {}; /* permName => permOrgUnitStore map */
 
             if (this.id && this.authtoken) this.user = this.getById( this.id );
             else if (this.authtoken) this.getBySession();
@@ -169,17 +170,16 @@ if(!dojo._hasResource["openils.User"]) {
          * has the given permission.
          */
         getPermOrgList : function(perm, onload) {
-    
-            var req = OpenSRF.CachedClientSession('open-ils.actor').request(
-                'open-ils.actor.user.work_perm.highest_org_set',
-                this.authtoken, perm);
-    
-            req.oncomplete = function(r) {
-                org_list = r.recv().content();
-                onload(org_list);
-            }
-    
-            req.send();
+            fieldmapper.standardRequest(
+                ['open-ils.actor', 'open-ils.actor.user.work_perm.highest_org_set'],
+                {   async: true,
+                    params: [this.authtoken, perm],
+                    oncomplete: function(r) {
+                        org_list = r.recv().content();
+                        onload(org_list);
+                    }
+                }
+            );
         },
     
         /**
@@ -229,29 +229,28 @@ if(!dojo._hasResource["openils.User"]) {
     
             dojo.require('dojo.data.ItemFileReadStore');
 
-            function buildTreePicker(r) {
-                var orgList = r.recv().content();
-                var orgNodeList = [];
+            function hookupStore(store) {
+                selector.store = store;
+                selector.startup();
+                selector.setValue(_u.user.ws_ou());
+            }
 
+            function buildTreePicker(orgList) {
+                var orgNodeList = [];
                 for(var i = 0; i < orgList.length; i++) 
                     orgNodeList = orgNodeList.concat(
                         fieldmapper.aou.descendantNodeList(orgList[i]));
 
                 var store = new dojo.data.ItemFileReadStore({data:aou.toStoreData(orgNodeList)});
-                selector.store = store;
-                selector.startup();
-                selector.setValue(_u.user.ws_ou());
+                hookupStore(store);
+                _u.permOrgStoreCache[perm] = store;
             }
     
-            fieldmapper.standardRequest(
-                ['open-ils.actor', 'open-ils.actor.user.work_perm.highest_org_set'],
-                {   params: [this.authtoken, perm],
-                    oncomplete: buildTreePicker,
-                    async: true
-                }
-            )
+               if (_u.permOrgStoreCache[perm])
+                       hookupStore(_u.permOrgStoreCache[perm]);
+               else
+                _u.getPermOrgList(perm, buildTreePicker);
         }
-
     });
 
        openils.User.user = null;