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 function fetchFleshedUser(id) {
29 if(id == null) return null;
30 var req = new Request(
31 'open-ils.actor:open-ils.actor.user.fleshed.retrieve', SESSION, id );
37 * Fetches the highest org at for each perm and stores the value in
38 * PERMS[ permName ]. It also returns the org list to the caller
40 function fetchHighestPermOrgs( session, userId, perms ) {
41 var req = new RemoteRequest(
43 'open-ils.actor.user.perm.highest_org.batch',
44 session, userId, perms );
46 var orgs = req.getResultObject();
47 for( var i = 0; i != orgs.length; i++ )
48 PERMS[ perms[i] ] = ( orgs[i] != null ) ? orgs[i] : -1 ;
52 /* offset is the depth of the highest org
53 in the tree we're building
56 /* XXX Moved to opac_utils.js */
59 function buildOrgSel(selector, org, offset) {
60 insertSelectorVal( selector, -1,
61 org.name(), org.id(), null, findOrgDepth(org) - offset );
62 for( var c in org.children() )
63 buildOrgSel( selector, org.children()[c], offset);
67 /** removes all child nodes in 'tbody' that have the attribute 'key' defined */
68 function cleanTbody(tbody, key) {
69 for( var c = 0; c < tbody.childNodes.length; c++ ) {
70 var child = tbody.childNodes[c];
71 if(child && child.getAttribute(key)) tbody.removeChild(child);
76 /** Inserts a row into a specified place in a table
77 * tbody is the table body
78 * row is the context row after which the new row is to be inserted
79 * newRow is the new row to insert
81 function insRow( tbody, row, newRow ) {
82 if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
83 else{ tbody.appendChild(newRow); }
87 /** Checks to see if a given node should be enabled
88 * A node should be enabled if the itemOrg is lower in the
89 * org tree than my permissions allow editing
90 * I.e. I can edit the context item because it's "below" me
92 function checkDisabled( node, itemOrg, perm ) {
93 var itemDepth = findOrgDepth(itemOrg);
94 var mydepth = findOrgDepth(PERMS[perm]);
95 if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
99 function fetchOrgUnit(id, callback) {
101 if(ORG_CACHE[id]) return ORG_CACHE[id];
102 var req = new Request(FETCH_ORG_UNIT, SESSION, id);
107 var org = r.getResultObject();
116 var org = req.result();