]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/circ/patron/holds.js
holds shelf. actions / clear shelf
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / circ / patron / holds.js
1 /**
2  * List of patron holds
3  */
4
5 angular.module('egPatronApp').controller('PatronHoldsCtrl',
6
7        ['$scope','$q','$routeParams','egCore','egUser','patronSvc',
8         'egGridDataProvider','egHolds','$window','$location','egCirc',
9 function($scope,  $q,  $routeParams,  egCore,  egUser,  patronSvc,  
10         egGridDataProvider , egHolds , $window , $location , egCirc) {
11
12     $scope.initTab('holds', $routeParams.id);
13     $scope.holds_display = 'main';
14     $scope.detail_hold_id = $routeParams.hold_id;
15
16     function refresh_all() {
17         patronSvc.refreshPrimary();
18         patronSvc.holds = [];
19         patronSvc.hold_ids = [];
20         provider.refresh() 
21     }
22
23     $scope.show_main_list = function() {
24         // don't need a full reset_page() to swap tabs
25         $scope.holds_display = 'main';
26         patronSvc.holds = [];
27         patronSvc.hold_ids = [];
28         provider.refresh();
29     }
30
31     $scope.show_alt_list = function() {
32         // don't need a full reset_page() to swap tabs
33         $scope.holds_display = 'alt';
34         patronSvc.holds = [];
35         patronSvc.hold_ids = [];
36         provider.refresh();
37     }
38
39     var provider = egGridDataProvider.instance({});
40     $scope.gridDataProvider = provider;
41
42     function fetchHolds(offset, count) {
43         var ids = patronSvc.hold_ids.slice(offset, offset + count);
44         return egHolds.fetch_holds(ids).then(
45             function() { $scope.loading = false; },
46             null,
47             function(hold_data) { patronSvc.holds.push(hold_data) }
48         );
49     }
50
51     provider.get = function(offset, count) {
52
53         // see if we have the requested range cached
54         if (patronSvc.holds[offset]) {
55             return provider.arrayNotifier(patronSvc.holds, offset, count);
56         }
57
58         // see if we have the holds IDs for this range already loaded
59         if (patronSvc.hold_ids[offset]) {
60             return fetchHolds(offset, count);
61         }
62
63         var deferred = $q.defer();
64         patronSvc.hold_ids = [];
65
66         var method = 'open-ils.circ.holds.id_list.retrieve.authoritative';
67         if ($scope.holds_display == 'alt')
68             method = 'open-ils.circ.holds.canceled.id_list.retrieve.authoritative';
69
70         egCore.net.request(
71             'open-ils.circ', method,
72             egCore.auth.token(), $scope.patron_id
73
74         ).then(function(hold_ids) {
75             if (!hold_ids.length) { deferred.resolve(); return; }
76
77             patronSvc.hold_ids = hold_ids;
78             fetchHolds(offset, count)
79             .then(deferred.resolve, null, deferred.notify);
80         });
81
82         return deferred.promise;
83     }
84
85     $scope.cancel_hold = function(items) {
86         var hold_ids = items.filter(function(item) {
87             return !item.hold.cancel_time();
88         }).map(function(item) {return item.hold.id()});
89
90         return egHolds.cancel_holds(hold_ids).then(refresh_all);
91     }
92
93     // jump to circ list for either 1) the targeted copy or
94     // 2) the hold target copy for copy-level holds
95     $scope.show_recent_circs = function(items) {
96         if (items.length && (copy = items[0].copy)) {
97             var url = $location.path(
98                 '/cat/item/' + copy.id() + '/circ_list').absUrl();
99             $window.open(url, '_blank').focus();
100         }
101     }
102
103     function generic_update(items, action) {
104         if (!items.length) return $q.when();
105         var hold_ids = items.map(function(item) {return item.hold.id()});
106         return egHolds[action](hold_ids).then(refresh_all);
107     }
108
109     $scope.set_copy_quality = function(items) {
110         generic_update(items, 'set_copy_quality'); }
111     $scope.edit_pickup_lib = function(items) {
112         generic_update(items, 'edit_pickup_lib'); }
113     $scope.edit_notify_prefs = function(items) {
114         generic_update(items, 'edit_notify_prefs'); }
115     $scope.edit_dates = function(items) {
116         generic_update(items, 'edit_dates'); }
117     $scope.suspend = function(items) {
118         generic_update(items, 'suspend_holds'); }
119     $scope.activate = function(items) {
120         generic_update(items, 'activate_holds'); }
121     $scope.set_top_of_queue = function(items) {
122         generic_update(items, 'set_top_of_queue'); }
123     $scope.clear_top_of_queue = function(items) {
124         generic_update(items, 'clear_top_of_queue'); }
125     $scope.transfer_to_marked_title = function(items) {
126         generic_update(items, 'transfer_to_marked_title'); }
127
128     $scope.mark_damaged = function(items) {
129         var copy_ids = items
130             .filter(function(item) { return Boolean(item.copy) })
131             .map(function(item) { return item.copy.id() });
132         if (copy_ids.length) 
133             egCirc.mark_damaged(copy_ids).then(refresh_all);
134     }
135     $scope.mark_missing = function(items) {
136         var copy_ids = items
137             .filter(function(item) { return Boolean(item.copy) })
138             .map(function(item) { return item.copy.id() });
139         if (copy_ids.length) 
140             egCirc.mark_missing(copy_ids).then(refresh_all);
141     }
142
143     $scope.retarget = function(items) {
144         var hold_ids = items.map(function(item) { return item.hold.id() });
145         egHolds.retarget(hold_ids).then(refresh_all);
146     }
147
148     $scope.print = function() {
149         var holds = [];
150         angular.forEach(patronSvc.holds, function(item) {
151             holds.push({
152                 hold : egCore.idl.toHash(item.hold),
153                 copy : egCore.idl.toHash(item.copy),
154                 volume : egCore.idl.toHash(item.volume),
155                 title : item.mvr.title(),
156                 author : item.mvr.author()
157             });
158         });
159
160         egCore.print.print({
161             context : 'receipt', 
162             template : 'holds_for_patron', 
163             scope : {holds : holds}
164         });
165     }
166
167     $scope.detail_view = function(action, user_data, items) {
168         if (h = items[0]) {
169             $location.path('/circ/patron/' + 
170                 $scope.patron_id + '/holds/' + h.hold.id());
171         }
172     }
173
174     $scope.list_view = function(items) {
175         $location.path('/circ/patron/' + $scope.patron_id + '/holds');
176     }
177
178     // when the detail hold is fetched (and updated), update the bib
179     // record summary display record id.
180     $scope.set_hold = function(hold_data) {
181         $scope.detail_hold_record_id = hold_data.mvr.doc_id();
182     }
183
184 }])