5 angular.module('egRenewApp',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
8 .config(function($routeProvider, $locationProvider, $compileProvider) {
9 $locationProvider.html5Mode(true);
10 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
12 var resolver = {delay : function(egStartup) {return egStartup.go()}};
14 $routeProvider.when('/circ/renew/renew', {
15 templateUrl: './circ/renew/t_renew',
16 controller: 'RenewCtrl',
20 $routeProvider.when('/circ/renew/renew', {
21 templateUrl: './circ/renew/t_renew',
22 controller: 'RenewCtrl',
26 $routeProvider.otherwise({redirectTo : '/circ/renew/renew'});
32 .controller('RenewCtrl',
33 ['$scope','$window','$location','egCore','egGridDataProvider','egCirc',
34 function($scope , $window , $location , egCore , egGridDataProvider , egCirc) {
36 egCore.hatch.getItem('circ.renew.strict_barcode')
37 .then(function(sb){ $scope.strict_barcode = sb });
38 $scope.focusBarcode = true;
39 $scope.outOfRange = false;
40 $scope.minDate = new Date();
43 var today = new Date();
44 $scope.renewalArgs = {due_date : today};
46 $scope.sort_money = function (a,b) {
47 var ma = parseFloat(a);
48 var mb = parseFloat(b);
49 if (ma < mb) return -1;
50 if (ma > mb) return 1;
54 $scope.gridDataProvider = egGridDataProvider.instance({
55 get : function(offset, count) {
56 return this.arrayNotifier($scope.renewals, offset, count);
60 // avoid multiple, in-flight attempts on the same barcode
61 var pending_barcodes = {};
63 $scope.renew = function(args) {
64 var params = angular.copy(args);
66 if (args.sticky_date) {
67 params.due_date = args.due_date.toISOString();
69 delete params.due_date;
71 delete params.sticky_date;
72 if (!args.copy_barcode) return;
74 args.copy_barcode = ''; // reset UI input
76 if (pending_barcodes[params.copy_barcode]) {
78 "Skipping renewals of redundant barcode "
84 pending_barcodes[params.copy_barcode] = true;
87 $scope.focusBarcode = true; // return focus to barcode input
90 function send_renewal(params) {
92 params.noncat_type = params.noncat ? params.noncat_type : '';
94 // populate the grid row before we send the request so that the
95 // order of actions is maintained and so the user gets an
96 // immediate reaction to their barcode input action.
98 index : $scope.renewals.length,
99 input_barcode : params.copy_barcode,
100 noncat_type : params.noncat_type
103 $scope.renewals.unshift(row_item);
104 $scope.gridDataProvider.refresh();
106 egCore.hatch.setItem('circ.renew.strict_barcode', $scope.strict_barcode);
107 var options = {check_barcode : $scope.strict_barcode};
109 egCirc.renew(params, options).then(
110 function(final_resp) {
112 row_item.evt = final_resp.evt;
113 angular.forEach(final_resp.data, function(val, key) {
117 row_item['copy_barcode'] = row_item.acp.barcode();
120 var amt = Number(row_item.mbts.balance_owed());
122 $scope.billable_barcode = row_item.copy_barcode;
123 $scope.billable_amount = amt;
125 ($scope.fine_total * 100 + amt * 100) / 100;
129 if ($scope.trim_list && checkinSvc.checkins.length > 20)
130 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
134 // Circ was rejected somewhere along the way.
135 // Remove the copy from the grid since there was no action.
136 // note: since renewals are unshifted onto the array, the
137 // index value does not (generally) match the array position.
139 angular.forEach($scope.renewals, function(co, idx) {
140 if (co.index == row_item.index) pos = idx;
142 $scope.renewals.splice(pos, 1);
143 $scope.gridDataProvider.refresh();
146 )['finally'](function() {
148 // regardless of the outcome of the circ, remove the
149 // barcode from the pending list.
150 if (params.copy_barcode)
151 delete pending_barcodes[params.copy_barcode];
155 $scope.fetchLastCircPatron = function(items) {
156 var renewal = items[0];
157 if (!renewal || !renewal.acp) return;
159 egCirc.last_copy_circ(renewal.acp.id())
160 .then(function(circ) {
163 // jump to the patron UI (separate app)
164 $window.location.href = $location
165 .path('/circ/patron/' + circ.usr() + '/checkout')
170 $scope.alert = {item_never_circed : renewal.acp.barcode()};
174 $scope.showMarkDamaged = function(items) {
176 angular.forEach(items, function(item) {
177 if (item.acp) copy_ids.push(item.acp.id());
180 if (copy_ids.length) {
181 egCirc.mark_damaged(copy_ids).then(function() {
182 // update grid items?
187 $scope.showMarkDiscard = function(items) {
189 angular.forEach(items, function(item) {
190 if (item.acp) copies.push(egCore.idl.toHash(item.acp));
194 egCirc.mark_discard(copies).then(function() {
195 // update grid items?
200 $scope.showLastFewCircs = function(items) {
201 if (items.length && (copy = items[0].acp)) {
202 var url = $location.path(
203 '/cat/item/' + copy.id() + '/circ_list').absUrl();
204 $window.open(url, '_blank').focus();
208 $scope.abortTransit = function(items) {
209 var transit_ids = [];
210 angular.forEach(items, function(item) {
211 if (item.transit) transit_ids.push(item.transit.id());
214 egCirc.abort_transits(transit_ids).then(function() {
215 // update grid items?
219 $scope.addCopyAlerts = function(items) {
221 angular.forEach(items, function(item) {
222 if (item.acp) copy_ids.push(item.acp.id());
224 egCirc.add_copy_alerts(copy_ids).then(function() {
225 // update grid items?
229 $scope.manageCopyAlerts = function(items) {
231 angular.forEach(items, function(item) {
232 if (item.acp) copy_ids.push(item.acp.id());
234 egCirc.manage_copy_alerts(copy_ids).then(function() {
235 // update grid items?
239 $scope.print_receipt = function() {
240 var print_data = {circulations : []}
242 if ($scope.renewals.length == 0) return $q.when();
244 angular.forEach($scope.renewals, function(renewal) {
246 print_data.circulations.push({
247 circ : egCore.idl.toHash(renewal.circ),
248 copy : egCore.idl.toHash(renewal.acp),
249 title : egCore.idl.toHash(renewal.title),
250 author : egCore.idl.toHash(renewal.author)
255 return egCore.print.print({