5 angular.module('egPatronApp').controller('PatronHoldsCtrl',
7 ['$scope','$q','$routeParams','egCore','egUser','patronSvc',
8 'egGridDataProvider','egHolds','$window','$location','egCirc','egHoldGridActions',
9 function($scope, $q, $routeParams, egCore, egUser, patronSvc,
10 egGridDataProvider , egHolds , $window , $location , egCirc, egHoldGridActions) {
12 $scope.initTab('holds', $routeParams.id);
13 $scope.holds_display = 'main';
14 $scope.detail_hold_id = $routeParams.hold_id;
15 $scope.grid_actions = egHoldGridActions;
17 function refresh_all() {
18 patronSvc.refreshPrimary();
20 patronSvc.hold_ids = [];
23 $scope.grid_actions.refresh = refresh_all;
25 $scope.show_main_list = function() {
26 // don't need a full reset_page() to swap tabs
27 $scope.holds_display = 'main';
29 patronSvc.hold_ids = [];
33 $scope.show_alt_list = function() {
34 // don't need a full reset_page() to swap tabs
35 $scope.holds_display = 'alt';
37 patronSvc.hold_ids = [];
41 $scope.hide_cancel_hold = function(action) {
42 return $scope.holds_display == 'alt';
45 $scope.hide_uncancel_hold = function(action) {
46 return !$scope.hide_cancel_hold();
49 var provider = egGridDataProvider.instance({});
50 $scope.gridDataProvider = provider;
52 function fetchHolds(offset, count) {
53 // TODO: LP#1697954 Fetch all holds on grid render to support
54 // client-side sorting. Migrate to server-side sorting to avoid
55 // the need for fetching all items.
57 // we're going to just fetch all the holds up front
58 //var ids = patronSvc.hold_ids.slice(offset, offset + count);
59 return egHolds.fetch_holds(patronSvc.hold_ids).then(null, null,
61 egCirc.flesh_copy_circ_library(hold_data.copy);
62 patronSvc.holds.push(hold_data);
68 provider.get = function(offset, count) {
70 // see if we have the requested range cached
71 if (patronSvc.holds[offset]) {
72 return provider.arrayNotifier(patronSvc.holds, offset, count);
75 // see if we have the holds IDs for this range already loaded
76 if (patronSvc.hold_ids[offset]) {
77 return fetchHolds(offset, count);
80 var deferred = $q.defer();
81 patronSvc.hold_ids = [];
83 var method = 'open-ils.circ.holds.id_list.retrieve.authoritative';
84 if ($scope.holds_display == 'alt')
85 method = 'open-ils.circ.holds.canceled.id_list.retrieve.authoritative';
89 'open-ils.circ', method,
90 egCore.auth.token(), $scope.patron_id
92 ).then(function(hold_ids) {
93 if (!hold_ids.length) { deferred.resolve(); return; }
95 patronSvc.hold_ids = hold_ids;
96 fetchHolds(offset, count)
97 .then(deferred.resolve, null, function (data) {
99 if (current >= offset && current < count) {
100 deferred.notify(data);
107 return deferred.promise;
110 $scope.print = function() {
112 angular.forEach(patronSvc.holds, function(item) {
114 hold : egCore.idl.toHash(item.hold),
115 copy : egCore.idl.toHash(item.copy),
116 volume : egCore.idl.toHash(item.volume),
117 title : item.mvr.title(),
118 author : item.mvr.author()
124 template : 'holds_for_patron',
125 scope : {holds : holds}
129 $scope.detail_view = function(action, user_data, items) {
131 $location.path('/circ/patron/' +
132 $scope.patron_id + '/holds/' + h.hold.id());
136 $scope.list_view = function(items) {
137 $location.path('/circ/patron/' + $scope.patron_id + '/holds');
140 $scope.place_hold = function() {
141 $location.path($location.path() + '/create');
144 // when the detail hold is fetched (and updated), update the bib
145 // record summary display record id.
146 $scope.set_hold = function(hold_data) {
147 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
153 .controller('PatronHoldsCreateCtrl',
154 ['$scope','$routeParams','$location','egCore','egWorkLog','patronSvc',
155 function($scope , $routeParams , $location , egCore , egWorkLog , patronSvc) {
158 opac_hold_placed : function(hold) {
159 patronSvc.fetchUserStats(); // update hold counts
161 egCore.strings.EG_WORK_LOG_REQUESTED_HOLD,{
162 'action' : 'requested_hold',
163 'patron_id' : patronSvc.current.id(),
170 $scope.initTab('holds', $routeParams.id).then(function(isAlert) {
172 // not guarenteed to have a barcode until init fetches the user
173 $scope.handlers.patron_barcode = patronSvc.current.card().barcode();
177 $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
179 $scope.handle_page = function(url) {