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 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 input_barcode : params.copy_barcode
190 // track the item in the grid before sending the request
191 checkinSvc.checkins.unshift(row_item);
193 egCirc.checkin(params, options).then(
194 function(final_resp) {
196 row_item.evt = final_resp.evt;
197 angular.forEach(final_resp.data, function(val, key) {
201 row_item['copy_barcode'] = row_item.acp.barcode();
204 var amt = Number(row_item.mbts.balance_owed());
206 $scope.billable_barcode = row_item.copy_barcode;
207 $scope.billable_amount = amt;
208 $scope.billable_user_id = row_item.circ.usr();
210 ($scope.fine_total * 100 + amt * 100) / 100;
214 if (final_resp.evt.textcode == 'NO_CHANGE') {
216 {already_checked_in : final_resp.evt.copy_barcode};
219 if ($scope.trim_list && checkinSvc.checkins.length > 20)
220 //cut array short at 20 items
221 checkinSvc.checkins.length = 20;
224 // Checkin was rejected somewhere along the way.
225 // Remove the copy from the grid since there was no action.
226 // note: since checkins are unshifted onto the array, the
227 // index value does not (generally) match the array position.
229 angular.forEach(checkinSvc.checkins, function(ci, idx) {
230 if (ci.index == row_item.index) pos = idx;
232 checkinSvc.checkins.splice(pos, 1);
234 })['finally'](function() {
236 // when all is said and done, refresh the grid and refocus
237 checkinGrid.refresh();
238 $scope.focusMe = true;
242 $scope.print_receipt = function() {
243 var print_data = {checkins : []}
245 if (checkinSvc.checkins.length == 0) return $q.when();
247 angular.forEach(checkinSvc.checkins, function(checkin) {
250 copy : egCore.idl.toHash(checkin.acp) || {},
251 call_number : egCore.idl.toHash(checkin.acn) || {},
252 copy_barcode : checkin.copy_barcode,
253 title : checkin.title,
254 author : checkin.author
257 print_data.checkins.push(checkin);
260 return egCore.print.print({
261 template : 'checkin',
263 show_dialog : $scope.show_print_dialog
268 // --- context menu actions
270 $scope.fetchLastCircPatron = function(items) {
271 var checkin = items[0];
272 if (!checkin || !checkin.acp) return;
274 egCirc.last_copy_circ(checkin.acp.id())
275 .then(function(circ) {
278 // jump to the patron UI (separate app)
279 $window.location.href = $location
280 .path('/circ/patron/' + circ.usr() + '/checkout')
285 $scope.alert = {item_never_circed : checkin.acp.barcode()};
289 $scope.showBackdateDialog = function(items) {
292 angular.forEach(items, function(item) {
293 if (item.circ) circ_ids.push(item.circ.id());
296 if (circ_ids.length) {
297 egCirc.backdate_dialog(circ_ids).then(function(result) {
298 angular.forEach(items, function(item) {
299 item.circ.checkin_time(result.backdate);
302 // TODO: support grid row styling
303 checkinGrid.refresh();
307 $scope.showMarkDamaged = function(items) {
309 angular.forEach(items, function(item) {
311 egCirc.mark_damaged({
313 barcode: item.acp.barcode()
321 $scope.abortTransit = function(items) {
322 var transit_ids = [];
323 angular.forEach(items, function(item) {
324 if (item.transit) transit_ids.push(item.transit.id());
327 egCirc.abort_transits(transit_ids).then(function() {
328 // update grid items?
332 $scope.add_copies_to_bucket = function(items){
334 angular.forEach(items, function(cp){
335 itemsIds.push(cp.acp.id());
338 itemSvc.add_copies_to_bucket(itemsIds);
341 $scope.showBibHolds = function(items){
343 angular.forEach(items, function(i){
344 recordIds.push(i.acn.record());
346 angular.forEach(recordIds, function (r) {
347 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
348 $timeout(function() { $window.open(url, '_blank') });
352 $scope.showLastCircs = function(items){
354 angular.forEach(items, function(cp){
355 itemIds.push(cp.acp.id());
357 angular.forEach(itemIds, function (id) {
358 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
359 $timeout(function() { $window.open(url, '_blank') });
363 $scope.selectedHoldingsVolCopyEdit = function (items) {
365 angular.forEach(items, function(i){
366 var h = egCore.idl.toHash(i);
368 'call_number.record.id': h.record.doc_id,
372 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
375 $scope.show_mark_missing_pieces = function(items){
376 angular.forEach(items, function(i){
377 i.acp.call_number(i.acn);
378 i.acp.call_number().record(i.record);
379 itemSvc.mark_missing_pieces(i.acp,$scope);
383 $scope.printSpineLabels = function(items){
385 angular.forEach(items, function(item) {
386 if (item.acp) copy_ids.push(item.acp.id());
388 itemSvc.print_spine_labels(copy_ids);
391 $scope.addCopyAlerts = function(items) {
393 angular.forEach(items, function(item) {
394 if (item.acp) copy_ids.push(item.acp.id());
396 egCirc.add_copy_alerts(copy_ids).then(function() {
397 // update grid items?
401 $scope.manageCopyAlerts = function(items) {
403 angular.forEach(items, function(item) {
404 if (item.acp) copy_ids.push(item.acp.id());
406 egCirc.manage_copy_alerts(copy_ids).then(function() {
407 // update grid items?