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];
57 //PERMS[ perms[i] ] = ( orgs[i] != null ) ? orgs[i] : -1 ;
61 /* offset is the depth of the highest org
62 in the tree we're building
65 /* XXX Moved to opac_utils.js */
68 function buildOrgSel(selector, org, offset) {
69 insertSelectorVal( selector, -1,
70 org.name(), org.id(), null, findOrgDepth(org) - offset );
71 for( var c in org.children() )
72 buildOrgSel( selector, org.children()[c], offset);
76 /** removes all child nodes in 'tbody' that have the attribute 'key' defined */
77 function cleanTbody(tbody, key) {
78 for( var c = 0; c < tbody.childNodes.length; c++ ) {
79 var child = tbody.childNodes[c];
80 if(child && child.getAttribute(key)) tbody.removeChild(child);
85 /** Inserts a row into a specified place in a table
86 * tbody is the table body
87 * row is the context row after which the new row is to be inserted
88 * newRow is the new row to insert
90 function insRow( tbody, row, newRow ) {
91 if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
92 else{ tbody.appendChild(newRow); }
96 /** Checks to see if a given node should be enabled
97 * A node should be enabled if the itemOrg is lower in the
98 * org tree than my permissions allow editing
99 * I.e. I can edit the context item because it's "below" me
101 function checkDisabled( node, itemOrg, perm ) {
102 var itemDepth = findOrgDepth(itemOrg);
103 var mydepth = findOrgDepth(PERMS[perm]);
104 if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
108 function fetchOrgUnit(id, callback) {
110 if(ORG_CACHE[id]) return ORG_CACHE[id];
111 var req = new Request(FETCH_ORG_UNIT, SESSION, id);
116 var org = r.getResultObject();
125 var org = req.result();