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) {
37 egCore.hatch.getItem('circ.renew.strict_barcode')
38 .then(function(sb){ $scope.strict_barcode = sb });
39 $scope.focusBarcode = true;
40 $scope.outOfRange = false;
41 $scope.minDate = new Date(now);
44 $scope.renewalArgs = {due_date : new Date(now)};
46 $scope.sort_money = function (a,b) {
47 var ma = parseFloat(a);
48 var mb = parseFloat(b);
49 if (ma < mb) return -1;
50 if (ma > mb) return 1;
54 $scope.gridDataProvider = egGridDataProvider.instance({
55 get : function(offset, count) {
56 return this.arrayNotifier($scope.renewals, offset, count);
60 // avoid multiple, in-flight attempts on the same barcode
61 var pending_barcodes = {};
63 $scope.renew = function(args) {
64 var params = angular.copy(args);
66 if (args.sticky_date) {
67 params.due_date = args.due_date.toISOString();
69 delete params.due_date;
71 delete params.sticky_date;
72 if (!args.copy_barcode) return;
74 args.copy_barcode = ''; // reset UI input
76 if (pending_barcodes[params.copy_barcode]) {
78 "Skipping renewals of redundant barcode "
84 pending_barcodes[params.copy_barcode] = true;
87 $scope.focusBarcode = true; // return focus to barcode input
90 function send_renewal(params) {
92 params.noncat_type = params.noncat ? params.noncat_type : '';
94 // populate the grid row before we send the request so that the
95 // order of actions is maintained and so the user gets an
96 // immediate reaction to their barcode input action.
98 index : $scope.renewals.length,
99 input_barcode : params.copy_barcode,
100 noncat_type : params.noncat_type
103 $scope.renewals.unshift(row_item);
104 $scope.gridDataProvider.refresh();
106 var options = {check_barcode : $scope.strict_barcode};
108 egCirc.renew(params, options).then(
109 function(final_resp) {
111 row_item.evt = final_resp.evt;
112 angular.forEach(final_resp.data, function(val, key) {
116 row_item['copy_barcode'] = row_item.acp.barcode();
119 var amt = Number(row_item.mbts.balance_owed());
121 $scope.billable_barcode = row_item.copy_barcode;
122 $scope.billable_amount = amt;
124 ($scope.fine_total * 100 + amt * 100) / 100;
128 if ($scope.trim_list && checkinSvc.checkins.length > 20)
129 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
133 // Circ was rejected somewhere along the way.
134 // Remove the copy from the grid since there was no action.
135 // note: since renewals are unshifted onto the array, the
136 // index value does not (generally) match the array position.
138 angular.forEach($scope.renewals, function(co, idx) {
139 if (co.index == row_item.index) pos = idx;
141 $scope.renewals.splice(pos, 1);
142 $scope.gridDataProvider.refresh();
145 )['finally'](function() {
147 // regardless of the outcome of the circ, remove the
148 // barcode from the pending list.
149 if (params.copy_barcode)
150 delete pending_barcodes[params.copy_barcode];
154 $scope.fetchLastCircPatron = function(items) {
155 var renewal = items[0];
156 if (!renewal || !renewal.acp) return;
158 egCirc.last_copy_circ(renewal.acp.id())
159 .then(function(circ) {
162 // jump to the patron UI (separate app)
163 $window.location.href = $location
164 .path('/circ/patron/' + circ.usr() + '/checkout')
169 $scope.alert = {item_never_circed : renewal.acp.barcode()};
173 $scope.showMarkDamaged = function(items) {
175 angular.forEach(items, function(item) {
176 if (item.acp) copy_ids.push(item.acp.id());
179 if (copy_ids.length) {
180 egCirc.mark_damaged(copy_ids).then(function() {
181 // update grid items?
186 $scope.showMarkDiscard = function(items) {
188 angular.forEach(items, function(item) {
189 if (item.acp) copies.push(egCore.idl.toHash(item.acp));
193 egCirc.mark_discard(copies).then(function() {
194 // update grid items?
199 $scope.showLastFewCircs = function(items) {
200 if (items.length && (copy = items[0].acp)) {
201 var url = $location.path(
202 '/cat/item/' + copy.id() + '/circ_list').absUrl();
203 $window.open(url, '_blank').focus();
207 $scope.abortTransit = function(items) {
208 var transit_ids = [];
209 angular.forEach(items, function(item) {
210 if (item.transit) transit_ids.push(item.transit.id());
213 egCirc.abort_transits(transit_ids).then(function() {
214 // update grid items?
218 $scope.addCopyAlerts = function(items) {
220 angular.forEach(items, function(item) {
221 if (item.acp) copy_ids.push(item.acp.id());
223 egCirc.add_copy_alerts(copy_ids).then(function() {
224 // update grid items?
228 $scope.manageCopyAlerts = function(items) {
230 angular.forEach(items, function(item) {
231 if (item.acp) copy_ids.push(item.acp.id());
233 egCirc.manage_copy_alerts(copy_ids).then(function() {
234 // update grid items?
238 $scope.onStrictBarcodeChange = function() {
239 egCore.hatch.setItem(
240 'circ.renew.strict_barcode',
241 $scope.strict_barcode
245 $scope.print_receipt = function() {
246 var print_data = {circulations : []}
248 if ($scope.renewals.length == 0) return $q.when();
250 angular.forEach($scope.renewals, function(renewal) {
252 print_data.circulations.push({
253 circ : egCore.idl.toHash(renewal.circ),
254 copy : egCore.idl.toHash(renewal.acp),
255 title : egCore.idl.toHash(renewal.title),
256 author : egCore.idl.toHash(renewal.author)
258 // Flesh selected fields of this circulation
259 print_data.circulations[0].copy.call_number =
260 egCore.idl.toHash(renewal.acn);
261 print_data.circulations[0].copy.owning_lib =
262 egCore.idl.toHash(renewal.aou);
266 return egCore.print.print({