1 angular.module('egHoldsApp',
2 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
4 .config(function($routeProvider, $locationProvider, $compileProvider) {
5 $locationProvider.html5Mode(true);
6 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
8 var resolver = {delay :
9 ['egStartup', function(egStartup) {return egStartup.go()}]}
11 $routeProvider.when('/circ/holds/shelf', {
12 templateUrl: './circ/holds/t_shelf',
13 controller: 'HoldsShelfCtrl',
17 $routeProvider.when('/circ/holds/shelf/:hold_id', {
18 templateUrl: './circ/holds/t_shelf',
19 controller: 'HoldsShelfCtrl',
23 $routeProvider.when('/circ/holds/pull', {
24 templateUrl: './circ/holds/t_pull',
25 controller: 'HoldsPullListCtrl',
29 $routeProvider.when('/circ/holds/pull/:hold_id', {
30 templateUrl: './circ/holds/t_pull',
31 controller: 'HoldsPullListCtrl',
35 $routeProvider.otherwise({redirectTo : '/circ/holds/shelf'});
39 .controller('HoldsShelfCtrl',
40 ['$scope','$q','$routeParams','$window','$location','egCore','egHolds','egHoldGridActions','egCirc','egGridDataProvider',
41 function($scope , $q , $routeParams , $window , $location , egCore , egHolds , egHoldGridActions , egCirc , egGridDataProvider) {
42 $scope.detail_hold_id = $routeParams.hold_id;
46 var clear_mode = false;
47 $scope.gridControls = {};
48 $scope.grid_actions = egHoldGridActions;
50 function fetch_holds(offset, count) {
51 var ids = hold_ids.slice(offset, offset + count);
52 return egHolds.fetch_holds(ids).then(null, null,
54 holds.push(hold_data);
55 return hold_data; // to the grid
60 var provider = egGridDataProvider.instance({});
61 $scope.gridDataProvider = provider;
63 function refresh_page() {
68 // called after any egHoldGridActions action occurs
69 $scope.grid_actions.refresh = refresh_page;
71 provider.get = function(offset, count) {
73 // see if we have the requested range cached
75 return provider.arrayNotifier(holds, offset, count);
78 // see if we have the holds IDs for this range already loaded
79 if (hold_ids[offset]) {
80 return fetch_holds(offset, count);
83 var deferred = $q.defer();
87 var method = 'open-ils.circ.captured_holds.id_list.on_shelf.retrieve.authoritative.atomic';
89 method = 'open-ils.circ.captured_holds.id_list.expired_on_shelf_or_wrong_shelf.retrieve.atomic';
92 'open-ils.circ', method,
93 egCore.auth.token(), $scope.pickup_ou.id()
95 ).then(function(ids) {
102 fetch_holds(offset, count)
103 .then(deferred.resolve, null, deferred.notify);
106 return deferred.promise;
109 // re-draw the grid when user changes the org selector
110 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
111 $scope.$watch('pickup_ou', function(newVal, oldVal) {
112 if (newVal && newVal != oldVal)
116 $scope.detail_view = function(action, user_data, items) {
118 $location.path('/circ/holds/shelf/' + h.hold.id());
122 $scope.list_view = function(items) {
123 $location.path('/circ/holds/shelf');
126 // when the detail hold is fetched (and updated), update the bib
127 // record summary display record id.
128 $scope.set_hold = function(hold_data) {
129 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
132 // manage active vs. clearable holds display
133 var clearing = false; // true if actively clearing holds (below)
134 $scope.is_clearing = function() { return clearing };
135 $scope.active_mode = function() {return !clear_mode}
136 $scope.clear_mode = function() {return clear_mode}
137 $scope.show_clearable = function() { clear_mode = true; refresh_page() }
138 $scope.show_active = function() { clear_mode = false; refresh_page() }
139 $scope.disable_clear = function() { return clearing || !clear_mode }
141 // udpate the in-grid hold with the clear-shelf cached response info.
142 function handle_clear_cache_resp(resp) {
143 if (!angular.isArray(resp)) resp = [resp];
144 angular.forEach(resp, function(info) {
146 var grid_item = holds.filter(function(item) {
147 return item.hold.id() == info.hold_details.id
150 // there will be no grid item if the hold is off-page
152 grid_item.post_clear =
153 egCore.strings['CLEAR_SHELF_ACTION_' + info.action];
159 $scope.clear_holds = function() {
161 $scope.clear_progress = {max : 0, value : 0};
163 // we want to see all processed holds, so (effectively) remove
165 $scope.gridControls.setLimit(1000, true);
167 // initiate clear shelf and grab cache key
170 'open-ils.circ.hold.clear_shelf.process',
171 egCore.auth.token(), $scope.pickup_ou.id(),
174 // request responses from the clear shelf cache
177 // clear shelf done; fetch the cached results.
182 'open-ils.circ.hold.clear_shelf.get_cache',
183 egCore.auth.token(), resp.cache_key, 1
184 ).then(null, null, handle_clear_cache_resp);
189 // handle streamed clear_shelf progress updates
192 $scope.clear_progress.max = resp.maximum;
194 $scope.clear_progress.value = resp.progress;
200 $scope.print_list_progress = null;
201 $scope.print_shelf_list = function() {
202 var print_holds = [];
203 $scope.print_list_loading = true;
204 $scope.print_list_progress = 0;
206 // collect the full list of holds
209 'open-ils.circ.captured_holds.id_list.on_shelf.retrieve.authoritative.atomic',
210 egCore.auth.token(), $scope.pickup_ou.id()
211 ).then( function(idlist) {
213 egHolds.fetch_holds(idlist).then(
215 console.debug('printing ' + print_holds.length + ' holds');
216 // holds fetched, send to print
219 template : 'hold_shelf_list',
220 scope : {holds : print_holds}
224 function(hold_data) {
225 $scope.print_list_progress++;
226 egHolds.local_flesh(hold_data);
227 print_holds.push(hold_data);
228 hold_data.title = hold_data.mvr.title();
229 hold_data.author = hold_data.mvr.author();
230 hold_data.hold = egCore.idl.toHash(hold_data.hold);
231 hold_data.copy = egCore.idl.toHash(hold_data.copy);
232 hold_data.volume = egCore.idl.toHash(hold_data.volume);
233 hold_data.part = egCore.idl.toHash(hold_data.part);
236 }).finally(function() {
237 $scope.print_list_loading = false;
238 $scope.print_list_progress = null;
246 .controller('HoldsPullListCtrl',
247 ['$scope','$q','$routeParams','$window','$location','egCore',
248 'egHolds','egCirc','egHoldGridActions',
249 function($scope , $q , $routeParams , $window , $location , egCore ,
250 egHolds , egCirc , egHoldGridActions) {
252 $scope.detail_hold_id = $routeParams.hold_id;
254 var cached_details = {};
255 var details_needed = {};
257 $scope.gridControls = {
258 setQuery : function() {
259 return {'copy_circ_lib_id' : egCore.auth.user().ws_ou()}
261 setSort : function() {
262 return ['copy_location_order_position','call_number_sort_key']
264 itemRetrieved : function(item) {
265 if (!cached_details[item.id]) {
266 details_needed[item.id] = item;
269 allItemsRetrieved : flesh_holds
273 // Fetches hold detail data for each hold in the grid and links
274 // the detail data to the related grid item so egHoldGridActions
275 // and friends have access to holds data they understand.
276 // Only fetch not-yet-cached data.
277 function flesh_holds() {
279 // Start by fleshing hold details from our cached data.
280 var items = $scope.gridControls.allItems();
281 angular.forEach(items, function(item) {
282 if (!cached_details[item.id]) return;
283 angular.forEach(cached_details[item.id],
284 function(val, key) { item[key] = val })
287 // Exit if all needed details were already cached
288 if (Object.keys(details_needed).length == 0) return;
290 $scope.print_list_loading = true;
291 $scope.print_list_progress = 0;
295 'open-ils.circ.hold.details.batch.retrieve.authoritative',
296 egCore.auth.token(), Object.keys(details_needed)
299 $scope.print_list_loading = false;
300 $scope.print_list_progress = null;
302 function(hold_info) {
303 var hold_id = hold_info.hold.id();
304 cached_details[hold_id] = hold_info;
305 var item = details_needed[hold_id];
306 delete details_needed[hold_id];
307 angular.forEach(hold_info,
308 function(val, key) { item[key] = val });
309 $scope.print_list_progress++;
314 $scope.grid_actions = egHoldGridActions;
315 $scope.grid_actions.refresh = function() {
316 cached_details = {}; // un-cache details after edit actions.
317 $scope.gridControls.refresh();
320 $scope.detail_view = function(action, user_data, items) {
322 $location.path('/circ/holds/pull/' + h.hold.id());
326 $scope.list_view = function(items) {
327 $location.path('/circ/holds/pull');
330 // when the detail hold is fetched (and updated), update the bib
331 // record summary display record id.
332 $scope.set_hold = function(hold_data) {
333 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
336 // By default, this action is hidded from the UI, but leaving it
337 // here in case it's needed in the future
338 $scope.print_list_alt = function() {
339 var url = '/opac/extras/circ/alt_holds_print.html';
340 var win = $window.open(url, '_blank');
341 win.ses = function() {return egCore.auth.token()};
346 $scope.print_list_progress = null;
347 $scope.print_full_list = function() {
348 var print_holds = [];
349 $scope.print_list_loading = true;
350 $scope.print_list_progress = 0;
352 // collect the full list of holds
355 'open-ils.circ.hold_pull_list.fleshed.stream',
356 egCore.auth.token(), 10000, 0
359 console.debug('printing ' + print_holds.length + ' holds');
361 // holds fetched, send to print
364 template : 'hold_pull_list',
365 scope : {holds : print_holds}
369 function(hold_data) {
370 $scope.print_list_progress++;
371 egHolds.local_flesh(hold_data);
372 print_holds.push(hold_data);
373 hold_data.title = hold_data.mvr.title();
374 hold_data.author = hold_data.mvr.author();
375 hold_data.hold = egCore.idl.toHash(hold_data.hold);
376 hold_data.copy = egCore.idl.toHash(hold_data.copy);
377 hold_data.volume = egCore.idl.toHash(hold_data.volume);
378 hold_data.part = egCore.idl.toHash(hold_data.part);
380 ).finally(function() {
381 $scope.print_list_loading = false;
382 $scope.print_list_progress = null;