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 $scope.focusBarcode = true;
38 var today = new Date();
39 $scope.renewalArgs = {due_date : today};
41 $scope.gridDataProvider = egGridDataProvider.instance({
42 get : function(offset, count) {
43 return this.arrayNotifier($scope.renewals, offset, count);
47 // avoid multiple, in-flight attempts on the same barcode
48 var pending_barcodes = {};
50 $scope.renew = function(args) {
51 var params = angular.copy(args);
53 if (args.sticky_date) {
54 params.due_date = args.due_date.toISOString();
56 delete params.due_date;
58 delete params.sticky_date;
59 if (!args.copy_barcode) return;
61 args.copy_barcode = ''; // reset UI input
63 if (pending_barcodes[params.copy_barcode]) {
65 "Skipping renewals of redundant barcode "
71 pending_barcodes[params.copy_barcode] = true;
74 $scope.focusBarcode = true; // return focus to barcode input
77 function send_renewal(params) {
79 params.noncat_type = params.noncat ? params.noncat_type : '';
81 // populate the grid row before we send the request so that the
82 // order of actions is maintained and so the user gets an
83 // immediate reaction to their barcode input action.
85 index : $scope.renewals.length,
86 copy_barcode : params.copy_barcode,
87 noncat_type : params.noncat_type
90 $scope.renewals.unshift(row_item);
91 $scope.gridDataProvider.refresh();
93 var options = {check_barcode : $scope.strict_barcode};
95 egCirc.renew(params, options).then(
96 function(final_resp) {
98 row_item.evt = final_resp.evt;
99 angular.forEach(final_resp.data, function(val, key) {
104 var amt = Number(row_item.mbts.balance_owed());
106 $scope.billable_barcode = row_item.copy_barcode;
107 $scope.billable_amount = amt;
109 ($scope.fine_total * 100 + amt * 100) / 100;
113 if ($scope.trim_list && checkinSvc.checkins.length > 20)
114 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
118 // Circ was rejected somewhere along the way.
119 // Remove the copy from the grid since there was no action.
120 // note: since renewals are unshifted onto the array, the
121 // index value does not (generally) match the array position.
123 angular.forEach($scope.renewals, function(co, idx) {
124 if (co.index == row_item.index) pos = idx;
126 $scope.renewals.splice(pos, 1);
127 $scope.gridDataProvider.refresh();
130 )['finally'](function() {
132 // regardless of the outcome of the circ, remove the
133 // barcode from the pending list.
134 if (params.copy_barcode)
135 delete pending_barcodes[params.copy_barcode];
139 $scope.fetchLastCircPatron = function(items) {
140 var renewal = items[0];
141 if (!renewal || !renewal.acp) return;
143 egCirc.last_copy_circ(renewal.acp.id())
144 .then(function(circ) {
147 // jump to the patron UI (separate app)
148 $window.location.href = $location
149 .path('/circ/patron/' + circ.usr() + '/checkout')
154 $scope.alert = {item_never_circed : renewal.acp.barcode()};
158 $scope.showMarkDamaged = function(items) {
160 angular.forEach(items, function(item) {
161 if (item.acp) copy_ids.push(item.acp.id());
164 if (copy_ids.length) {
165 egCirc.mark_damaged(copy_ids).then(function() {
166 // update grid items?
171 $scope.showLastFewCircs = function(items) {
172 if (items.length && (copy = items[0].acp)) {
173 var url = $location.path(
174 '/cat/item/' + copy.id() + '/circ_list').absUrl();
175 $window.open(url, '_blank').focus();
179 $scope.abortTransit = function(items) {
180 var transit_ids = [];
181 angular.forEach(items, function(item) {
182 if (item.transit) transit_ids.push(item.transit.id());
185 egCirc.abort_transits(transit_ids).then(function() {
186 // update grid items?
190 $scope.print_receipt = function() {
191 var print_data = {circulations : []}
193 if ($scope.renewals.length == 0) return $q.when();
195 angular.forEach($scope.renewals, function(renewal) {
197 print_data.circulations.push({
198 circ : egCore.idl.toHash(renewal.circ),
199 copy : egCore.idl.toHash(renewal.acp),
200 title : egCore.idl.toHash(renewal.title),
201 author : egCore.idl.toHash(renewal.author)
206 return egCore.print.print({