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?|mailto|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 // TODO: add this to the setting batch lookup below
53 egCore.hatch.getItem('circ.checkin.strict_barcode')
54 .then(function(sb){ $scope.strict_barcode = sb });
57 'ui.circ.suppress_checkin_popups' // add other settings as needed
58 ]).then(function(set) {
59 suppress_popups = set['ui.circ.suppress_checkin_popups'];
62 $scope.sort_money = function (a,b) {
63 var ma = parseFloat(a);
64 var mb = parseFloat(b);
65 if (ma < mb) return -1;
66 if (ma > mb) return 1;
70 // checkin & hold capture modifiers
81 if ($scope.is_capture) {
82 // in hold capture mode, some values are forced, regardless
83 // of stored preferences.
84 $scope.modifiers.noop = false;
85 $scope.modifiers.auto_print_holds_transits = true;
87 modifiers.push('noop'); // AKA suppress holds and transits
88 modifiers.push('auto_print_holds_transits');
91 // set modifiers from stored preferences
92 var snames = modifiers.map(function(m) {return 'eg.circ.checkin.' + m;});
93 egCore.hatch.getItemBatch(snames).then(function(settings) {
94 angular.forEach(settings, function(val, key) {
96 var parts = key.split('.')
97 var mod = parts.pop();
98 $scope.modifiers[mod] = true;
103 // set / unset a checkin modifier
104 // when set, store the preference
105 $scope.toggle_mod = function(mod) {
106 if ($scope.modifiers[mod]) {
107 $scope.modifiers[mod] = false;
108 egCore.hatch.removeItem('eg.circ.checkin.' + mod);
110 $scope.modifiers[mod] = true;
111 egCore.hatch.setItem('eg.circ.checkin.' + mod, true);
116 // ensure the backdate is not in the future
117 // note: input type=date max=foo not yet supported anywhere
118 $scope.$watch('checkinArgs.backdate', function(newval) {
119 if (newval && newval > today)
120 $scope.checkinArgs.backdate = today;
123 $scope.is_backdate = function() {
124 return $scope.checkinArgs.backdate < today;
127 var checkinGrid = $scope.gridControls = {};
129 $scope.gridDataProvider = egGridDataProvider.instance({
130 get : function(offset, count) {
131 return this.arrayNotifier($scope.checkins, offset, count);
135 // turns the various inputs (form args, modifiers, etc.) into
136 // checkin params and options.
137 function compile_checkin_args(args) {
138 var params = angular.copy(args);
140 if (params.backdate) {
142 params.backdate.toISOString().replace(/T.*/,'');
144 // a backdate of 'today' is not really a backdate
145 if (params.backdate == $scope.max_backdate)
146 delete params.backdate;
149 angular.forEach(['noop','void_overdues',
150 'clear_expired','hold_as_transit','manual_float'],
152 if ($scope.modifiers[opt]) params[opt] = true;
156 if ($scope.modifiers.retarget_holds) {
157 if ($scope.modifiers.retarget_holds_all) {
158 params.retarget_mode = 'retarget.all';
160 params.retarget_mode = 'retarget';
164 egCore.hatch.setItem('circ.checkin.strict_barcode', $scope.strict_barcode);
166 check_barcode : $scope.strict_barcode,
167 no_precat_alert : $scope.modifiers.no_precat_alert,
168 auto_print_holds_transits :
169 $scope.modifiers.auto_print_holds_transits,
170 suppress_popups : suppress_popups
173 return {params : params, options: options};
176 $scope.checkin = function(args) {
178 var compiled = compile_checkin_args(args);
179 args.copy_barcode = ''; // reset UI for next scan
180 $scope.focusMe = true;
182 delete $scope.billable_amount;
183 delete $scope.billable_barcode;
184 delete $scope.billable_user_id;
186 var params = compiled.params;
187 var options = compiled.options;
189 if (!params.copy_barcode) return;
193 index : checkinSvc.checkins.length,
194 input_barcode : params.copy_barcode
197 // track the item in the grid before sending the request
198 checkinSvc.checkins.unshift(row_item);
200 egCirc.checkin(params, options).then(
201 function(final_resp) {
203 row_item.evt = final_resp.evt;
204 angular.forEach(final_resp.data, function(val, key) {
208 row_item['copy_barcode'] = row_item.acp.barcode();
211 var amt = Number(row_item.mbts.balance_owed());
213 $scope.billable_barcode = row_item.copy_barcode;
214 $scope.billable_amount = amt;
215 $scope.billable_user_id = row_item.circ.usr();
217 ($scope.fine_total * 100 + amt * 100) / 100;
221 if (final_resp.evt.textcode == 'NO_CHANGE') {
223 {already_checked_in : final_resp.evt.copy_barcode};
226 if ($scope.trim_list && checkinSvc.checkins.length > 20)
227 //cut array short at 20 items
228 checkinSvc.checkins.length = 20;
231 // Checkin was rejected somewhere along the way.
232 // Remove the copy from the grid since there was no action.
233 // note: since checkins are unshifted onto the array, the
234 // index value does not (generally) match the array position.
236 angular.forEach(checkinSvc.checkins, function(ci, idx) {
237 if (ci.index == row_item.index) pos = idx;
239 checkinSvc.checkins.splice(pos, 1);
241 })['finally'](function() {
243 // when all is said and done, refresh the grid and refocus
244 checkinGrid.refresh();
245 $scope.focusMe = true;
249 $scope.print_receipt = function() {
250 var print_data = {checkins : []}
252 if (checkinSvc.checkins.length == 0) return $q.when();
254 angular.forEach(checkinSvc.checkins, function(checkin) {
257 copy : egCore.idl.toHash(checkin.acp) || {},
258 call_number : egCore.idl.toHash(checkin.acn) || {},
259 copy_barcode : checkin.copy_barcode,
260 title : checkin.title,
261 author : checkin.author
264 print_data.checkins.push(checkin);
267 return egCore.print.print({
268 template : 'checkin',
270 show_dialog : $scope.show_print_dialog
275 // --- context menu actions
277 $scope.fetchLastCircPatron = function(items) {
278 var checkin = items[0];
279 if (!checkin || !checkin.acp) return;
281 egCirc.last_copy_circ(checkin.acp.id())
282 .then(function(circ) {
285 // jump to the patron UI (separate app)
286 $window.location.href = $location
287 .path('/circ/patron/' + circ.usr() + '/checkout')
292 $scope.alert = {item_never_circed : checkin.acp.barcode()};
296 $scope.showBackdateDialog = function(items) {
299 angular.forEach(items, function(item) {
300 if (item.circ) circ_ids.push(item.circ.id());
303 if (circ_ids.length) {
304 egCirc.backdate_dialog(circ_ids).then(function(result) {
305 angular.forEach(items, function(item) {
306 item.circ.checkin_time(result.backdate);
309 // TODO: support grid row styling
310 checkinGrid.refresh();
314 $scope.showMarkDamaged = function(items) {
316 angular.forEach(items, function(item) {
318 egCirc.mark_damaged({
320 barcode: item.acp.barcode()
328 $scope.abortTransit = function(items) {
329 var transit_ids = [];
330 angular.forEach(items, function(item) {
331 if (item.transit) transit_ids.push(item.transit.id());
334 egCirc.abort_transits(transit_ids).then(function() {
335 // update grid items?
339 $scope.add_copies_to_bucket = function(items){
341 angular.forEach(items, function(cp){
342 itemsIds.push(cp.acp.id());
345 itemSvc.add_copies_to_bucket(itemsIds);
348 $scope.showBibHolds = function(items){
350 angular.forEach(items, function(i){
351 recordIds.push(i.acn.record());
353 angular.forEach(recordIds, function (r) {
354 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
355 $timeout(function() { $window.open(url, '_blank') });
359 $scope.showLastCircs = function(items){
361 angular.forEach(items, function(cp){
362 itemIds.push(cp.acp.id());
364 angular.forEach(itemIds, function (id) {
365 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
366 $timeout(function() { $window.open(url, '_blank') });
370 $scope.selectedHoldingsVolCopyEdit = function (items) {
372 angular.forEach(items, function(i){
373 var h = egCore.idl.toHash(i);
375 'call_number.record.id': h.record.doc_id,
379 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
382 $scope.show_mark_missing_pieces = function(items){
383 angular.forEach(items, function(i){
384 i.acp.call_number(i.acn);
385 i.acp.call_number().record(i.record);
386 itemSvc.mark_missing_pieces(i.acp,$scope);
390 $scope.printSpineLabels = function(items){
392 angular.forEach(items, function(item) {
393 if (item.acp) copy_ids.push(item.acp.id());
395 itemSvc.print_spine_labels(copy_ids);
398 $scope.addCopyAlerts = function(items) {
400 angular.forEach(items, function(item) {
401 if (item.acp) copy_ids.push(item.acp.id());
403 egCirc.add_copy_alerts(copy_ids).then(function() {
404 // update grid items?
408 $scope.manageCopyAlerts = function(items) {
410 angular.forEach(items, function(item) {
411 if (item.acp) copy_ids.push(item.acp.id());
413 egCirc.manage_copy_alerts(copy_ids).then(function() {
414 // update grid items?