6 var XML_ELEMENT_NODE = 1;
9 var FETCH_ORG_UNIT = "open-ils.actor:open-ils.actor.org_unit.retrieve";
11 function fetchUser(session) {
12 if(session == null ) {
14 session = cgi.param('ses');
16 if(!session) throw "User session is not defined";
18 var request = new Request(FETCH_SESSION, session, 1 );
20 var user = request.result();
21 if(checkILSEvent(user)) throw user;
26 function fetchFleshedUser(id) {
27 if(id == null) return null;
31 * Fetches the highest org at for each perm and stores the value in
32 * PERMS[ permName ]. It also returns the org list to the caller
34 function fetchHighestPermOrgs( session, userId, perms ) {
35 var req = new RemoteRequest(
37 'open-ils.actor.user.perm.highest_org.batch',
38 session, userId, perms );
40 var orgs = req.getResultObject();
41 for( var i = 0; i != orgs.length; i++ )
42 PERMS[ perms[i] ] = ( orgs[i] != null ) ? orgs[i] : -1 ;
46 /* offset is the depth of the highest org
47 in the tree we're building
49 function buildOrgSel(selector, org, offset) {
50 insertSelectorVal( selector, -1,
51 org.name(), org.id(), null, findOrgDepth(org) - offset );
52 for( var c in org.children() )
53 buildOrgSel( selector, org.children()[c], offset);
56 /** removes all child nodes in 'tbody' that have the attribute 'key' defined */
57 function cleanTbody(tbody, key) {
58 for( var c = 0; c < tbody.childNodes.length; c++ ) {
59 var child = tbody.childNodes[c];
60 if(child && child.getAttribute(key)) tbody.removeChild(child);
65 /** Inserts a row into a specified place in a table
66 * tbody is the table body
67 * row is the context row after which the new row is to be inserted
68 * newRow is the new row to insert
70 function insRow( tbody, row, newRow ) {
71 if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
72 else{ tbody.appendChild(newRow); }
76 /** Checks to see if a given node should be enabled
77 * A node should be enabled if the itemOrg is lower in the
78 * org tree than my permissions allow editing
79 * I.e. I can edit the context item because it's "below" me
81 function checkDisabled( node, itemOrg, perm ) {
82 var itemDepth = findOrgDepth(itemOrg);
83 var mydepth = findOrgDepth(PERMS[perm]);
84 if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
88 function fetchOrgUnit(id, callback) {
90 if(ORG_CACHE[id]) return ORG_CACHE[id];
91 var req = new Request(FETCH_ORG_UNIT, SESSION, id);
96 var org = r.getResultObject();
105 var org = req.result();