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