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() {
16 $('pl_user').appendChild(text(USER.usrname()));
17 $('pl_org').appendChild(text(findOrgUnit(USER.ws_ou()).name()));
18 setTimeout( function() {
19 fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
24 function pullListFetchHolds() {
25 var req = new Request(FETCH_HOLD_LIST, SESSION, HOLD_LIST_LIMIT, listOffset );
26 req.callback(pullListDrawHolds);
31 function pullListDrawHolds(r) {
32 var holds = r.getResultObject();
34 var tbody = $('pull_list_tbody');
36 holdRowTemplate = tbody.removeChild($('pull_list_row'));
37 numHolds = holds.length;
39 for( var h in holds ) {
41 var row = holdRowTemplate.cloneNode(true);
42 tbody.appendChild(row);
43 pullListDrawHold( tbody, row, hold, h );
48 function pullListDrawHold( tbody, row, hold, idx ) {
50 $n(row, 'date').appendChild(text(hold.request_time().replace(/\ .*/, "")));
52 switch( hold.hold_type() ) {
53 case 'C' : unHideMe($n(row, 'copy_hold')); break;
54 case 'V' : unHideMe($n(row, 'volume_hold')); break;
55 case 'T' : unHideMe($n(row, 'title_hold')); break;
56 case 'M' : unHideMe($n(row, 'mr_hold')); break;
59 var treq = new Request( FETCH_MODS_FROM_COPY, hold.current_copy() );
62 pullListDrawTitle( tbody, row, hold, idx, r.getResultObject() ); });
65 var creq = new Request( FETCH_COPY, hold.current_copy(), ['location'] );
68 pullListDrawCopy( tbody, row, hold, idx, r.getResultObject() ); });
71 var ureq = new Request( FETCH_USER, SESSION, hold.usr(), ['card'] );
74 pullListDrawUser( tbody, row, hold, idx, r.getResultObject() ); });
80 function pullListDrawTitle( tbody, row, hold, idx, record ) {
81 $n(row, 'title').appendChild(text(record.title()));
82 $n(row, 'author').appendChild(text(record.author()));
84 var type = modsFormatToMARC(record.types_of_resource()[0]);
85 unHideMe($n(row, 'format_' + type));
86 if( (parseInt(idx) +1) == numHolds ) update_ready('title');
90 function pullListDrawCopy( tbody, row, hold, idx, copy ) {
92 $n(row, 'barcode').appendChild(text(copy.barcode()));
93 $n(row, 'copy_location').appendChild(text(copy.location().name()));
94 $n(row, 'copy_number').appendChild(text(copy.copy_number()));
96 var vreq = new Request(FETCH_VOLUME, copy.call_number());
98 function(r) { pullListDrawVolume( tbody, row, hold, idx, r.getResultObject() ); } );
103 function pullListDrawUser( tbody, row, hold, idx, user ) {
104 $n(row, 'patron').appendChild(text(user.card().barcode()));
105 if( (parseInt(idx) +1) == numHolds ) update_ready('patron');
108 var callNumbers = [];
109 function pullListDrawVolume( tbody, row, hold, idx, volume ) {
110 $n(row, 'call_number').appendChild(text(volume.label()));
111 callNumbers.push(volume.label());
113 if( (parseInt(idx) +1) == numHolds ) update_ready('call_number');
117 function ts_getInnerText(el) {
119 if (el == null) { alert('null'); return ''; }
120 if (typeof el == "string") return el;
121 if (typeof el == "undefined") { return el };
122 if (el.innerText) return el.innerText; //Not needed but it is faster
125 var cs = el.childNodes;
127 for (var i = 0; i < l; i++) {
128 switch (cs[i].nodeType) {
129 case 1: //ELEMENT_NODE
130 str += ts_getInnerText(cs[i]);
133 str += cs[i].nodeValue;
140 alert('el = ' + el + '\nel.nodeName = ' + el.nodeName + ' el.nodeType = ' + el.nodeType + '\nE = ' + E);
142 alert('el = ' + el + '\nF = ' + F + '\nE = ' + E);
147 function get_unhidden_span(node) {
148 var nl = node.childNodes;
150 for (var i = 0; i < nl.length; i++) {
151 if (nl[i].nodeName != 'span') continue;
152 if (nl[i].getAttribute('class') != 'hide_me') s += ts_getInnerText(nl[i]);
157 function $f(parent,name) {
158 var nl = parent.childNodes;
159 for (var i = 0; i < nl.length; i++) {
160 if (typeof nl[i].getAttribute != 'undefined' && nl[i].getAttribute('name') == name) {
166 function update_ready(which_update) {
167 g[which_update] = true;
168 if (typeof g.title != 'undefined' && typeof g.patron != 'undefined' && typeof g.call_number != 'undefined') {
169 unHideMe($('pull_list_tbody')); hideMe($('inprogress'));
171 var div = $('pull_list_tbody');
172 var div_children = div.childNodes;
173 for (var i = 0; i < div_children.length; i++) {
174 var pre = div_children[i];
175 if (pre.nodeName != 'pre') continue;
178 'call_number' : ts_getInnerText($f(pre,'call_number')),
179 'title' : ts_getInnerText($f(pre,'title')),
180 'author' : ts_getInnerText($f(pre,'author')),
181 'location' : ts_getInnerText($f(pre,'copy_location')),
182 'copy_number' : ts_getInnerText($f(pre,'copy_number')),
183 'item_type' : get_unhidden_span($f(pre,'item_type')),
189 rows = rows.sort( function(a,b) {
190 function inner_sort(sort_type,a,b) {
193 a = Number(a); b = Number(b);
195 case 'title' : /* special case for "a" and "the". doesn't use marc 245 indicator */
196 a = String( a ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
197 b = String( b ).toUpperCase().replace( /^\s*(THE|A|AN)\s+/, '' );
200 a = String( a ).toUpperCase();
201 b = String( b ).toUpperCase();
205 if (a < b) return -1;
209 var value = inner_sort('string',a.call_number,b.call_number);
210 if (value == 0) value = inner_sort('title',a.title,b.title);
211 if (value == 0) value = inner_sort('string',a.author,b.author);
212 if (value == 0) value = inner_sort('string',a.location,b.location);
213 if (value == 0) value = inner_sort('number',a.copy_number,b.copy_number);
214 if (value == 0) value = inner_sort('string',a.item_type,b.item_type);
217 while(div.lastChild) div.removeChild( div.lastChild );
218 for (var i = 0; i < rows.length; i++) {
219 div.appendChild( rows[i].node );