[open-ils-commits] r11787 - trunk/Open-ILS/web/js/dojo/openils
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jan 9 14:04:05 EST 2009
Author: erickson
Date: 2009-01-09 14:04:02 -0500 (Fri, 09 Jan 2009)
New Revision: 11787
Modified:
trunk/Open-ILS/web/js/dojo/openils/User.js
Log:
enhanced getPermOrgList. you can now provide a list of perms and get the consolidated set of allowed orgs
Modified: trunk/Open-ILS/web/js/dojo/openils/User.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/User.js 2009-01-09 18:49:53 UTC (rev 11786)
+++ trunk/Open-ILS/web/js/dojo/openils/User.js 2009-01-09 19:04:02 UTC (rev 11787)
@@ -22,6 +22,7 @@
dojo.require("DojoSRF");
dojo.require('openils.Event');
dojo.require('fieldmapper.Fieldmapper');
+ dojo.require('fieldmapper.OrgUtils');
dojo.declare('openils.User', null, {
@@ -175,21 +176,47 @@
/**
- * 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
More information about the open-ils-commits
mailing list