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;
41 var today = new Date();
42 $scope.renewalArgs = {due_date : today};
44 $scope.sort_money = function (a,b) {
45 var ma = parseFloat(a);
46 var mb = parseFloat(b);
47 if (ma < mb) return -1;
48 if (ma > mb) return 1;
52 $scope.gridDataProvider = egGridDataProvider.instance({
53 get : function(offset, count) {
54 return this.arrayNotifier($scope.renewals, offset, count);
58 // avoid multiple, in-flight attempts on the same barcode
59 var pending_barcodes = {};
61 $scope.renew = function(args) {
62 var params = angular.copy(args);
64 if (args.sticky_date) {
65 params.due_date = args.due_date.toISOString();
67 delete params.due_date;
69 delete params.sticky_date;
70 if (!args.copy_barcode) return;
72 args.copy_barcode = ''; // reset UI input
74 if (pending_barcodes[params.copy_barcode]) {
76 "Skipping renewals of redundant barcode "
82 pending_barcodes[params.copy_barcode] = true;
85 $scope.focusBarcode = true; // return focus to barcode input
88 function send_renewal(params) {
90 params.noncat_type = params.noncat ? params.noncat_type : '';
92 // populate the grid row before we send the request so that the
93 // order of actions is maintained and so the user gets an
94 // immediate reaction to their barcode input action.
96 index : $scope.renewals.length,
97 input_barcode : params.copy_barcode,
98 noncat_type : params.noncat_type
101 $scope.renewals.unshift(row_item);
102 $scope.gridDataProvider.refresh();
104 egCore.hatch.setItem('circ.renew.strict_barcode', $scope.strict_barcode);
105 var options = {check_barcode : $scope.strict_barcode};
107 egCirc.renew(params, options).then(
108 function(final_resp) {
110 row_item.evt = final_resp.evt;
111 angular.forEach(final_resp.data, function(val, key) {
115 row_item['copy_barcode'] = row_item.acp.barcode();
118 var amt = Number(row_item.mbts.balance_owed());
120 $scope.billable_barcode = row_item.copy_barcode;
121 $scope.billable_amount = amt;
123 ($scope.fine_total * 100 + amt * 100) / 100;
127 if ($scope.trim_list && checkinSvc.checkins.length > 20)
128 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
132 // Circ was rejected somewhere along the way.
133 // Remove the copy from the grid since there was no action.
134 // note: since renewals are unshifted onto the array, the
135 // index value does not (generally) match the array position.
137 angular.forEach($scope.renewals, function(co, idx) {
138 if (co.index == row_item.index) pos = idx;
140 $scope.renewals.splice(pos, 1);
141 $scope.gridDataProvider.refresh();
144 )['finally'](function() {
146 // regardless of the outcome of the circ, remove the
147 // barcode from the pending list.
148 if (params.copy_barcode)
149 delete pending_barcodes[params.copy_barcode];
153 $scope.fetchLastCircPatron = function(items) {
154 var renewal = items[0];
155 if (!renewal || !renewal.acp) return;
157 egCirc.last_copy_circ(renewal.acp.id())
158 .then(function(circ) {
161 // jump to the patron UI (separate app)
162 $window.location.href = $location
163 .path('/circ/patron/' + circ.usr() + '/checkout')
168 $scope.alert = {item_never_circed : renewal.acp.barcode()};
172 $scope.showMarkDamaged = function(items) {
174 angular.forEach(items, function(item) {
175 if (item.acp) copy_ids.push(item.acp.id());
178 if (copy_ids.length) {
179 egCirc.mark_damaged(copy_ids).then(function() {
180 // update grid items?
185 $scope.showLastFewCircs = function(items) {
186 if (items.length && (copy = items[0].acp)) {
187 var url = $location.path(
188 '/cat/item/' + copy.id() + '/circ_list').absUrl();
189 $window.open(url, '_blank').focus();
193 $scope.abortTransit = function(items) {
194 var transit_ids = [];
195 angular.forEach(items, function(item) {
196 if (item.transit) transit_ids.push(item.transit.id());
199 egCirc.abort_transits(transit_ids).then(function() {
200 // update grid items?
204 $scope.print_receipt = function() {
205 var print_data = {circulations : []}
207 if ($scope.renewals.length == 0) return $q.when();
209 angular.forEach($scope.renewals, function(renewal) {
211 print_data.circulations.push({
212 circ : egCore.idl.toHash(renewal.circ),
213 copy : egCore.idl.toHash(renewal.acp),
214 title : egCore.idl.toHash(renewal.title),
215 author : egCore.idl.toHash(renewal.author)
220 return egCore.print.print({