5 var OILS_WORK_PERMS = {};
7 var XML_ELEMENT_NODE = 1;
10 var FETCH_ORG_UNIT = "open-ils.actor:open-ils.actor.org_unit.retrieve";
12 function debug(str) { try { dump(str + '\n'); } catch(e){} }
14 function fetchUser(session) {
15 if(session == null ) {
17 session = cgi.param('ses');
19 if(!session) throw "User session is not defined";
21 var request = new Request(FETCH_SESSION, session, 1);
23 var user = request.result();
24 if(checkILSEvent(user)) throw user;
29 /* if defined, callback will get the user object asynchronously */
30 function fetchFleshedUser(id, callback) {
31 if(id == null) return null;
32 var req = new Request(
33 'open-ils.actor:open-ils.actor.user.fleshed.retrieve', SESSION, id );
36 req.callback( function(r){callback(r.getResultObject());} );
46 * Fetches the highest org at for each perm and stores the value in
47 * PERMS[ permName ]. It also returns the org list to the caller
49 function fetchHighestPermOrgs( session, userId, perms ) {
50 var req = new RemoteRequest(
52 'open-ils.actor.user.perm.highest_org.batch',
53 session, userId, perms );
55 var orgs = req.getResultObject();
56 for( var i = 0; i != orgs.length; i++ )
57 PERMS[perms[i]] = orgs[i];
58 //PERMS[ perms[i] ] = ( orgs[i] != null ) ? orgs[i] : -1 ;
62 function fetchHighestWorkPermOrgs(session, userId, perms, onload) {
63 var req = new RemoteRequest(
65 'open-ils.actor.user.work_perm.highest_org_set.batch',
68 req.setCompleteCallback(function(r){
69 onload(OILS_WORK_PERMS = r.getResultObject());
74 return OILS_WORK_PERMS = req.getResultObject();
79 /* offset is the depth of the highest org
80 in the tree we're building
83 /* XXX Moved to opac_utils.js */
86 function buildOrgSel(selector, org, offset) {
87 insertSelectorVal( selector, -1,
88 org.name(), org.id(), null, findOrgDepth(org) - offset );
89 for( var c in org.children() )
90 buildOrgSel( selector, org.children()[c], offset);
94 /** removes all child nodes in 'tbody' that have the attribute 'key' defined */
95 function cleanTbody(tbody, key) {
96 for( var c = 0; c < tbody.childNodes.length; c++ ) {
97 var child = tbody.childNodes[c];
98 if(child && child.getAttribute(key)) tbody.removeChild(child);
103 /** Inserts a row into a specified place in a table
104 * tbody is the table body
105 * row is the context row after which the new row is to be inserted
106 * newRow is the new row to insert
108 function insRow( tbody, row, newRow ) {
109 if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
110 else{ tbody.appendChild(newRow); }
114 /** Checks to see if a given node should be enabled
115 * A node should be enabled if the itemOrg is lower in the
116 * org tree than my permissions allow editing
117 * I.e. I can edit the context item because it's "below" me
119 function checkDisabled( node, itemOrg, perm ) {
120 var itemDepth = findOrgDepth(itemOrg);
121 var mydepth = findOrgDepth(PERMS[perm]);
122 if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
126 * If the item-related org unit (owner, etc.) is one of or
127 * or a child of any of the perm-orgs related to the
128 * provided permission, enable the requested node
130 function checkPermOrgDisabled(node, itemOrg, perm) {
131 var org_list = OILS_WORK_PERMS[perm];
132 if(org_list.length > 0) {
133 for(var i = 0; i < org_list.length; i++) {
134 var highPermOrg = findOrgUnit(org_list[i]);
135 if(orgIsMine(highPermOrg, findOrgUnit(itemOrg)))
136 node.disabled = false;
142 function fetchOrgUnit(id, callback) {
144 if(ORG_CACHE[id]) return ORG_CACHE[id];
145 var req = new Request(FETCH_ORG_UNIT, SESSION, id);
150 var org = r.getResultObject();
159 var org = req.result();