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'});
38 .factory('holdUiSvc', function() {
44 .controller('HoldsShelfCtrl',
45 ['$scope','$q','$routeParams','$window','$location','egCore','egHolds','egHoldGridActions','egCirc','egGridDataProvider',
46 function($scope , $q , $routeParams , $window , $location , egCore , egHolds , egHoldGridActions , egCirc , egGridDataProvider) {
47 $scope.detail_hold_id = $routeParams.hold_id;
51 var clear_mode = false;
52 $scope.gridControls = {};
53 $scope.grid_actions = egHoldGridActions;
55 function fetch_holds(offset, count) {
56 var ids = hold_ids.slice(offset, offset + count);
57 return egHolds.fetch_holds(ids).then(null, null,
59 holds.push(hold_data);
60 return hold_data; // to the grid
65 var provider = egGridDataProvider.instance({});
66 $scope.gridDataProvider = provider;
68 function refresh_page() {
73 // called after any egHoldGridActions action occurs
74 $scope.grid_actions.refresh = refresh_page;
76 provider.get = function(offset, count) {
78 // see if we have the requested range cached
80 return provider.arrayNotifier(holds, offset, count);
83 // see if we have the holds IDs for this range already loaded
84 if (hold_ids[offset]) {
85 return fetch_holds(offset, count);
88 var deferred = $q.defer();
92 var method = 'open-ils.circ.captured_holds.id_list.on_shelf.retrieve.authoritative.atomic';
94 method = 'open-ils.circ.captured_holds.id_list.expired_on_shelf_or_wrong_shelf.retrieve.atomic';
97 'open-ils.circ', method,
98 egCore.auth.token(), $scope.pickup_ou.id()
100 ).then(function(ids) {
107 fetch_holds(offset, count)
108 .then(deferred.resolve, null, deferred.notify);
111 return deferred.promise;
114 // re-draw the grid when user changes the org selector
115 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
116 $scope.$watch('pickup_ou', function(newVal, oldVal) {
117 if (newVal && newVal != oldVal)
121 $scope.detail_view = function(action, user_data, items) {
123 $location.path('/circ/holds/shelf/' + h.hold.id());
127 $scope.list_view = function(items) {
128 $location.path('/circ/holds/shelf');
131 // when the detail hold is fetched (and updated), update the bib
132 // record summary display record id.
133 $scope.set_hold = function(hold_data) {
134 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
137 // manage active vs. clearable holds display
138 var clearing = false; // true if actively clearing holds (below)
139 $scope.is_clearing = function() { return clearing };
140 $scope.active_mode = function() {return !clear_mode}
141 $scope.clear_mode = function() {return clear_mode}
142 $scope.show_clearable = function() { clear_mode = true; refresh_page() }
143 $scope.show_active = function() { clear_mode = false; refresh_page() }
144 $scope.disable_clear = function() { return clearing || !clear_mode }
146 // udpate the in-grid hold with the clear-shelf cached response info.
147 function handle_clear_cache_resp(resp) {
148 if (!angular.isArray(resp)) resp = [resp];
149 angular.forEach(resp, function(info) {
151 var grid_item = holds.filter(function(item) {
152 return item.hold.id() == info.hold_details.id
155 // there will be no grid item if the hold is off-page
157 grid_item.post_clear =
158 egCore.strings['CLEAR_SHELF_ACTION_' + info.action];
164 $scope.clear_holds = function() {
166 $scope.clear_progress = {max : 0, value : 0};
168 // we want to see all processed holds, so (effectively) remove
170 $scope.gridControls.setLimit(1000, true);
172 // initiate clear shelf and grab cache key
175 'open-ils.circ.hold.clear_shelf.process',
176 egCore.auth.token(), $scope.pickup_ou.id(),
179 // request responses from the clear shelf cache
182 // clear shelf done; fetch the cached results.
187 'open-ils.circ.hold.clear_shelf.get_cache',
188 egCore.auth.token(), resp.cache_key, 1
189 ).then(null, null, handle_clear_cache_resp);
194 // handle streamed clear_shelf progress updates
197 $scope.clear_progress.max = resp.maximum;
199 $scope.clear_progress.value = resp.progress;
205 $scope.print_list_progress = null;
206 $scope.print_shelf_list = function() {
207 var print_holds = [];
208 $scope.print_list_loading = true;
209 $scope.print_list_progress = 0;
211 // collect the full list of holds
214 'open-ils.circ.captured_holds.id_list.on_shelf.retrieve.authoritative.atomic',
215 egCore.auth.token(), $scope.pickup_ou.id()
216 ).then( function(idlist) {
218 egHolds.fetch_holds(idlist).then(
220 console.debug('printing ' + print_holds.length + ' holds');
221 // holds fetched, send to print
224 template : 'hold_shelf_list',
225 scope : {holds : print_holds}
229 function(hold_data) {
230 $scope.print_list_progress++;
231 egHolds.local_flesh(hold_data);
232 print_holds.push(hold_data);
233 hold_data.title = hold_data.mvr.title();
234 hold_data.author = hold_data.mvr.author();
235 hold_data.hold = egCore.idl.toHash(hold_data.hold);
236 hold_data.copy = egCore.idl.toHash(hold_data.copy);
237 hold_data.volume = egCore.idl.toHash(hold_data.volume);
238 hold_data.part = egCore.idl.toHash(hold_data.part);
241 }).finally(function() {
242 $scope.print_list_loading = false;
243 $scope.print_list_progress = null;
251 .controller('HoldsPullListCtrl',
252 ['$scope','$q','$routeParams','$window','$location','egCore','egHolds','egCirc','egGridDataProvider','egHoldGridActions','holdUiSvc',
253 function($scope , $q , $routeParams , $window , $location , egCore , egHolds , egCirc , egGridDataProvider , egHoldGridActions , holdUiSvc) {
254 $scope.detail_hold_id = $routeParams.hold_id;
256 var provider = egGridDataProvider.instance({});
257 $scope.gridDataProvider = provider;
259 $scope.grid_actions = egHoldGridActions;
260 $scope.grid_actions.refresh = function() {
261 holdUiSvc.holds = [];
265 provider.get = function(offset, count) {
267 if (holdUiSvc.holds[offset]) {
268 return provider.arrayNotifier(holdUiSvc.holds, offset, count);
271 var deferred = $q.defer();
277 'open-ils.circ.hold_pull_list.fleshed.stream',
278 egCore.auth.token(), count, offset
280 deferred.resolve, null,
281 function(hold_data) {
282 egHolds.local_flesh(hold_data);
283 holdUiSvc.holds[offset + recv_index++] = hold_data;
284 deferred.notify(hold_data);
288 return deferred.promise;
291 $scope.detail_view = function(action, user_data, items) {
293 $location.path('/circ/holds/pull/' + h.hold.id());
297 $scope.list_view = function(items) {
298 $location.path('/circ/holds/pull');
301 // when the detail hold is fetched (and updated), update the bib
302 // record summary display record id.
303 $scope.set_hold = function(hold_data) {
304 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
307 // By default, this action is hidded from the UI, but leaving it
308 // here in case it's needed in the future
309 $scope.print_list_alt = function() {
310 var url = '/opac/extras/circ/alt_holds_print.html';
311 var win = $window.open(url, '_blank');
312 win.ses = function() {return egCore.auth.token()};
317 $scope.print_list_progress = null;
318 $scope.print_full_list = function() {
319 var print_holds = [];
320 $scope.print_list_loading = true;
321 $scope.print_list_progress = 0;
323 // collect the full list of holds
326 'open-ils.circ.hold_pull_list.fleshed.stream',
327 egCore.auth.token(), 10000, 0
330 console.debug('printing ' + print_holds.length + ' holds');
332 // holds fetched, send to print
335 template : 'hold_pull_list',
336 scope : {holds : print_holds}
340 function(hold_data) {
341 $scope.print_list_progress++;
342 egHolds.local_flesh(hold_data);
343 print_holds.push(hold_data);
344 hold_data.title = hold_data.mvr.title();
345 hold_data.author = hold_data.mvr.author();
346 hold_data.hold = egCore.idl.toHash(hold_data.hold);
347 hold_data.copy = egCore.idl.toHash(hold_data.copy);
348 hold_data.volume = egCore.idl.toHash(hold_data.volume);
349 hold_data.part = egCore.idl.toHash(hold_data.part);
351 ).finally(function() {
352 $scope.print_list_loading = false;
353 $scope.print_list_progress = null;