]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/circ/patron/holds.js
LP#1350042 Browser client templates/scripts (phase 1)
[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','egHoldGridActions',
9 function($scope,  $q,  $routeParams,  egCore,  egUser,  patronSvc,  
10         egGridDataProvider , egHolds , $window , $location , egCirc, egHoldGridActions) {
11
12     $scope.initTab('holds', $routeParams.id);
13     $scope.holds_display = 'main';
14     $scope.detail_hold_id = $routeParams.hold_id;
15     $scope.grid_actions = egHoldGridActions;
16
17     function refresh_all() {
18         patronSvc.refreshPrimary();
19         patronSvc.holds = [];
20         patronSvc.hold_ids = [];
21         provider.refresh() 
22     }
23     $scope.grid_actions.refresh = refresh_all;
24
25     $scope.show_main_list = function() {
26         // don't need a full reset_page() to swap tabs
27         $scope.holds_display = 'main';
28         patronSvc.holds = [];
29         patronSvc.hold_ids = [];
30         provider.refresh();
31     }
32
33     $scope.show_alt_list = function() {
34         // don't need a full reset_page() to swap tabs
35         $scope.holds_display = 'alt';
36         patronSvc.holds = [];
37         patronSvc.hold_ids = [];
38         provider.refresh();
39     }
40
41     var provider = egGridDataProvider.instance({});
42     $scope.gridDataProvider = provider;
43
44     function fetchHolds(offset, count) {
45         var ids = patronSvc.hold_ids.slice(offset, offset + count);
46         return egHolds.fetch_holds(ids).then(null, null,
47             function(hold_data) { 
48                 patronSvc.holds.push(hold_data);
49                 return hold_data;
50             }
51         );
52     }
53
54     provider.get = function(offset, count) {
55
56         // see if we have the requested range cached
57         if (patronSvc.holds[offset]) {
58             return provider.arrayNotifier(patronSvc.holds, offset, count);
59         }
60
61         // see if we have the holds IDs for this range already loaded
62         if (patronSvc.hold_ids[offset]) {
63             return fetchHolds(offset, count);
64         }
65
66         var deferred = $q.defer();
67         patronSvc.hold_ids = [];
68
69         var method = 'open-ils.circ.holds.id_list.retrieve.authoritative';
70         if ($scope.holds_display == 'alt')
71             method = 'open-ils.circ.holds.canceled.id_list.retrieve.authoritative';
72
73         egCore.net.request(
74             'open-ils.circ', method,
75             egCore.auth.token(), $scope.patron_id
76
77         ).then(function(hold_ids) {
78             if (!hold_ids.length) { deferred.resolve(); return; }
79
80             patronSvc.hold_ids = hold_ids;
81             fetchHolds(offset, count)
82             .then(deferred.resolve, null, deferred.notify);
83         });
84
85         return deferred.promise;
86     }
87
88     $scope.print = function() {
89         var holds = [];
90         angular.forEach(patronSvc.holds, function(item) {
91             holds.push({
92                 hold : egCore.idl.toHash(item.hold),
93                 copy : egCore.idl.toHash(item.copy),
94                 volume : egCore.idl.toHash(item.volume),
95                 title : item.mvr.title(),
96                 author : item.mvr.author()
97             });
98         });
99
100         egCore.print.print({
101             context : 'receipt', 
102             template : 'holds_for_patron', 
103             scope : {holds : holds}
104         });
105     }
106
107     $scope.detail_view = function(action, user_data, items) {
108         if (h = items[0]) {
109             $location.path('/circ/patron/' + 
110                 $scope.patron_id + '/holds/' + h.hold.id());
111         }
112     }
113
114     $scope.list_view = function(items) {
115         $location.path('/circ/patron/' + $scope.patron_id + '/holds');
116     }
117
118     $scope.place_hold = function() {
119         $location.path($location.path() + '/create');
120     }
121
122     // when the detail hold is fetched (and updated), update the bib
123     // record summary display record id.
124     $scope.set_hold = function(hold_data) {
125         $scope.detail_hold_record_id = hold_data.mvr.doc_id();
126     }
127
128 }])
129
130
131 .controller('PatronHoldsCreateCtrl',
132        ['$scope','$routeParams','$location','egCore','patronSvc',
133 function($scope , $routeParams , $location , egCore , patronSvc) {
134
135     $scope.handlers = {
136         opac_hold_placed : function() {
137             // FIXME: this isn't getting called.. not sure why
138             patronSvc.fetchUserStats(); // update hold counts
139         }
140     }
141
142     $scope.initTab('holds', $routeParams.id).then(function(isAlert) {
143         if (isAlert) return;
144         // not guarenteed to have a barcode until init fetches the user
145         $scope.handlers.patron_barcode = patronSvc.current.card().barcode();
146     });
147
148     $scope.catalog_url = 
149         $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
150
151     $scope.handle_page = function(url) {
152     }
153
154 }])
155