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(new Date().setHours(0,0,0,0));
43 $scope.checkinArgs = {backdate : today}
44 $scope.modifiers = {};
45 $scope.fine_total = 0;
46 $scope.is_capture = $location.path().match(/capture$/);
47 var suppress_popups = false;
48 $scope.grid_persist_key = $scope.is_capture ?
49 'circ.checkin.capture' : 'circ.checkin.checkin';
51 egCore.hatch.usePrinting().then(function(useHatch) {
52 $scope.using_hatch_printer = useHatch;
55 // TODO: add this to the setting batch lookup below
56 egCore.hatch.getItem('circ.checkin.strict_barcode')
57 .then(function(sb){ $scope.strict_barcode = sb });
60 'ui.circ.suppress_checkin_popups' // add other settings as needed
61 ]).then(function(set) {
62 suppress_popups = set['ui.circ.suppress_checkin_popups'];
65 $scope.sort_money = function (a,b) {
66 var ma = parseFloat(a);
67 var mb = parseFloat(b);
68 if (ma < mb) return -1;
69 if (ma > mb) return 1;
73 // checkin & hold capture modifiers
84 if ($scope.is_capture) {
85 // in hold capture mode, some values are forced, regardless
86 // of stored preferences.
87 $scope.modifiers.noop = false;
88 $scope.modifiers.auto_print_holds_transits = true;
90 modifiers.push('noop'); // AKA suppress holds and transits
91 modifiers.push('auto_print_holds_transits');
92 modifiers.push('do_inventory_update');
94 // backdate is possible so load options
95 $scope.backdate = {date: egCore.hatch.getSessionItem('eg.circ.checkin.backdate')};
96 $scope.backdate.untilLogout = !!$scope.backdate.date;
97 if ($scope.backdate.untilLogout)
98 $scope.checkinArgs.backdate = new Date($scope.backdate.date);
100 // watch backdate to enable/disable the sticky option
101 // and ensure the backdate is not in the future
102 // note: input type=date max=foo not yet supported anywhere
103 $scope.$watch('checkinArgs.backdate', function(newval) {
104 if (!newval || newval.getTime() == today.getTime()) {
105 $scope.backdate.untilLogout = false;
106 egCore.hatch.removeSessionItem('eg.circ.checkin.backdate');
107 } else if (newval > today) {
108 $scope.checkinArgs.backdate = today;
109 } else if ($scope.backdate.untilLogout) {
110 egCore.hatch.setSessionItem('eg.circ.checkin.backdate', newval);
115 // set modifiers from stored preferences
116 var snames = modifiers.map(function(m) {return 'eg.circ.checkin.' + m;});
117 egCore.hatch.getItemBatch(snames).then(function(settings) {
118 angular.forEach(settings, function(val, key) {
120 var parts = key.split('.')
121 var mod = parts.pop();
122 $scope.modifiers[mod] = true;
127 // set / unset a checkin modifier
128 // when set, store the preference
129 $scope.toggle_mod = function(mod) {
130 if ($scope.modifiers[mod]) {
131 $scope.modifiers[mod] = false;
132 egCore.hatch.removeItem('eg.circ.checkin.' + mod);
134 $scope.modifiers[mod] = true;
135 egCore.hatch.setItem('eg.circ.checkin.' + mod, true);
139 $scope.onStrictBarcodeChange = function() {
140 egCore.hatch.setItem(
141 'circ.checkin.strict_barcode',
142 $scope.strict_barcode
146 $scope.onUntilLogoutChange = function() {
147 if ($scope.backdate.untilLogout)
148 egCore.hatch.setSessionItem('eg.circ.checkin.backdate',
149 $scope.checkinArgs.backdate
152 egCore.hatch.removeSessionItem('eg.circ.checkin.backdate');
155 $scope.is_backdate = function() {
156 return $scope.checkinArgs.backdate && $scope.checkinArgs.backdate < today;
159 var checkinGrid = $scope.gridControls = {};
161 $scope.gridDataProvider = egGridDataProvider.instance({
162 get : function(offset, count) {
163 return this.arrayNotifier($scope.checkins, offset, count);
167 // turns the various inputs (form args, modifiers, etc.) into
168 // checkin params and options.
169 function compile_checkin_args(args) {
170 var params = angular.copy(args);
172 // a backdate of 'today' is not really a backdate
173 // (and this particularly matters when checking in hourly
174 // loans, as backdated checkins currently get the time
175 // portion of the checkin time from the due date; this will
176 // stop mattering when FIXME bug 1793817 is dealt with)
177 if (!$scope.is_backdate())
178 delete params.backdate;
180 if (params.backdate) {
182 params.backdate.toISOString().replace(/T.*/,'');
185 angular.forEach(['noop','void_overdues',
186 'clear_expired','hold_as_transit','manual_float'],
188 if ($scope.modifiers[opt]) params[opt] = true;
192 if ($scope.modifiers.retarget_holds) {
193 if ($scope.modifiers.retarget_holds_all) {
194 params.retarget_mode = 'retarget.all';
196 params.retarget_mode = 'retarget';
199 if ($scope.modifiers.do_inventory_update) params.do_inventory_update = true;
202 check_barcode : $scope.strict_barcode,
203 no_precat_alert : $scope.modifiers.no_precat_alert,
204 auto_print_holds_transits :
205 $scope.modifiers.auto_print_holds_transits,
206 suppress_popups : suppress_popups,
207 do_inventory_update : $scope.modifiers.do_inventory_update
210 return {params : params, options: options};
213 $scope.checkin = function(args) {
215 var compiled = compile_checkin_args(args);
216 args.copy_barcode = ''; // reset UI for next scan
217 $scope.focusMe = true;
219 delete $scope.billable_amount;
220 delete $scope.billable_barcode;
221 delete $scope.billable_user_id;
223 var params = compiled.params;
224 var options = compiled.options;
226 if (!params.copy_barcode) return;
230 index : checkinSvc.checkins.length,
231 input_barcode : params.copy_barcode
234 // track the item in the grid before sending the request
235 checkinSvc.checkins.unshift(row_item);
236 egCirc.checkin(params, options).then(
237 function(final_resp) {
239 row_item.evt = final_resp.evt;
240 angular.forEach(final_resp.data, function(val, key) {
244 row_item['copy_barcode'] = row_item.acp.barcode();
246 if (row_item.acp.latest_inventory() && row_item.acp.latest_inventory().inventory_date() == "now")
247 row_item.acp.latest_inventory().inventory_date(Date.now());
250 var amt = Number(row_item.mbts.balance_owed());
252 $scope.billable_barcode = row_item.copy_barcode;
253 $scope.billable_amount = amt;
254 $scope.billable_user_id = row_item.circ.usr();
256 ($scope.fine_total * 100 + amt * 100) / 100;
260 if (final_resp.evt.textcode == 'NO_CHANGE') {
262 {already_checked_in : final_resp.evt.copy_barcode};
265 if ($scope.trim_list && checkinSvc.checkins.length > 20) {
266 //cut array short at 20 items
267 checkinSvc.checkins.length = 20;
268 checkinGrid.prepend(20);
270 checkinGrid.prepend();
274 // Checkin was rejected somewhere along the way.
275 // Remove the copy from the grid since there was no action.
276 // note: since checkins are unshifted onto the array, the
277 // index value does not (generally) match the array position.
279 angular.forEach(checkinSvc.checkins, function(ci, idx) {
280 if (ci.index == row_item.index) pos = idx;
282 checkinSvc.checkins.splice(pos, 1);
284 })['finally'](function() {
285 // when all is said and done, refocus
286 $scope.focusMe = true;
290 $scope.print_receipt = function() {
291 var print_data = {checkins : []}
293 if (checkinSvc.checkins.length == 0) return $q.when();
295 angular.forEach(checkinSvc.checkins, function(checkin) {
298 copy : egCore.idl.toHash(checkin.acp) || {},
299 call_number : egCore.idl.toHash(checkin.acn) || {},
300 copy_barcode : checkin.copy_barcode,
301 title : checkin.title,
302 author : checkin.author
305 print_data.checkins.push(checkin);
308 return egCore.print.print({
309 template : 'checkin',
311 show_dialog : $scope.show_print_dialog
316 // --- context menu actions
318 $scope.fetchLastCircPatron = function(items) {
319 var checkin = items[0];
320 if (!checkin || !checkin.acp) return;
322 egCirc.last_copy_circ(checkin.acp.id())
323 .then(function(circ) {
326 // jump to the patron UI (separate app)
327 $window.location.href = $location
328 .path('/circ/patron/' + circ.usr() + '/checkout')
333 $scope.alert = {item_never_circed : checkin.acp.barcode()};
337 $scope.showBackdateDialog = function(items) {
340 angular.forEach(items, function(item) {
341 if (item.circ) circ_ids.push(item.circ.id());
344 if (circ_ids.length) {
345 egCirc.backdate_dialog(circ_ids).then(function(result) {
346 angular.forEach(items, function(item) {
347 item.circ.checkin_time(result.backdate);
350 // TODO: support grid row styling
351 checkinGrid.refresh();
355 $scope.showMarkDamaged = function(items) {
357 angular.forEach(items, function(item) {
359 egCirc.mark_damaged({
361 barcode: item.acp.barcode()
369 $scope.showMarkDiscard = function(items) {
371 angular.forEach(items, function(item) {
373 copies.push(egCore.idl.toHash(item.acp));
377 egCirc.mark_discard(copies).then(function() {
378 // update grid items?
383 $scope.abortTransit = function(items) {
384 var transit_ids = [];
385 angular.forEach(items, function(item) {
386 if (item.transit) transit_ids.push(item.transit.id());
389 egCirc.abort_transits(transit_ids).then(function() {
390 // update grid items?
394 $scope.add_copies_to_bucket = function(items){
396 angular.forEach(items, function(cp){
397 itemsIds.push(cp.acp.id());
400 itemSvc.add_copies_to_bucket(itemsIds);
403 $scope.showBibHolds = function(items){
405 angular.forEach(items, function(i){
406 recordIds.push(i.acn.record());
408 angular.forEach(recordIds, function (r) {
409 var url = '/eg2/staff/catalog/record/' + r + '/holds';
410 $timeout(function() { $window.open(url, '_blank') });
414 $scope.showLastCircs = function(items){
416 angular.forEach(items, function(cp){
417 itemIds.push(cp.acp.id());
419 angular.forEach(itemIds, function (id) {
420 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
421 $timeout(function() { $window.open(url, '_blank') });
425 $scope.selectedHoldingsVolCopyEdit = function (items) {
427 angular.forEach(items, function(i){
428 var h = egCore.idl.toHash(i);
430 'call_number.record.id': h.record.doc_id,
434 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
437 $scope.show_mark_missing_pieces = function(items){
438 angular.forEach(items, function(i){
439 i.acp.call_number(i.acn);
440 i.acp.call_number().record(i.record);
441 itemSvc.mark_missing_pieces(i.acp,$scope);
445 $scope.printSpineLabels = function(items){
447 angular.forEach(items, function(item) {
448 if (item.acp) copy_ids.push(item.acp.id());
450 itemSvc.print_spine_labels(copy_ids);
453 $scope.addCopyAlerts = function(items) {
455 angular.forEach(items, function(item) {
456 if (item.acp) copy_ids.push(item.acp.id());
458 egCirc.add_copy_alerts(copy_ids).then(function() {
459 // update grid items?
463 $scope.manageCopyAlerts = function(items) {
465 angular.forEach(items, function(item) {
466 if (item.acp) copy_ids.push(item.acp.id());
468 egCirc.manage_copy_alerts(copy_ids).then(function() {
469 // update grid items?