]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/hold_pull_list.js
9a9b7428b6e145e47973a36116bd03f8a0aed1aa
[Evergreen.git] / Open-ILS / xul / staff_client / server / admin / hold_pull_list.js
1
2 var FETCH_HOLD_LIST            = 'open-ils.circ:open-ils.circ.hold_pull_list.retrieve';
3 var FETCH_COPY                    = 'open-ils.search:open-ils.search.asset.copy.fleshed.custom';
4 var FETCH_USER                    = 'open-ils.actor:open-ils.actor.user.fleshed.retrieve';
5 var FETCH_VOLUME                = 'open-ils.search:open-ils.search.callnumber.retrieve';
6
7 var myPerms                = [ 'VIEW_HOLD' ];
8 var HOLD_LIST_LIMIT    = 100;
9 var numHolds            = 0;
10
11 var listOffset            = 0;
12
13 function pullListInit() {
14     fetchUser();
15     $('pl_user').appendChild(text(USER.usrname()));
16     $('pl_org').appendChild(text(findOrgUnit(USER.ws_ou()).name()));
17     setTimeout( function() { 
18         fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
19         pullListFetchHolds();
20     }, 20 );
21 }
22
23 function pullListFetchHolds() {
24     var req = new Request(FETCH_HOLD_LIST, SESSION, HOLD_LIST_LIMIT, listOffset );
25     req.callback(pullListDrawHolds);
26     req.send();
27 }
28
29 var holdRowTemplate;
30 function pullListDrawHolds(r) {
31     var holds = r.getResultObject();
32
33     var tbody = $('pull_list_tbody');
34     if(!holdRowTemplate) 
35         holdRowTemplate = tbody.removeChild($('pull_list_row'));
36     numHolds = holds.length;
37
38     for( var h in holds ) {
39         var hold = holds[h];
40         var row = holdRowTemplate.cloneNode(true);
41         tbody.appendChild(row);
42         pullListDrawHold( tbody, row, hold, h );
43     }
44
45 }
46
47 function pullListDrawHold( tbody, row, hold, idx ) {
48
49     $n(row, 'date').appendChild(text(hold.request_time().replace(/\ .*/, "")));
50
51     switch( hold.hold_type() ) {
52         case 'C' : unHideMe($n(row, 'copy_hold')); break;
53         case 'V' : unHideMe($n(row, 'volume_hold')); break;
54         case 'T' : unHideMe($n(row, 'title_hold')); break;
55         case 'M' : unHideMe($n(row, 'mr_hold')); break;
56     }
57     
58     var treq = new Request( FETCH_MODS_FROM_COPY, hold.current_copy() );
59     treq.callback(
60         function(r) {
61             pullListDrawTitle( tbody, row, hold, idx, r.getResultObject() );    });
62     treq.send();
63
64     var creq = new Request( FETCH_COPY, hold.current_copy(), ['location'] );
65     creq.callback(
66         function(r) {
67             pullListDrawCopy( tbody, row, hold, idx, r.getResultObject() ); });
68     creq.send();
69
70     var ureq = new Request( FETCH_USER, SESSION, hold.usr(), ['card'] );
71     ureq.callback(
72         function(r) {
73             pullListDrawUser( tbody, row, hold, idx, r.getResultObject() ); });
74     ureq.send();
75
76 }
77
78
79 function pullListDrawTitle( tbody, row, hold, idx, record ) {
80     $n(row, 'title').appendChild(text(record.title()));
81     $n(row, 'author').appendChild(text(record.author()));
82
83     var type = modsFormatToMARC(record.types_of_resource()[0]);
84     unHideMe($n(row, 'format_' + type));
85 }
86
87
88 function pullListDrawCopy( tbody, row, hold, idx, copy ) {
89
90     $n(row, 'hold_type').appendChild(text(hold.hold_type()));
91     $n(row, 'barcode').appendChild(text(copy.barcode()));
92     $n(row, 'copy_location').appendChild(text(copy.location().name()));
93     $n(row, 'copy_number').appendChild(text(copy.copy_number()));
94
95     var vreq = new Request(FETCH_VOLUME, copy.call_number());
96     vreq.callback(
97         function(r) { pullListDrawVolume( tbody, row, hold, idx, r.getResultObject() ); } );
98     vreq.send();
99 }
100
101
102 function pullListDrawUser( tbody, row, hold, idx, user ) {
103     $n(row, 'patron').appendChild(text(user.card().barcode()));
104 }
105
106 var callNumbers = [];
107 function pullListDrawVolume( tbody, row, hold, idx, volume ) {
108     $n(row, 'call_number').appendChild(text(volume.label()));
109     callNumbers.push(volume.label());
110
111     if( (parseInt(idx) +1) == numHolds )
112         ts_resortTable($('pl_callnumber').getElementsByTagName('a')[0]);
113 }
114
115