1 angular.module('egCheckinApp', ['ngRoute', 'ui.bootstrap',
2 'egCoreMod', 'egUiMod', 'egGridMod', 'egUserMod'])
4 .config(function($routeProvider, $locationProvider, $compileProvider) {
5 $locationProvider.html5Mode(true);
6 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
8 var resolver = {delay :
9 ['egStartup', function(egStartup) {return egStartup.go()}]}
11 $routeProvider.when('/circ/checkin/checkin', {
12 templateUrl: './circ/checkin/t_checkin',
13 controller: 'CheckinCtrl',
17 $routeProvider.when('/circ/checkin/capture', {
18 templateUrl: './circ/checkin/t_checkin',
19 controller: 'CheckinCtrl',
23 $routeProvider.otherwise({redirectTo : '/circ/checkin/checkin'});
26 .factory('checkinSvc', [function() {
28 service.checkins = [];
36 .controller('CheckinCtrl',
37 ['$scope','$q','$window','$location', '$timeout','egCore','checkinSvc','egGridDataProvider','egCirc', 'egItem',
38 function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , egGridDataProvider , egCirc, itemSvc) {
40 $scope.focusMe = true;
41 $scope.checkins = checkinSvc.checkins;
42 var today = new Date();
43 $scope.checkinArgs = {backdate : today}
44 $scope.using_hatch_printer = egCore.hatch.usePrinting();
45 $scope.modifiers = {};
46 $scope.fine_total = 0;
47 $scope.is_capture = $location.path().match(/capture$/);
48 var suppress_popups = false;
49 $scope.grid_persist_key = $scope.is_capture ?
50 'circ.checkin.capture' : 'circ.checkin.checkin';
52 egCore.hatch.getItem('circ.checkin.strict_barcode')
53 .then(function(sb){ $scope.strict_barcode = sb });
56 'ui.circ.suppress_checkin_popups' // add other settings as needed
57 ]).then(function(set) {
58 suppress_popups = set['ui.circ.suppress_checkin_popups'];
61 $scope.sort_money = function (a,b) {
62 var ma = parseFloat(a);
63 var mb = parseFloat(b);
64 if (ma < mb) return -1;
65 if (ma > mb) return 1;
69 // checkin & hold capture modifiers
80 if ($scope.is_capture) {
81 // in hold capture mode, some values are forced, regardless
82 // of stored preferences.
83 $scope.modifiers.noop = false;
84 $scope.modifiers.auto_print_holds_transits = true;
86 modifiers.push('noop'); // AKA suppress holds and transits
87 modifiers.push('auto_print_holds_transits');
90 // set modifiers from stored preferences
91 angular.forEach(modifiers, function(mod) {
92 egCore.hatch.getItem('eg.circ.checkin.' + mod)
93 .then(function(val) { if (val) $scope.modifiers[mod] = true });
96 // set / unset a checkin modifier
97 // when set, store the preference
98 $scope.toggle_mod = function(mod) {
99 if ($scope.modifiers[mod]) {
100 $scope.modifiers[mod] = false;
101 egCore.hatch.removeItem('eg.circ.checkin.' + mod);
103 $scope.modifiers[mod] = true;
104 egCore.hatch.setItem('eg.circ.checkin.' + mod, true);
109 // ensure the backdate is not in the future
110 // note: input type=date max=foo not yet supported anywhere
111 $scope.$watch('checkinArgs.backdate', function(newval) {
112 if (newval && newval > today)
113 $scope.checkinArgs.backdate = today;
116 $scope.is_backdate = function() {
117 return $scope.checkinArgs.backdate < today;
120 var checkinGrid = $scope.gridControls = {};
122 $scope.gridDataProvider = egGridDataProvider.instance({
123 get : function(offset, count) {
124 return this.arrayNotifier($scope.checkins, offset, count);
128 // turns the various inputs (form args, modifiers, etc.) into
129 // checkin params and options.
130 function compile_checkin_args(args) {
131 var params = angular.copy(args);
133 if (params.backdate) {
135 params.backdate.toISOString().replace(/T.*/,'');
137 // a backdate of 'today' is not really a backdate
138 if (params.backdate == $scope.max_backdate)
139 delete params.backdate;
142 angular.forEach(['noop','void_overdues',
143 'clear_expired','hold_as_transit','manual_float'],
145 if ($scope.modifiers[opt]) params[opt] = true;
149 if ($scope.modifiers.retarget_holds) {
150 if ($scope.modifiers.retarget_holds_all) {
151 params.retarget_mode = 'retarget.all';
153 params.retarget_mode = 'retarget';
157 egCore.hatch.setItem('circ.checkin.strict_barcode', $scope.strict_barcode);
159 check_barcode : $scope.strict_barcode,
160 no_precat_alert : $scope.modifiers.no_precat_alert,
161 auto_print_holds_transits :
162 $scope.modifiers.auto_print_holds_transits,
163 suppress_popups : suppress_popups
166 return {params : params, options: options};
169 $scope.checkin = function(args) {
171 var compiled = compile_checkin_args(args);
172 args.copy_barcode = ''; // reset UI for next scan
173 $scope.focusMe = true;
175 delete $scope.billable_amount;
176 delete $scope.billable_barcode;
177 delete $scope.billable_user_id;
179 var params = compiled.params;
180 var options = compiled.options;
182 if (!params.copy_barcode) return;
186 index : checkinSvc.checkins.length,
187 copy_barcode : params.copy_barcode
190 // track the item in the grid before sending the request
191 checkinSvc.checkins.unshift(row_item);
192 checkinGrid.refresh();
194 egCirc.checkin(params, options).then(
195 function(final_resp) {
197 row_item.evt = final_resp.evt;
198 angular.forEach(final_resp.data, function(val, key) {
203 var amt = Number(row_item.mbts.balance_owed());
205 $scope.billable_barcode = row_item.copy_barcode;
206 $scope.billable_amount = amt;
207 $scope.billable_user_id = row_item.circ.usr();
209 ($scope.fine_total * 100 + amt * 100) / 100;
213 if (final_resp.evt.textcode == 'NO_CHANGE') {
215 {already_checked_in : final_resp.evt.copy_barcode};
218 if ($scope.trim_list && checkinSvc.checkins.length > 20)
219 checkinSvc.checkins = checkinSvc.checkins.splice(0, 20);
222 // Checkin was rejected somewhere along the way.
223 // Remove the copy from the grid since there was no action.
224 // note: since checkins are unshifted onto the array, the
225 // index value does not (generally) match the array position.
227 angular.forEach(checkinSvc.checkins, function(ci, idx) {
228 if (ci.index == row_item.index) pos = idx;
230 checkinSvc.checkins.splice(pos, 1);
232 })['finally'](function() {
234 // when all is said and done, refresh the grid and refocus
235 checkinGrid.refresh();
236 $scope.focusMe = true;
240 $scope.print_receipt = function() {
241 var print_data = {checkins : []}
243 if (checkinSvc.checkins.length == 0) return $q.when();
245 angular.forEach(checkinSvc.checkins, function(checkin) {
248 copy : egCore.idl.toHash(checkin.acp) || {},
249 call_number : egCore.idl.toHash(checkin.acn) || {},
250 copy_barcode : checkin.copy_barcode,
251 title : checkin.title,
252 author : checkin.author
255 print_data.checkins.push(checkin);
258 return egCore.print.print({
259 template : 'checkin',
261 show_dialog : $scope.show_print_dialog
266 // --- context menu actions
268 $scope.fetchLastCircPatron = function(items) {
269 var checkin = items[0];
270 if (!checkin || !checkin.acp) return;
272 egCirc.last_copy_circ(checkin.acp.id())
273 .then(function(circ) {
276 // jump to the patron UI (separate app)
277 $window.location.href = $location
278 .path('/circ/patron/' + circ.usr() + '/checkout')
283 $scope.alert = {item_never_circed : checkin.acp.barcode()};
287 $scope.showBackdateDialog = function(items) {
290 angular.forEach(items, function(item) {
291 if (item.circ) circ_ids.push(item.circ.id());
294 if (circ_ids.length) {
295 egCirc.backdate_dialog(circ_ids).then(function(result) {
296 angular.forEach(items, function(item) {
297 item.circ.checkin_time(result.backdate);
300 // TODO: support grid row styling
301 checkinGrid.refresh();
305 $scope.showMarkDamaged = function(items) {
307 angular.forEach(items, function(item) {
308 if (item.acp) copy_ids.push(item.acp.id());
311 if (copy_ids.length) {
312 egCirc.mark_damaged(copy_ids).then(function() {
313 // update grid items?
318 $scope.abortTransit = function(items) {
319 var transit_ids = [];
320 angular.forEach(items, function(item) {
321 if (item.transit) transit_ids.push(item.transit.id());
324 egCirc.abort_transits(transit_ids).then(function() {
325 // update grid items?
329 $scope.add_copies_to_bucket = function(items){
331 angular.forEach(items, function(cp){
332 itemsIds.push(cp.acp.id());
335 itemSvc.add_copies_to_bucket(itemsIds);
338 $scope.showBibHolds = function(items){
340 angular.forEach(items, function(i){
341 recordIds.push(i.acn.record());
343 angular.forEach(recordIds, function (r) {
344 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
345 $timeout(function() { $window.open(url, '_blank') });
349 $scope.showLastCircs = function(items){
351 angular.forEach(items, function(cp){
352 itemIds.push(cp.acp.id());
354 angular.forEach(itemIds, function (id) {
355 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
356 $timeout(function() { $window.open(url, '_blank') });
360 $scope.selectedHoldingsVolCopyEdit = function (items) {
362 angular.forEach(items, function(i){
363 var h = egCore.idl.toHash(i);
364 h['call_number.record.id'] = h.record.doc_id;
367 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
370 $scope.show_mark_missing_pieces = function(items){
371 angular.forEach(items, function(i){
372 i.acp.call_number(i.acn);
373 i.acp.call_number().record(i.record);
374 itemSvc.mark_missing_pieces(i.acp);