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 var ids = patronSvc.hold_ids.slice(offset, offset + count);
54 return egHolds.fetch_holds(ids).then(null, null,
56 patronSvc.holds.push(hold_data);
62 provider.get = function(offset, count) {
64 // see if we have the requested range cached
65 if (patronSvc.holds[offset]) {
66 return provider.arrayNotifier(patronSvc.holds, offset, count);
69 // see if we have the holds IDs for this range already loaded
70 if (patronSvc.hold_ids[offset]) {
71 return fetchHolds(offset, count);
74 var deferred = $q.defer();
75 patronSvc.hold_ids = [];
77 var method = 'open-ils.circ.holds.id_list.retrieve.authoritative';
78 if ($scope.holds_display == 'alt')
79 method = 'open-ils.circ.holds.canceled.id_list.retrieve.authoritative';
82 'open-ils.circ', method,
83 egCore.auth.token(), $scope.patron_id
85 ).then(function(hold_ids) {
86 if (!hold_ids.length) { deferred.resolve(); return; }
88 patronSvc.hold_ids = hold_ids;
89 fetchHolds(offset, count)
90 .then(deferred.resolve, null, deferred.notify);
93 return deferred.promise;
96 $scope.print = function() {
98 angular.forEach(patronSvc.holds, function(item) {
100 hold : egCore.idl.toHash(item.hold),
101 copy : egCore.idl.toHash(item.copy),
102 volume : egCore.idl.toHash(item.volume),
103 title : item.mvr.title(),
104 author : item.mvr.author()
110 template : 'holds_for_patron',
111 scope : {holds : holds}
115 $scope.detail_view = function(action, user_data, items) {
117 $location.path('/circ/patron/' +
118 $scope.patron_id + '/holds/' + h.hold.id());
122 $scope.list_view = function(items) {
123 $location.path('/circ/patron/' + $scope.patron_id + '/holds');
126 $scope.place_hold = function() {
127 $location.path($location.path() + '/create');
130 // when the detail hold is fetched (and updated), update the bib
131 // record summary display record id.
132 $scope.set_hold = function(hold_data) {
133 $scope.detail_hold_record_id = hold_data.mvr.doc_id();
139 .controller('PatronHoldsCreateCtrl',
140 ['$scope','$routeParams','$location','egCore','patronSvc',
141 function($scope , $routeParams , $location , egCore , patronSvc) {
144 opac_hold_placed : function() {
145 // FIXME: this isn't getting called.. not sure why
146 patronSvc.fetchUserStats(); // update hold counts
150 $scope.initTab('holds', $routeParams.id).then(function(isAlert) {
152 // not guarenteed to have a barcode until init fetches the user
153 $scope.handlers.patron_barcode = patronSvc.current.card().barcode();
157 $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
159 $scope.handle_page = function(url) {