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?|blob):/); // grid export
11 var resolver = {delay : function(egStartup) {return egStartup.go()}};
13 $routeProvider.when('/circ/renew/renew', {
14 templateUrl: './circ/renew/t_renew',
15 controller: 'RenewCtrl',
19 $routeProvider.when('/circ/renew/renew', {
20 templateUrl: './circ/renew/t_renew',
21 controller: 'RenewCtrl',
25 $routeProvider.otherwise({redirectTo : '/circ/renew/renew'});
31 .controller('RenewCtrl',
32 ['$scope','$window','$location','egCore','egGridDataProvider','egCirc',
33 function($scope , $window , $location , egCore , egGridDataProvider , egCirc) {
35 egCore.hatch.getItem('circ.renew.strict_barcode')
36 .then(function(sb){ $scope.strict_barcode = sb });
37 $scope.focusBarcode = true;
40 var today = new Date();
41 $scope.renewalArgs = {due_date : today};
43 $scope.gridDataProvider = egGridDataProvider.instance({
44 get : function(offset, count) {
45 return this.arrayNotifier($scope.renewals, offset, count);
49 // avoid multiple, in-flight attempts on the same barcode
50 var pending_barcodes = {};
52 $scope.renew = function(args) {
53 var params = angular.copy(args);
55 if (args.sticky_date) {
56 params.due_date = args.due_date.toISOString();
58 delete params.due_date;
60 delete params.sticky_date;
61 if (!args.copy_barcode) return;
63 args.copy_barcode = ''; // reset UI input
65 if (pending_barcodes[params.copy_barcode]) {
67 "Skipping renewals of redundant barcode "
73 pending_barcodes[params.copy_barcode] = true;
76 $scope.focusBarcode = true; // return focus to barcode input
79 function send_renewal(params) {
81 params.noncat_type = params.noncat ? params.noncat_type : '';
83 // populate the grid row before we send the request so that the
84 // order of actions is maintained and so the user gets an
85 // immediate reaction to their barcode input action.
87 index : $scope.renewals.length,
88 copy_barcode : params.copy_barcode,
89 noncat_type : params.noncat_type
92 $scope.renewals.unshift(row_item);
93 $scope.gridDataProvider.refresh();
95 egCore.hatch.setItem('circ.renew.strict_barcode', $scope.strict_barcode);
96 var options = {check_barcode : $scope.strict_barcode};
98 egCirc.renew(params, options).then(
99 function(final_resp) {
101 row_item.evt = final_resp.evt;
102 angular.forEach(final_resp.data, function(val, key) {
107 var amt = Number(row_item.mbts.balance_owed());
109 $scope.billable_barcode = row_item.copy_barcode;
110 $scope.billable_amount = amt;
112 ($scope.fine_total * 100 + amt * 100) / 100;
116 if ($scope.trim_list && checkinSvc.checkins.length > 20)
117 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
121 // Circ was rejected somewhere along the way.
122 // Remove the copy from the grid since there was no action.
123 // note: since renewals are unshifted onto the array, the
124 // index value does not (generally) match the array position.
126 angular.forEach($scope.renewals, function(co, idx) {
127 if (co.index == row_item.index) pos = idx;
129 $scope.renewals.splice(pos, 1);
130 $scope.gridDataProvider.refresh();
133 )['finally'](function() {
135 // regardless of the outcome of the circ, remove the
136 // barcode from the pending list.
137 if (params.copy_barcode)
138 delete pending_barcodes[params.copy_barcode];
142 $scope.fetchLastCircPatron = function(items) {
143 var renewal = items[0];
144 if (!renewal || !renewal.acp) return;
146 egCirc.last_copy_circ(renewal.acp.id())
147 .then(function(circ) {
150 // jump to the patron UI (separate app)
151 $window.location.href = $location
152 .path('/circ/patron/' + circ.usr() + '/checkout')
157 $scope.alert = {item_never_circed : renewal.acp.barcode()};
161 $scope.showMarkDamaged = function(items) {
163 angular.forEach(items, function(item) {
164 if (item.acp) copy_ids.push(item.acp.id());
167 if (copy_ids.length) {
168 egCirc.mark_damaged(copy_ids).then(function() {
169 // update grid items?
174 $scope.showLastFewCircs = function(items) {
175 if (items.length && (copy = items[0].acp)) {
176 var url = $location.path(
177 '/cat/item/' + copy.id() + '/circ_list').absUrl();
178 $window.open(url, '_blank').focus();
182 $scope.abortTransit = function(items) {
183 var transit_ids = [];
184 angular.forEach(items, function(item) {
185 if (item.transit) transit_ids.push(item.transit.id());
188 egCirc.abort_transits(transit_ids).then(function() {
189 // update grid items?
193 $scope.print_receipt = function() {
194 var print_data = {circulations : []}
196 if ($scope.renewals.length == 0) return $q.when();
198 angular.forEach($scope.renewals, function(renewal) {
200 print_data.circulations.push({
201 circ : egCore.idl.toHash(renewal.circ),
202 copy : egCore.idl.toHash(renewal.acp),
203 title : egCore.idl.toHash(renewal.title),
204 author : egCore.idl.toHash(renewal.author)
209 return egCore.print.print({