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','egProgressDialog',
41 function($scope , $q , $routeParams , $window , $location , egCore , egHolds , egHoldGridActions , egCirc , egGridDataProvider , egProgressDialog) {
42 $scope.detail_hold_id = $routeParams.hold_id;
46 var clear_mode = false;
47 $scope.gridControls = {};
48 $scope.grid_actions = egHoldGridActions;
50 var provider = egGridDataProvider.instance({});
51 $scope.gridDataProvider = provider;
53 function refresh_page() {
59 // called after any egHoldGridActions action occurs
60 $scope.grid_actions.refresh = refresh_page;
62 provider.get = function(offset, count) {
64 // see if we have the requested range cached
66 return provider.arrayNotifier(holds, offset, count);
69 // if in clear mode...
70 if (clear_mode && holds.length) {
71 holds = holds.filter(function(h) { return h.hold.clear_me == 't' });
77 is_staff_request : 'true',
78 capture_time : { not : null },
79 cs_id : 8, // on holds shelf
80 fulfillment_time : null,
81 current_shelf_lib : $scope.pickup_ou.id()
84 var order_by = [{ capture_time : null }];
85 if (provider.sort && provider.sort.length) {
87 angular.forEach(provider.sort, function (c) {
88 if (!angular.isObject(c)) {
89 if (c.match(/^hold\./)) {
90 var i = c.replace('hold.','');
96 var i = Object.keys(c)[0];
98 if (i.match(/^hold\./)) {
99 i = i.replace('hold.','');
101 ob[i] = {dir:direction};
108 egProgressDialog.open({max : 1, value : 0});
110 return egHolds.fetch_wide_holds(
114 return provider.arrayNotifier(holds, offset, count);
117 function(hold_data) {
119 hold_count = hold_data;
121 egProgressDialog.update({max:hold_count});
123 egProgressDialog.increment();
124 var new_item = { id : hold_data.id, hold : hold_data };
125 new_item.status_string =
126 egCore.strings['HOLD_STATUS_' + hold_data.hold_status]
127 || hold_data.hold_status;
130 if (hold_data.clear_me == 't') holds.push(new_item);
132 holds.push(new_item);
136 ).finally(egProgressDialog.close);
139 // re-draw the grid when user changes the org selector
140 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
141 $scope.$watch('pickup_ou', function(newVal, oldVal) {
142 if (newVal && newVal != oldVal)
146 $scope.detail_view = function(action, user_data, items) {
148 $location.path('/circ/holds/shelf/' + h.hold.id);
152 $scope.list_view = function(items) {
153 $location.path('/circ/holds/shelf');
156 // when the detail hold is fetched (and updated), update the bib
157 // record summary display record id.
158 $scope.set_hold = function(hold_data) {
159 $scope.detail_hold_record_id = hold_data.hold.record_id;
162 // manage active vs. clearable holds display
163 var clearing = false; // true if actively clearing holds (below)
164 $scope.is_clearing = function() { return clearing };
165 $scope.active_mode = function() {return !clear_mode}
166 $scope.clear_mode = function() {return clear_mode}
167 $scope.show_clearable = function() { clear_mode = true; refresh_page() }
168 $scope.show_active = function() { clear_mode = false; refresh_page() }
169 $scope.disable_clear = function() { return clearing || !clear_mode }
171 // udpate the in-grid hold with the clear-shelf cached response info.
172 function handle_clear_cache_resp(resp) {
173 if (!angular.isArray(resp)) resp = [resp];
174 angular.forEach(resp, function(info) {
176 var grid_item = holds.filter(function(item) {
177 return item.hold.id == info.hold_details.id
180 // there will be no grid item if the hold is off-page
182 grid_item.post_clear =
183 egCore.strings['CLEAR_SHELF_ACTION_' + info.action];
189 $scope.clear_holds = function() {
191 $scope.clear_progress = {max : 0, value : 0};
193 // we want to see all processed holds, so (effectively) remove
195 $scope.gridControls.setLimit(1000, true);
197 // initiate clear shelf and grab cache key
200 'open-ils.circ.hold.clear_shelf.process',
201 egCore.auth.token(), $scope.pickup_ou.id(),
204 // request responses from the clear shelf cache
207 // clear shelf done; fetch the cached results.
212 'open-ils.circ.hold.clear_shelf.get_cache',
213 egCore.auth.token(), resp.cache_key, 1
214 ).then(null, null, handle_clear_cache_resp);
219 // handle streamed clear_shelf progress updates
222 $scope.clear_progress.max = resp.maximum;
224 $scope.clear_progress.value = resp.progress;
230 function map_prefix_to_subhash (h,pf) {
232 angular.forEach(Object.keys(h), function (k) {
233 if (k.startsWith(pf)) {
234 var nk = k.substr(pf.length);
241 $scope.print_shelf_list = function() {
242 var print_holds = [];
243 angular.forEach(holds, function(hold_data) {
245 print_holds.push(phold);
247 phold.status_string = hold_data.status_string;
249 phold.patron_first = hold_data.hold.usr_first_given_name;
250 phold.patron_last = hold_data.hold.usr_family_name;
251 phold.patron_alias = hold_data.hold.usr_alias;
252 phold.patron_barcode = hold_data.hold.ucard_barcode;
254 phold.title = hold_data.hold.title;
255 phold.author = hold_data.hold.author;
257 phold.hold = hold_data.hold;
258 phold.copy = map_prefix_to_subhash(hold_data.hold, 'cp_');
259 phold.volume = map_prefix_to_subhash(hold_data.hold, 'cn_');
260 phold.part = map_prefix_to_subhash(hold_data.hold, 'p_');
263 console.log(print_holds);
265 return egCore.print.print({
267 template : 'hold_shelf_list',
268 scope : {holds : print_holds}
276 .controller('HoldsPullListCtrl',
277 ['$scope','$q','$routeParams','$window','$location','egCore',
278 'egHolds','egCirc','egHoldGridActions','egProgressDialog',
279 function($scope , $q , $routeParams , $window , $location , egCore ,
280 egHolds , egCirc , egHoldGridActions , egProgressDialog) {
282 $scope.detail_hold_id = $routeParams.hold_id;
284 var cached_details = {};
285 var details_needed = {};
287 $scope.gridControls = {
288 setQuery : function() {
289 return {'copy_circ_lib_id' : egCore.auth.user().ws_ou()}
291 setSort : function() {
292 return ['copy_location_order_position','call_number_sort_key']
294 collectStarted : function(offset) {
295 // Launch an indeterminate -> semi-determinate progress
296 // modal. Using a determinate modal that starts counting
297 // on the post-grid holds data retrieval results in a modal
298 // that's stuck at 0% for most of its life, which is aggravating.
299 egProgressDialog.open();
301 itemRetrieved : function(item) {
302 egProgressDialog.increment();
303 if (!cached_details[item.id]) {
304 details_needed[item.id] = item;
307 allItemsRetrieved : function() {
308 flesh_holds().finally(egProgressDialog.close);
313 // Fetches hold detail data for each hold in the grid and links
314 // the detail data to the related grid item so egHoldGridActions
315 // and friends have access to holds data they understand.
316 // Only fetch not-yet-cached data.
317 function flesh_holds() {
318 egProgressDialog.increment();
320 // Start by fleshing hold details from our cached data.
321 var items = $scope.gridControls.allItems();
322 angular.forEach(items, function(item) {
323 if (!cached_details[item.id]) return $q.when();
324 angular.forEach(cached_details[item.id],
325 function(val, key) { item[key] = val })
328 // Exit if all needed details were already cached
329 if (Object.keys(details_needed).length == 0) return $q.when();
331 return egCore.net.request(
333 'open-ils.circ.hold.details.batch.retrieve.authoritative',
334 egCore.auth.token(), Object.keys(details_needed), {
338 ).then(null, null, function(hold_info) {
339 egProgressDialog.increment();
341 // check if this is a staff-created hold
342 // i.e., requestor is not the same as the user
343 hold_info['_is_staff_hold'] = hold_info.hold.requestor() != hold_info.hold.usr().id();
345 var hold_id = hold_info.hold.id();
346 cached_details[hold_id] = hold_info;
347 var item = details_needed[hold_id];
348 delete details_needed[hold_id];
350 // flesh the grid item from the blob of hold data.
351 angular.forEach(hold_info,
352 function(val, key) { item[key] = val });
357 $scope.grid_actions = egHoldGridActions;
358 $scope.grid_actions.refresh = function() {
359 cached_details = {}; // un-cache details after edit actions.
360 $scope.gridControls.refresh();
363 $scope.detail_view = function(action, user_data, items) {
365 $location.path('/circ/holds/pull/' + h.hold.id());
369 $scope.list_view = function(items) {
370 $location.path('/circ/holds/pull');
373 // when the detail hold is fetched (and updated), update the bib
374 // record summary display record id.
375 $scope.set_hold = function(hold_data) {
376 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
379 // By default, this action is hidded from the UI, but leaving it
380 // here in case it's needed in the future
381 $scope.print_list_alt = function() {
382 var url = '/opac/extras/circ/alt_holds_print.html';
383 var win = $window.open(url, '_blank');
384 win.ses = function() {return egCore.auth.token()};
389 $scope.print_full_list = function() {
390 var print_holds = [];
391 egProgressDialog.open({value : 0});
393 // collect the full list of holds
396 'open-ils.circ.hold_pull_list.fleshed.stream',
397 egCore.auth.token(), 10000, 0
400 console.debug('printing ' + print_holds.length + ' holds');
402 // holds fetched, send to print
405 template : 'hold_pull_list',
406 scope : {holds : print_holds}
410 function(hold_data) {
411 egProgressDialog.increment();
412 egHolds.local_flesh(hold_data);
413 print_holds.push(hold_data);
414 hold_data.title = hold_data.mvr.title();
415 hold_data.author = hold_data.mvr.author();
416 hold_data.hold = egCore.idl.toHash(hold_data.hold);
417 hold_data.copy = egCore.idl.toHash(hold_data.copy);
418 hold_data.volume = egCore.idl.toHash(hold_data.volume);
419 hold_data.part = egCore.idl.toHash(hold_data.part);
421 ).finally(egProgressDialog.close);