]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/adminlib.js
more coming together of the admin editor code
[Evergreen.git] / Open-ILS / xul / staff_client / server / admin / adminlib.js
1 var USER;
2 var SESSION;
3 var PERMS = {};
4
5 function fetchUser(session) {
6         if(session == null ) {
7                 cgi = new CGI();
8                 session = cgi.param('ses');
9         }
10         if(!session) throw "User session is not defined";
11         SESSION = session;
12         var request = new Request(FETCH_SESSION, session, 1 );
13         request.send(true);
14         var user = request.result();
15         if(checkILSEvent(user)) throw user;
16         USER = user;
17         return user;
18 }
19
20 /**
21   * Fetches the highest org at for each perm  and stores the value in
22   * PERMS[ permName ].  It also returns the org list to the caller
23   */
24 function fetchHighestPermOrgs( session, userId, perms ) {
25         var req = new RemoteRequest(
26                 'open-ils.actor',
27                 'open-ils.actor.user.perm.highest_org.batch', 
28                 session, userId, perms  );
29         req.send(true);
30         var orgs = req.getResultObject();
31         for( var i = 0; i != orgs.length; i++ ) 
32                 PERMS[ perms[i] ] = ( orgs[i] != null ) ? orgs[i] : -1 ;
33         return orgs;
34 }
35
36 /* offset is the depth of the highest org 
37         in the tree we're building 
38   */
39 function buildOrgSel(selector, org, offset) {
40         insertSelectorVal( selector, -1, 
41                 org.name(), org.id(), null, findOrgDepth(org) - offset );
42         for( var c in org.children() )
43                 buildOrgSel( selector, org.children()[c], offset);
44 }
45
46 /** removes all child nodes in 'tbody' that have the attribute 'key' defined */
47 function cleanTbody(tbody, key) {
48         for( var c  = 0; c < tbody.childNodes.length; c++ ) {
49                 var child = tbody.childNodes[c];
50                 if(child && child.getAttribute(key)) tbody.removeChild(child); 
51         }
52 }