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);
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;
209 .controller('HoldsPullListCtrl',
210 ['$scope','$q','$routeParams','$window','$location','egCore','egHolds','egCirc','egGridDataProvider','egHoldGridActions','holdUiSvc',
211 function($scope , $q , $routeParams , $window , $location , egCore , egHolds , egCirc , egGridDataProvider , egHoldGridActions , holdUiSvc) {
212 $scope.detail_hold_id = $routeParams.hold_id;
214 var provider = egGridDataProvider.instance({});
215 $scope.gridDataProvider = provider;
217 $scope.grid_actions = egHoldGridActions;
218 $scope.grid_actions.refresh = function() {
219 holdUiSvc.holds = [];
223 provider.get = function(offset, count) {
225 if (holdUiSvc.holds[offset]) {
226 return provider.arrayNotifier(holdUiSvc.holds, offset, count);
229 var deferred = $q.defer();
235 'open-ils.circ.hold_pull_list.fleshed.stream',
236 egCore.auth.token(), count, offset
238 deferred.resolve, null,
239 function(hold_data) {
240 egHolds.local_flesh(hold_data);
241 holdUiSvc.holds[offset + recv_index++] = hold_data;
242 deferred.notify(hold_data);
246 return deferred.promise;
249 $scope.detail_view = function(action, user_data, items) {
251 $location.path('/circ/holds/pull/' + h.hold.id());
255 $scope.list_view = function(items) {
256 $location.path('/circ/holds/pull');
259 // when the detail hold is fetched (and updated), update the bib
260 // record summary display record id.
261 $scope.set_hold = function(hold_data) {
262 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
265 // By default, this action is hidded from the UI, but leaving it
266 // here in case it's needed in the future
267 $scope.print_list_alt = function() {
268 var url = '/opac/extras/circ/alt_holds_print.html';
269 var win = $window.open(url, '_blank');
270 win.ses = function() {return egCore.auth.token()};
275 $scope.print_list_progress = null;
276 $scope.print_full_list = function() {
277 var print_holds = [];
278 $scope.print_list_loading = true;
279 $scope.print_list_progress = 0;
281 // collect the full list of holds
284 'open-ils.circ.hold_pull_list.fleshed.stream',
285 egCore.auth.token(), 10000, 0
288 console.debug('printing ' + print_holds.length + ' holds');
290 // holds fetched, send to print
293 template : 'hold_pull_list',
294 scope : {holds : print_holds}
298 function(hold_data) {
299 $scope.print_list_progress++;
300 egHolds.local_flesh(hold_data);
301 print_holds.push(hold_data);
302 hold_data.title = hold_data.mvr.title();
303 hold_data.author = hold_data.mvr.author();
304 hold_data.hold = egCore.idl.toHash(hold_data.hold);
305 hold_data.copy = egCore.idl.toHash(hold_data.copy);
306 hold_data.volume = egCore.idl.toHash(hold_data.volume);
307 hold_data.part = egCore.idl.toHash(hold_data.part);
309 ).finally(function() {
310 $scope.print_list_loading = false;
311 $scope.print_list_progress = null;