]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/hold_pull_list.js
fleshing copy location on fetch instead of fetching all copy locations
[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     = 50;
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, 'barcode').appendChild(text(copy.barcode()));
91         $n(row, 'copy_location').appendChild(text(copy.location().name()));
92         $n(row, 'copy_number').appendChild(text(copy.copy_number()));
93
94         var vreq = new Request(FETCH_VOLUME, copy.call_number());
95         vreq.callback(
96                 function(r) { pullListDrawVolume( tbody, row, hold, idx, r.getResultObject() ); } );
97         vreq.send();
98 }
99
100
101 function pullListDrawUser( tbody, row, hold, idx, user ) {
102         $n(row, 'patron').appendChild(text(user.card().barcode()));
103 }
104
105 var callNumbers = [];
106 function pullListDrawVolume( tbody, row, hold, idx, volume ) {
107         $n(row, 'call_number').appendChild(text(volume.label()));
108         callNumbers.push(volume.label());
109
110         if( (parseInt(idx) +1) == numHolds )
111                 ts_resortTable($('pl_callnumber').getElementsByTagName('a')[0]);
112 }
113
114