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 input_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) {
114 row_item['copy_barcode'] = row_item.acp.barcode();
117 var amt = Number(row_item.mbts.balance_owed());
119 $scope.billable_barcode = row_item.copy_barcode;
120 $scope.billable_amount = amt;
122 ($scope.fine_total * 100 + amt * 100) / 100;
126 if ($scope.trim_list && checkinSvc.checkins.length > 20)
127 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
131 // Circ was rejected somewhere along the way.
132 // Remove the copy from the grid since there was no action.
133 // note: since renewals are unshifted onto the array, the
134 // index value does not (generally) match the array position.
136 angular.forEach($scope.renewals, function(co, idx) {
137 if (co.index == row_item.index) pos = idx;
139 $scope.renewals.splice(pos, 1);
140 $scope.gridDataProvider.refresh();
143 )['finally'](function() {
145 // regardless of the outcome of the circ, remove the
146 // barcode from the pending list.
147 if (params.copy_barcode)
148 delete pending_barcodes[params.copy_barcode];
152 $scope.fetchLastCircPatron = function(items) {
153 var renewal = items[0];
154 if (!renewal || !renewal.acp) return;
156 egCirc.last_copy_circ(renewal.acp.id())
157 .then(function(circ) {
160 // jump to the patron UI (separate app)
161 $window.location.href = $location
162 .path('/circ/patron/' + circ.usr() + '/checkout')
167 $scope.alert = {item_never_circed : renewal.acp.barcode()};
171 $scope.showMarkDamaged = function(items) {
173 angular.forEach(items, function(item) {
174 if (item.acp) copy_ids.push(item.acp.id());
177 if (copy_ids.length) {
178 egCirc.mark_damaged(copy_ids).then(function() {
179 // update grid items?
184 $scope.showLastFewCircs = function(items) {
185 if (items.length && (copy = items[0].acp)) {
186 var url = $location.path(
187 '/cat/item/' + copy.id() + '/circ_list').absUrl();
188 $window.open(url, '_blank').focus();
192 $scope.abortTransit = function(items) {
193 var transit_ids = [];
194 angular.forEach(items, function(item) {
195 if (item.transit) transit_ids.push(item.transit.id());
198 egCirc.abort_transits(transit_ids).then(function() {
199 // update grid items?
203 $scope.print_receipt = function() {
204 var print_data = {circulations : []}
206 if ($scope.renewals.length == 0) return $q.when();
208 angular.forEach($scope.renewals, function(renewal) {
210 print_data.circulations.push({
211 circ : egCore.idl.toHash(renewal.circ),
212 copy : egCore.idl.toHash(renewal.acp),
213 title : egCore.idl.toHash(renewal.title),
214 author : egCore.idl.toHash(renewal.author)
219 return egCore.print.print({