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 = 100;
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();
20 JSAN.use('util.date');
23 $('pl_user').appendChild(text(USER.usrname()));
24 $('pl_org').appendChild(text(findOrgUnit(USER.ws_ou()).name()));
25 setTimeout( function() {
26 fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
31 function pullListFetchHolds() {
32 var req = new Request(FETCH_HOLD_LIST, SESSION, HOLD_LIST_LIMIT, listOffset );
33 req.callback(pullListDrawHolds);
38 function pullListDrawHolds(r) {
39 var holds = r.getResultObject();
41 var tbody = $('pull_list_tbody');
43 holdRowTemplate = tbody.removeChild($('pull_list_row'));
44 numHolds = holds.length;
46 for( var h in holds ) {
48 var row = holdRowTemplate.cloneNode(true);
49 tbody.appendChild(row);
50 pullListDrawHold( tbody, row, hold, h );
55 function pullListDrawHold( tbody, row, hold, idx ) {
57 $n(row, 'date').appendChild(text(hold.request_time().replace(/\ .*/, "")));
58 var pl = typeof hold.pickup_lib() == 'object' ? hold.pickup_lib().shortname() : g.data.hash.aou[ hold.pickup_lib() ].shortname();
59 $n(row, 'pickup').appendChild(text(pl));
61 switch( hold.hold_type() ) {
62 case 'C' : unHideMe($n(row, 'copy_hold')); break;
63 case 'V' : unHideMe($n(row, 'volume_hold')); break;
64 case 'T' : unHideMe($n(row, 'title_hold')); break;
65 case 'M' : unHideMe($n(row, 'mr_hold')); break;
68 var treq = new Request( FETCH_MODS_FROM_COPY, hold.current_copy() );
71 pullListDrawTitle( tbody, row, hold, idx, r.getResultObject() ); });
74 var creq = new Request( FETCH_COPY, hold.current_copy(), ['location'] );
77 pullListDrawCopy( tbody, row, hold, idx, r.getResultObject() ); });
80 var ureq = new Request( FETCH_USER, SESSION, hold.usr(), ['card'] );
83 pullListDrawUser( tbody, row, hold, idx, r.getResultObject() ); });
89 function pullListDrawTitle( tbody, row, hold, idx, record ) {
90 $n(row, 'title').appendChild(text(record.title()));
91 $n(row, 'author').appendChild(text(record.author()));
93 var type = modsFormatToMARC(record.types_of_resource()[0]);
94 unHideMe($n(row, 'format_' + type));
95 if( (parseInt(idx) +1) == numHolds ) update_ready('title');
99 function pullListDrawCopy( tbody, row, hold, idx, copy ) {
101 $n(row, 'barcode').appendChild(text(copy.barcode()));
102 $n(row, 'copy_location').appendChild(text(copy.location().name()));
103 $n(row, 'copy_number').appendChild(text(copy.copy_number()));
105 if (copy.age_protect()) {
106 $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() )) + ' (' + util.date.formatted_date( copy.create_date(), '%{localized_date}' ) + ')' ));
107 unHideMe($n(row, 'age_protect_span'));
109 } catch(E) { alert(E); }
111 var vreq = new Request(FETCH_VOLUME, copy.call_number());
113 function(r) { pullListDrawVolume( tbody, row, hold, idx, r.getResultObject() ); } );
118 function pullListDrawUser( tbody, row, hold, idx, user ) {
119 $n(row, 'patron').appendChild(text(user.card().barcode()));
120 if( (parseInt(idx) +1) == numHolds ) update_ready('patron');
123 var callNumbers = [];
124 function pullListDrawVolume( tbody, row, hold, idx, volume ) {
125 $n(row, 'call_number').appendChild(text(volume.label()));
126 callNumbers.push(volume.label());
128 if( (parseInt(idx) +1) == numHolds ) update_ready('call_number');
132 function ts_getInnerText(el) {
134 if (el == null) { alert('null'); return ''; }
135 if (typeof el == "string") return el;
136 if (typeof el == "undefined") { return el };
137 if (el.innerText) return el.innerText; //Not needed but it is faster
140 var cs = el.childNodes;
142 for (var i = 0; i < l; i++) {
143 switch (cs[i].nodeType) {
144 case 1: //ELEMENT_NODE
145 str += ts_getInnerText(cs[i]);
148 str += cs[i].nodeValue;
155 alert('el = ' + el + '\nel.nodeName = ' + el.nodeName + ' el.nodeType = ' + el.nodeType + '\nE = ' + E);
157 alert('el = ' + el + '\nF = ' + F + '\nE = ' + E);
162 function get_unhidden_span(node) {
163 var nl = node.childNodes;
165 for (var i = 0; i < nl.length; i++) {
166 if (nl[i].nodeName != 'span') continue;
167 if (nl[i].getAttribute('class') != 'hide_me') s += ts_getInnerText(nl[i]);
172 function $f(parent,name) {
173 var nl = parent.childNodes;
174 for (var i = 0; i < nl.length; i++) {
175 if (typeof nl[i].getAttribute != 'undefined' && nl[i].getAttribute('name') == name) {
181 function update_ready(which_update) {
182 g[which_update] = true;
183 if (typeof g.title != 'undefined' && typeof g.patron != 'undefined' && typeof g.call_number != 'undefined') {
184 setTimeout( function() { update_ready_do_it(); }, 1000);
188 function update_ready_do_it() {
189 unHideMe($('pull_list_tbody')); hideMe($('inprogress'));
191 var div = $('pull_list_tbody');
192 var div_children = div.childNodes;
193 for (var i = 0; i < div_children.length; i++) {
194 var pre = div_children[i];
195 if (pre.nodeName != 'pre') continue;
198 'call_number' : ts_getInnerText($f(pre,'call_number')),
199 'title' : ts_getInnerText($f(pre,'title')),
200 'author' : ts_getInnerText($f(pre,'author')),
201 'location' : ts_getInnerText($f(pre,'copy_location')),
202 'copy_number' : ts_getInnerText($f(pre,'copy_number')),
203 'item_type' : get_unhidden_span($f(pre,'item_type')),
209 rows = rows.sort( function(a,b) {
210 function inner_sort(sort_type,a,b) {
213 a = Number(a); b = Number(b);
215 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
216 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
217 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
220 a = String( a ).toUpperCase();
221 b = String( b ).toUpperCase();
225 if (a < b) return -1;
229 var value = inner_sort('string',a.call_number,b.call_number);
230 if (value == 0) value = inner_sort('title',a.title,b.title);
231 if (value == 0) value = inner_sort('string',a.author,b.author);
232 if (value == 0) value = inner_sort('string',a.location,b.location);
233 if (value == 0) value = inner_sort('number',a.copy_number,b.copy_number);
234 if (value == 0) value = inner_sort('string',a.item_type,b.item_type);
237 while(div.lastChild) div.removeChild( div.lastChild );
238 for (var i = 0; i < rows.length; i++) {
239 div.appendChild( rows[i].node );