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(patronSvc.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);
172 // initiate clear shelf and grab cache key
175 'open-ils.circ.hold.clear_shelf.process',
176 egCore.auth.token(), $scope.pickup_ou.id()
178 // request responses from the clear shelf cache
181 // clear shelf done; fetch the cached results.
186 'open-ils.circ.hold.clear_shelf.get_cache',
187 egCore.auth.token(), resp.cache_key
188 ).then(null, null, handle_clear_cache_resp);
193 // handle streamed clear_shelf progress updates
196 $scope.clear_progress.max = resp.maximum;
198 $scope.clear_progress.value = resp.progress;
208 .controller('HoldsPullListCtrl',
209 ['$scope','$q','$routeParams','$window','$location','egCore','egHolds','egCirc','egGridDataProvider','egHoldGridActions','holdUiSvc',
210 function($scope , $q , $routeParams , $window , $location , egCore , egHolds , egCirc , egGridDataProvider , egHoldGridActions , holdUiSvc) {
211 $scope.detail_hold_id = $routeParams.hold_id;
213 var provider = egGridDataProvider.instance({});
214 $scope.gridDataProvider = provider;
216 $scope.grid_actions = egHoldGridActions;
217 $scope.grid_actions.refresh = function() {
218 holdUiSvc.holds = [];
222 provider.get = function(offset, count) {
224 if (holdUiSvc.holds[offset]) {
225 return provider.arrayNotifier(holdUiSvc.holds, offset, count);
228 var deferred = $q.defer();
234 'open-ils.circ.hold_pull_list.fleshed.stream',
235 egCore.auth.token(), count, offset
237 deferred.resolve, null,
238 function(hold_data) {
239 egHolds.local_flesh(hold_data);
240 holdUiSvc.holds[offset + recv_index++] = hold_data;
241 deferred.notify(hold_data);
245 return deferred.promise;
248 $scope.detail_view = function(action, user_data, items) {
250 $location.path('/circ/holds/pull/' + h.hold.id());
254 $scope.list_view = function(items) {
255 $location.path('/circ/holds/pull');
258 // when the detail hold is fetched (and updated), update the bib
259 // record summary display record id.
260 $scope.set_hold = function(hold_data) {
261 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
264 // By default, this action is hidded from the UI, but leaving it
265 // here in case it's needed in the future
266 $scope.print_list_alt = function() {
267 var url = '/opac/extras/circ/alt_holds_print.html';
268 var win = $window.open(url, '_blank');
269 win.ses = function() {return egCore.auth.token()};
274 $scope.print_list_progress = null;
275 $scope.print_full_list = function() {
276 var print_holds = [];
277 $scope.print_list_loading = true;
278 $scope.print_list_progress = 0;
280 // collect the full list of holds
283 'open-ils.circ.hold_pull_list.fleshed.stream',
284 egCore.auth.token(), 10000, 0
287 console.debug('printing ' + print_holds.length + ' holds');
289 // holds fetched, send to print
292 template : 'hold_pull_list',
293 scope : {holds : print_holds}
297 function(hold_data) {
298 $scope.print_list_progress++;
299 egHolds.local_flesh(hold_data);
300 print_holds.push(hold_data);
301 hold_data.title = hold_data.mvr.title();
302 hold_data.author = hold_data.mvr.author();
303 hold_data.hold = egCore.idl.toHash(hold_data.hold);
304 hold_data.copy = egCore.idl.toHash(hold_data.copy);
305 hold_data.volume = egCore.idl.toHash(hold_data.volume);
306 hold_data.part = egCore.idl.toHash(hold_data.part);
308 ).finally(function() {
309 $scope.print_list_loading = false;
310 $scope.print_list_progress = null;