3 var FETCH_HOLD_LIST = 'open-ils.circ:open-ils.circ.hold_pull_list.retrieve';
4 var FETCH_COPY = 'open-ils.search:open-ils.search.asset.copy.fleshed.custom';
5 var FETCH_USER = 'open-ils.actor:open-ils.actor.user.fleshed.retrieve';
6 var FETCH_VOLUME = 'open-ils.search:open-ils.search.callnumber.retrieve';
8 var myPerms = [ 'VIEW_HOLD' ];
9 var HOLD_LIST_LIMIT = 50;
14 function pullListInit() {
15 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
16 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
17 JSAN.errorLevel = "die"; // none, warn, or die
18 JSAN.addRepository('/xul/server/');
19 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.stash_retrieve();
22 $('pl_user').appendChild(text(USER.usrname()));
23 $('pl_org').appendChild(text(findOrgUnit(USER.ws_ou()).name()));
24 setTimeout( function() {
25 fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
30 function pullListFetchHolds() {
31 var req = new Request(FETCH_HOLD_LIST, SESSION, HOLD_LIST_LIMIT, listOffset );
32 req.callback(pullListDrawHolds);
37 function pullListDrawHolds(r) {
38 var holds = r.getResultObject();
40 var tbody = $('pull_list_tbody');
42 holdRowTemplate = tbody.removeChild($('pull_list_row'));
43 numHolds = holds.length;
45 for( var h in holds ) {
47 var row = holdRowTemplate.cloneNode(true);
48 tbody.appendChild(row);
49 pullListDrawHold( tbody, row, hold, h );
54 function pullListDrawHold( tbody, row, hold, idx ) {
56 $n(row, 'date').appendChild(text(hold.request_time().replace(/\ .*/, "")));
58 switch( hold.hold_type() ) {
59 case 'C' : unHideMe($n(row, 'copy_hold')); break;
60 case 'V' : unHideMe($n(row, 'volume_hold')); break;
61 case 'T' : unHideMe($n(row, 'title_hold')); break;
62 case 'M' : unHideMe($n(row, 'mr_hold')); break;
65 var treq = new Request( FETCH_MODS_FROM_COPY, hold.current_copy() );
68 pullListDrawTitle( tbody, row, hold, idx, r.getResultObject() ); });
71 var creq = new Request( FETCH_COPY, hold.current_copy(), ['location'] );
74 pullListDrawCopy( tbody, row, hold, idx, r.getResultObject() ); });
77 var ureq = new Request( FETCH_USER, SESSION, hold.usr(), ['card'] );
80 pullListDrawUser( tbody, row, hold, idx, r.getResultObject() ); });
86 function pullListDrawTitle( tbody, row, hold, idx, record ) {
87 $n(row, 'title').appendChild(text(record.title()));
88 $n(row, 'author').appendChild(text(record.author()));
90 var type = modsFormatToMARC(record.types_of_resource()[0]);
91 unHideMe($n(row, 'format_' + type));
92 if( (parseInt(idx) +1) == numHolds ) update_ready('title');
96 function pullListDrawCopy( tbody, row, hold, idx, copy ) {
98 $n(row, 'barcode').appendChild(text(copy.barcode()));
99 $n(row, 'copy_location').appendChild(text(copy.location().name()));
100 $n(row, 'copy_number').appendChild(text(copy.copy_number()));
102 if (copy.age_protect()) {
103 $n(row, 'age_protect').appendChild(text( (copy.age_protect() == null ? '<Unset>' : ( typeof copy.age_protect() == 'object' ? copy.age_protect().name() : g.data.hash.crahp[ copy.age_protect() ].name() )) ));
104 unHideMe($n(row, 'age_protect_span'));
106 } catch(E) { alert(E); }
108 var vreq = new Request(FETCH_VOLUME, copy.call_number());
110 function(r) { pullListDrawVolume( tbody, row, hold, idx, r.getResultObject() ); } );
115 function pullListDrawUser( tbody, row, hold, idx, user ) {
116 $n(row, 'patron').appendChild(text(user.card().barcode()));
117 if( (parseInt(idx) +1) == numHolds ) update_ready('patron');
120 var callNumbers = [];
121 function pullListDrawVolume( tbody, row, hold, idx, volume ) {
122 $n(row, 'call_number').appendChild(text(volume.label()));
123 callNumbers.push(volume.label());
125 if( (parseInt(idx) +1) == numHolds ) update_ready('call_number');
129 function ts_getInnerText(el) {
131 if (el == null) { alert('null'); return ''; }
132 if (typeof el == "string") return el;
133 if (typeof el == "undefined") { return el };
134 if (el.innerText) return el.innerText; //Not needed but it is faster
137 var cs = el.childNodes;
139 for (var i = 0; i < l; i++) {
140 switch (cs[i].nodeType) {
141 case 1: //ELEMENT_NODE
142 str += ts_getInnerText(cs[i]);
145 str += cs[i].nodeValue;
152 alert('el = ' + el + '\nel.nodeName = ' + el.nodeName + ' el.nodeType = ' + el.nodeType + '\nE = ' + E);
154 alert('el = ' + el + '\nF = ' + F + '\nE = ' + E);
159 function get_unhidden_span(node) {
160 var nl = node.childNodes;
162 for (var i = 0; i < nl.length; i++) {
163 if (nl[i].nodeName != 'span') continue;
164 if (nl[i].getAttribute('class') != 'hide_me') s += ts_getInnerText(nl[i]);
169 function $f(parent,name) {
170 var nl = parent.childNodes;
171 for (var i = 0; i < nl.length; i++) {
172 if (typeof nl[i].getAttribute != 'undefined' && nl[i].getAttribute('name') == name) {
178 function update_ready(which_update) {
179 g[which_update] = true;
180 if (typeof g.title != 'undefined' && typeof g.patron != 'undefined' && typeof g.call_number != 'undefined') {
181 setTimeout( function() { update_ready_do_it(); }, 1000);
185 function update_ready_do_it() {
186 unHideMe($('pull_list_tbody')); hideMe($('inprogress'));
188 var div = $('pull_list_tbody');
189 var div_children = div.childNodes;
190 for (var i = 0; i < div_children.length; i++) {
191 var pre = div_children[i];
192 if (pre.nodeName != 'pre') continue;
195 'call_number' : ts_getInnerText($f(pre,'call_number')),
196 'title' : ts_getInnerText($f(pre,'title')),
197 'author' : ts_getInnerText($f(pre,'author')),
198 'location' : ts_getInnerText($f(pre,'copy_location')),
199 'copy_number' : ts_getInnerText($f(pre,'copy_number')),
200 'item_type' : get_unhidden_span($f(pre,'item_type')),
206 rows = rows.sort( function(a,b) {
207 function inner_sort(sort_type,a,b) {
210 a = Number(a); b = Number(b);
212 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
213 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
214 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
217 a = String( a ).toUpperCase();
218 b = String( b ).toUpperCase();
222 if (a < b) return -1;
226 var value = inner_sort('string',a.call_number,b.call_number);
227 if (value == 0) value = inner_sort('title',a.title,b.title);
228 if (value == 0) value = inner_sort('string',a.author,b.author);
229 if (value == 0) value = inner_sort('string',a.location,b.location);
230 if (value == 0) value = inner_sort('number',a.copy_number,b.copy_number);
231 if (value == 0) value = inner_sort('string',a.item_type,b.item_type);
234 while(div.lastChild) div.removeChild( div.lastChild );
235 for (var i = 0; i < rows.length; i++) {
236 div.appendChild( rows[i].node );