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.sort_money = function (a,b) {
44 var ma = parseFloat(a);
45 var mb = parseFloat(b);
46 if (ma < mb) return -1;
47 if (ma > mb) return 1;
51 $scope.gridDataProvider = egGridDataProvider.instance({
52 get : function(offset, count) {
53 return this.arrayNotifier($scope.renewals, offset, count);
57 // avoid multiple, in-flight attempts on the same barcode
58 var pending_barcodes = {};
60 $scope.renew = function(args) {
61 var params = angular.copy(args);
63 if (args.sticky_date) {
64 params.due_date = args.due_date.toISOString();
66 delete params.due_date;
68 delete params.sticky_date;
69 if (!args.copy_barcode) return;
71 args.copy_barcode = ''; // reset UI input
73 if (pending_barcodes[params.copy_barcode]) {
75 "Skipping renewals of redundant barcode "
81 pending_barcodes[params.copy_barcode] = true;
84 $scope.focusBarcode = true; // return focus to barcode input
87 function send_renewal(params) {
89 params.noncat_type = params.noncat ? params.noncat_type : '';
91 // populate the grid row before we send the request so that the
92 // order of actions is maintained and so the user gets an
93 // immediate reaction to their barcode input action.
95 index : $scope.renewals.length,
96 copy_barcode : params.copy_barcode,
97 noncat_type : params.noncat_type
100 $scope.renewals.unshift(row_item);
101 $scope.gridDataProvider.refresh();
103 egCore.hatch.setItem('circ.renew.strict_barcode', $scope.strict_barcode);
104 var options = {check_barcode : $scope.strict_barcode};
106 egCirc.renew(params, options).then(
107 function(final_resp) {
109 row_item.evt = final_resp.evt;
110 angular.forEach(final_resp.data, function(val, key) {
115 var amt = Number(row_item.mbts.balance_owed());
117 $scope.billable_barcode = row_item.copy_barcode;
118 $scope.billable_amount = amt;
120 ($scope.fine_total * 100 + amt * 100) / 100;
124 if ($scope.trim_list && checkinSvc.checkins.length > 20)
125 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
129 // Circ was rejected somewhere along the way.
130 // Remove the copy from the grid since there was no action.
131 // note: since renewals are unshifted onto the array, the
132 // index value does not (generally) match the array position.
134 angular.forEach($scope.renewals, function(co, idx) {
135 if (co.index == row_item.index) pos = idx;
137 $scope.renewals.splice(pos, 1);
138 $scope.gridDataProvider.refresh();
141 )['finally'](function() {
143 // regardless of the outcome of the circ, remove the
144 // barcode from the pending list.
145 if (params.copy_barcode)
146 delete pending_barcodes[params.copy_barcode];
150 $scope.fetchLastCircPatron = function(items) {
151 var renewal = items[0];
152 if (!renewal || !renewal.acp) return;
154 egCirc.last_copy_circ(renewal.acp.id())
155 .then(function(circ) {
158 // jump to the patron UI (separate app)
159 $window.location.href = $location
160 .path('/circ/patron/' + circ.usr() + '/checkout')
165 $scope.alert = {item_never_circed : renewal.acp.barcode()};
169 $scope.showMarkDamaged = function(items) {
171 angular.forEach(items, function(item) {
172 if (item.acp) copy_ids.push(item.acp.id());
175 if (copy_ids.length) {
176 egCirc.mark_damaged(copy_ids).then(function() {
177 // update grid items?
182 $scope.showLastFewCircs = function(items) {
183 if (items.length && (copy = items[0].acp)) {
184 var url = $location.path(
185 '/cat/item/' + copy.id() + '/circ_list').absUrl();
186 $window.open(url, '_blank').focus();
190 $scope.abortTransit = function(items) {
191 var transit_ids = [];
192 angular.forEach(items, function(item) {
193 if (item.transit) transit_ids.push(item.transit.id());
196 egCirc.abort_transits(transit_ids).then(function() {
197 // update grid items?
201 $scope.print_receipt = function() {
202 var print_data = {circulations : []}
204 if ($scope.renewals.length == 0) return $q.when();
206 angular.forEach($scope.renewals, function(renewal) {
208 print_data.circulations.push({
209 circ : egCore.idl.toHash(renewal.circ),
210 copy : egCore.idl.toHash(renewal.acp),
211 title : egCore.idl.toHash(renewal.title),
212 author : egCore.idl.toHash(renewal.author)
217 return egCore.print.print({