enhanced getPermOrgList. you can now provide a list of perms and get the consolidate...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 9 Jan 2009 19:04:02 +0000 (19:04 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 9 Jan 2009 19:04:02 +0000 (19:04 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11787 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 1b9fa93..3caba26 100644 (file)
@@ -22,6 +22,7 @@ if(!dojo._hasResource["openils.User"]) {
     dojo.require("DojoSRF");
     dojo.require('openils.Event');
     dojo.require('fieldmapper.Fieldmapper');
+    dojo.require('fieldmapper.OrgUtils');
 
     dojo.declare('openils.User', null, {
 
@@ -175,21 +176,47 @@ if(!dojo._hasResource["openils.User"]) {
 
     
         /**
-         * Returns a list of the "highest" org units where the user
-         * has the given permission.
+         * Returns a list of the "highest" org units where the user has the given permission(s).
+         * @param permList A single permission or list of permissions
+         * @param includeDescendents If true, return a list of 'highest' orgs plus descendents
+         * @idlist If true, return a list of IDs instead of org unit objects
          */
-        getPermOrgList : function(perm, onload) {
+        getPermOrgList : function(permList, onload, includeDescendents, idlist) {
+            if(typeof permList == 'string') permList = [permList];
+
+            var oncomplete = function(r) {
+                var permMap = openils.Util.readResponse(r);
+                var orgList = [];
+                for(var perm in permMap) {
+                    var permOrgList = permMap[perm];
+                    if(includeDescendents) {
+                        for(var i in permOrgList) {
+                            orgList = orgList.concat(
+                                fieldmapper.aou.descendantNodeList(permOrgList[i]));
+                        }
+                    } else {
+                        orgList = orgList.concat(permOrgList);
+                    }
+                }
+                // remove duplicates
+                var trimmed = [];
+                for(var idx in orgList) {
+                    var val = (idlist) ? orgList[idx].id() : orgList[idx];
+                    if(trimmed.indexOf(val) < 0)
+                        trimmed.push(val);
+                }
+                onload(trimmed);
+            };
+
             fieldmapper.standardRequest(
-                ['open-ils.actor', 'open-ils.actor.user.work_perm.highest_org_set'],
+                ['open-ils.actor', 'open-ils.actor.user.work_perm.highest_org_set.batch'],
                 {   async: true,
-                    params: [this.authtoken, perm],
-                    oncomplete: function(r) {
-                        org_list = r.recv().content();
-                        onload(org_list);
-                    }
+                    params: [this.authtoken, permList],
+                    oncomplete: oncomplete
                 }
             );
         },
+
     
         /**
          * Builds a dijit.Tree using the orgs where the user has the requested permission