6 var XML_ELEMENT_NODE = 1;
9 var FETCH_ORG_UNIT = "open-ils.actor:open-ils.actor.org_unit.retrieve";
11 function debug(str) { try { dump(str + '\n'); } catch(e){} }
13 function fetchUser(session) {
14 if(session == null ) {
16 session = cgi.param('ses');
18 if(!session) throw "User session is not defined";
20 var request = new Request(FETCH_SESSION, session, 1);
22 var user = request.result();
23 if(checkILSEvent(user)) throw user;
28 /* if defined, callback will get the user object asynchronously */
29 function fetchFleshedUser(id, callback) {
30 if(id == null) return null;
31 var req = new Request(
32 'open-ils.actor:open-ils.actor.user.fleshed.retrieve', SESSION, id );
35 req.callback( function(r){callback(r.getResultObject());} );
45 * Fetches the highest org at for each perm and stores the value in
46 * PERMS[ permName ]. It also returns the org list to the caller
48 function fetchHighestPermOrgs( session, userId, perms ) {
49 var req = new RemoteRequest(
51 'open-ils.actor.user.perm.highest_org.batch',
52 session, userId, perms );
54 var orgs = req.getResultObject();
55 for( var i = 0; i != orgs.length; i++ )
56 PERMS[ perms[i] ] = ( orgs[i] != null ) ? orgs[i] : -1 ;
60 /* offset is the depth of the highest org
61 in the tree we're building
64 /* XXX Moved to opac_utils.js */
67 function buildOrgSel(selector, org, offset) {
68 insertSelectorVal( selector, -1,
69 org.name(), org.id(), null, findOrgDepth(org) - offset );
70 for( var c in org.children() )
71 buildOrgSel( selector, org.children()[c], offset);
75 /** removes all child nodes in 'tbody' that have the attribute 'key' defined */
76 function cleanTbody(tbody, key) {
77 for( var c = 0; c < tbody.childNodes.length; c++ ) {
78 var child = tbody.childNodes[c];
79 if(child && child.getAttribute(key)) tbody.removeChild(child);
84 /** Inserts a row into a specified place in a table
85 * tbody is the table body
86 * row is the context row after which the new row is to be inserted
87 * newRow is the new row to insert
89 function insRow( tbody, row, newRow ) {
90 if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
91 else{ tbody.appendChild(newRow); }
95 /** Checks to see if a given node should be enabled
96 * A node should be enabled if the itemOrg is lower in the
97 * org tree than my permissions allow editing
98 * I.e. I can edit the context item because it's "below" me
100 function checkDisabled( node, itemOrg, perm ) {
101 var itemDepth = findOrgDepth(itemOrg);
102 var mydepth = findOrgDepth(PERMS[perm]);
103 if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
107 function fetchOrgUnit(id, callback) {
109 if(ORG_CACHE[id]) return ORG_CACHE[id];
110 var req = new Request(FETCH_ORG_UNIT, SESSION, id);
115 var org = r.getResultObject();
124 var org = req.result();