]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/hold_pull_list.js
Created holds list interface and method to pull the list from storage
[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.search:open-ils.search.config.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         var treq = new Request( FETCH_MODS_FROM_COPY, hold.current_copy() );
62         treq.callback(
63                 function(r) {
64                         pullListDrawTitle( tbody, row, hold, idx, r.getResultObject() );        });
65         treq.send();
66
67         var creq = new Request( FETCH_COPY, hold.current_copy() );
68         creq.callback(
69                 function(r) {
70                         pullListDrawCopy( tbody, row, hold, idx, r.getResultObject() ); });
71         creq.send();
72
73         var ureq = new Request( FETCH_USER, SESSION, hold.usr() );
74         ureq.callback(
75                 function(r) {
76                         pullListDrawUser( tbody, row, hold, idx, r.getResultObject() ); });
77         ureq.send();
78
79 }
80
81
82 function pullListDrawTitle( tbody, row, hold, idx, record ) {
83         $n(row, 'title').appendChild(text(record.title()));
84         $n(row, 'author').appendChild(text(record.author()));
85
86         var type = modsFormatToMARC(record.types_of_resource()[0]);
87         unHideMe($n(row, 'format_' + type));
88 }
89
90
91 function pullListDrawCopy( tbody, row, hold, idx, copy ) {
92         $n(row, 'barcode').appendChild(text(copy.barcode()));
93         for( var l in copyLocations ) {
94                 var loc = copyLocations[l];
95                 if( loc.id() == copy.location() ) {
96                         $n(row, 'copy_location').appendChild(text(loc.name()));
97                         break;
98                 }
99         }
100         $n(row, 'copy_number').appendChild(text(copy.copy_number()));
101
102         var vreq = new Request(FETCH_VOLUME, copy.call_number());
103         vreq.callback(
104                 function(r) { pullListDrawVolume( tbody, row, hold, idx, r.getResultObject() ); } );
105         vreq.send();
106 }
107
108
109 function pullListDrawUser( tbody, row, hold, idx, user ) {
110         $n(row, 'patron').appendChild(text(user.card().barcode()));
111 }
112
113 var callNumbers = [];
114 function pullListDrawVolume( tbody, row, hold, idx, volume ) {
115         $n(row, 'call_number').appendChild(text(volume.label()));
116         callNumbers.push(volume.label());
117
118         if( (parseInt(idx) +1) == numHolds )
119                 ts_resortTable($('pl_callnumber').getElementsByTagName('a')[0]);
120 }
121
122