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
55 function buildOrgSel(selector, org, offset) {
56 insertSelectorVal( selector, -1,
57 org.name(), org.id(), null, findOrgDepth(org) - offset );
58 for( var c in org.children() )
59 buildOrgSel( selector, org.children()[c], offset);
62 /** removes all child nodes in 'tbody' that have the attribute 'key' defined */
63 function cleanTbody(tbody, key) {
64 for( var c = 0; c < tbody.childNodes.length; c++ ) {
65 var child = tbody.childNodes[c];
66 if(child && child.getAttribute(key)) tbody.removeChild(child);
71 /** Inserts a row into a specified place in a table
72 * tbody is the table body
73 * row is the context row after which the new row is to be inserted
74 * newRow is the new row to insert
76 function insRow( tbody, row, newRow ) {
77 if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
78 else{ tbody.appendChild(newRow); }
82 /** Checks to see if a given node should be enabled
83 * A node should be enabled if the itemOrg is lower in the
84 * org tree than my permissions allow editing
85 * I.e. I can edit the context item because it's "below" me
87 function checkDisabled( node, itemOrg, perm ) {
88 var itemDepth = findOrgDepth(itemOrg);
89 var mydepth = findOrgDepth(PERMS[perm]);
90 if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
94 function fetchOrgUnit(id, callback) {
96 if(ORG_CACHE[id]) return ORG_CACHE[id];
97 var req = new Request(FETCH_ORG_UNIT, SESSION, id);
102 var org = r.getResultObject();
111 var org = req.result();