]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/adminlib.js
af55c167d29f7f0029ac260d45a228af1b08aab9
[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 }
53
54
55 /** Inserts a row into a specified place in a table
56   * tbody is the table body
57   * row is the context row after which the new row is to be inserted
58   * newRow is the new row to insert
59   */
60 function insRow( tbody, row, newRow ) {
61         if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
62         else{ tbody.appendChild(newRow); }
63 }
64
65
66 /** Checks to see if a given node should be enabled
67   * A node should be enabled if the itemOrg is lower in the
68   * org tree than my permissions allow editing
69   * I.e. I can edit the context item because it's "below" me
70   */
71 function checkDisabled( node, itemOrg, perm ) {
72         var itemDepth = findOrgDepth(itemOrg);
73         var mydepth = findOrgDepth(PERMS[perm]);
74         if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
75 }