2 * Checkin, checkout, and renew
5 angular.module('egCoreMod')
9 ['$uibModal','$q','egCore','egAlertDialog','egConfirmDialog','egAddCopyAlertDialog','egCopyAlertManagerDialog','egCopyAlertEditorDialog',
11 function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog, egAddCopyAlertDialog , egCopyAlertManagerDialog, egCopyAlertEditorDialog ,
15 // auto-override these events after the first override
16 auto_override_checkout_events : {},
17 require_initials : false,
19 hold_shelf_slip : false,
20 hold_transit_slip : false,
25 egCore.startup.go().finally(function() {
27 'ui.staff.require_initials.patron_standing_penalty',
28 'ui.admin.work_log.max_entries',
29 'ui.admin.patron_log.max_entries',
30 'circ.staff_client.do_not_auto_attempt_print',
31 'circ.clear_hold_on_checkout'
32 ]).then(function(set) {
33 service.require_initials = Boolean(set['ui.staff.require_initials.patron_standing_penalty']);
34 service.clearHold = Boolean(set['circ.clear_hold_on_checkout']);
36 if (angular.isArray(set['circ.staff_client.do_not_auto_attempt_print'])) {
37 if (set['circ.staff_client.do_not_auto_attempt_print'].indexOf('Hold Slip') > 1)
38 service.never_auto_print['hold_shelf_slip'] = true;
39 if (set['circ.staff_client.do_not_auto_attempt_print'].indexOf('Hold/Transit Slip') > 1)
40 service.never_auto_print['hold_transit_slip'] = true;
41 if (set['circ.staff_client.do_not_auto_attempt_print'].indexOf('Transit Slip') > 1)
42 service.never_auto_print['transit_slip'] = true;
47 service.reset = function() {
48 service.auto_override_checkout_events = {};
51 // these events can be overridden by staff during checkout
52 service.checkout_overridable_events = [
53 'PATRON_EXCEEDS_OVERDUE_COUNT',
54 'PATRON_EXCEEDS_CHECKOUT_COUNT',
55 'PATRON_EXCEEDS_FINES',
57 'CIRC_EXCEEDS_COPY_RANGE',
58 'ITEM_DEPOSIT_REQUIRED',
59 'ITEM_RENTAL_FEE_REQUIRED',
60 'PATRON_EXCEEDS_LOST_COUNT',
61 'COPY_CIRC_NOT_ALLOWED',
68 // after the first override of any of these events,
69 // auto-override them in subsequent calls.
70 service.checkout_auto_override_after_first = [
71 'PATRON_EXCEEDS_OVERDUE_COUNT',
73 'PATRON_EXCEEDS_LOST_COUNT',
74 'PATRON_EXCEEDS_CHECKOUT_COUNT',
75 'PATRON_EXCEEDS_FINES'
79 // overridable during renewal
80 service.renew_overridable_events = [
81 'PATRON_EXCEEDS_OVERDUE_COUNT',
82 'PATRON_EXCEEDS_LOST_COUNT',
83 'PATRON_EXCEEDS_CHECKOUT_COUNT',
84 'PATRON_EXCEEDS_FINES',
85 'CIRC_EXCEEDS_COPY_RANGE',
86 'ITEM_DEPOSIT_REQUIRED',
87 'ITEM_RENTAL_FEE_REQUIRED',
89 'COPY_CIRC_NOT_ALLOWED',
92 'COPY_NEEDED_FOR_HOLD',
93 'MAX_RENEWALS_REACHED',
94 'CIRC_CLAIMS_RETURNED'
97 // these checkin events do not produce alerts when
98 // options.suppress_alerts is in effect.
99 service.checkin_suppress_overrides = [
103 'PATRON_ACCOUNT_EXPIRED',
105 'CIRC_CLAIMS_RETURNED',
106 'COPY_ALERT_MESSAGE',
108 'COPY_STATUS_LOST_AND_PAID',
109 'COPY_STATUS_LONG_OVERDUE',
110 'COPY_STATUS_MISSING',
111 'PATRON_EXCEEDS_FINES'
114 // these events can be overridden by staff during checkin
115 service.checkin_overridable_events =
116 service.checkin_suppress_overrides.concat([
117 'HOLD_CAPTURE_DELAYED', // not technically overridable, but special prompt and param
118 'TRANSIT_CHECKIN_INTERVAL_BLOCK'
121 // Performs a checkout.
122 // Returns a promise resolved with the original params and options
123 // and the final checkout event (e.g. in the case of override).
124 // Rejected if the checkout cannot be completed.
126 // params : passed directly as arguments to the server API
127 // options : non-parameter controls. e.g. "override", "check_barcode"
128 service.checkout = function(params, options) {
129 if (!options) options = {};
130 params.new_copy_alerts = 1;
132 console.debug('egCirc.checkout() : '
133 + js2JSON(params) + ' : ' + js2JSON(options));
135 // handle barcode completion
136 return service.handle_barcode_completion(params.copy_barcode)
137 .then(function(barcode) {
138 console.debug('barcode after completion: ' + barcode);
139 params.copy_barcode = barcode;
141 var promise = options.check_barcode ?
142 service.test_barcode(params.copy_barcode) : $q.when();
144 // avoid re-check on override, etc.
145 delete options.check_barcode;
147 return promise.then(function() {
149 var method = 'open-ils.circ.checkout.full';
150 if (options.override) method += '.override';
152 return egCore.net.request(
153 'open-ils.circ', method, egCore.auth.token(), params
155 ).then(function(evt) {
157 if (!angular.isArray(evt)) evt = [evt];
159 if (evt[0].payload && evt[0].payload.auto_renew == 1) {
160 // open circulation found with auto-renew toggle on.
161 console.debug('Auto-renewing item ' + params.copy_barcode);
162 options.auto_renew = true;
163 return service.renew(params, options);
166 var action = params.noncat ? 'noncat_checkout' : 'checkout';
168 return service.flesh_response_data(action, evt, params, options)
170 return service.handle_checkout_resp(evt, params, options);
172 .then(function(final_resp) {
173 return service.munge_resp_data(final_resp,action,method)
180 // Performs a renewal.
181 // Returns a promise resolved with the original params and options
182 // and the final checkout event (e.g. in the case of override)
183 // Rejected if the renewal cannot be completed.
184 service.renew = function(params, options) {
185 if (!options) options = {};
186 params.new_copy_alerts = 1;
188 console.debug('egCirc.renew() : '
189 + js2JSON(params) + ' : ' + js2JSON(options));
191 // handle barcode completion
192 return service.handle_barcode_completion(params.copy_barcode)
193 .then(function(barcode) {
194 params.copy_barcode = barcode;
196 var promise = options.check_barcode ?
197 service.test_barcode(params.copy_barcode) : $q.when();
199 // avoid re-check on override, etc.
200 delete options.check_barcode;
202 return promise.then(function() {
204 var method = 'open-ils.circ.renew';
205 if (options.override) method += '.override';
207 return egCore.net.request(
208 'open-ils.circ', method, egCore.auth.token(), params
210 ).then(function(evt) {
212 if (!angular.isArray(evt)) evt = [evt];
214 return service.flesh_response_data(
215 'renew', evt, params, options)
217 return service.handle_renew_resp(evt, params, options);
219 .then(function(final_resp) {
220 final_resp.auto_renew = options.auto_renew;
221 return service.munge_resp_data(final_resp,'renew',method)
228 // Performs a checkin
229 // Returns a promise resolved with the original params and options,
230 // plus the final checkin event (e.g. in the case of override).
231 // Rejected if the checkin cannot be completed.
232 service.checkin = function(params, options) {
233 if (!options) options = {};
234 params.new_copy_alerts = 1;
236 console.debug('egCirc.checkin() : '
237 + js2JSON(params) + ' : ' + js2JSON(options));
239 // handle barcode completion
240 return service.handle_barcode_completion(params.copy_barcode)
241 .then(function(barcode) {
242 params.copy_barcode = barcode;
244 var promise = options.check_barcode ?
245 service.test_barcode(params.copy_barcode) : $q.when();
247 // avoid re-check on override, etc.
248 delete options.check_barcode;
250 return promise.then(function() {
252 var method = 'open-ils.circ.checkin';
253 if (options.override) method += '.override';
255 return egCore.net.request(
256 'open-ils.circ', method, egCore.auth.token(), params
258 ).then(function(evt) {
260 if (!angular.isArray(evt)) evt = [evt];
261 return service.flesh_response_data(
262 'checkin', evt, params, options)
264 return service.handle_checkin_resp(evt, params, options);
266 .then(function(final_resp) {
267 return service.munge_resp_data(final_resp,'checkin',method)
274 // provide consistent formatting of the final response data
275 service.munge_resp_data = function(final_resp,worklog_action,worklog_method) {
276 var data = final_resp.data = {};
278 if (!final_resp.evt[0]) {
279 egCore.audio.play('error.unknown.no_event');
283 var payload = final_resp.evt[0].payload;
285 egCore.audio.play('error.unknown.no_payload');
289 // retrieve call number affixes prior to sending payload data to the grid
290 if (payload.volume && typeof payload.volume.prefix() != 'object') {
291 egCore.pcrud.retrieve('acnp',payload.volume.prefix()).then(function(p) {payload.volume.prefix(p)});
293 if (payload.volume && typeof payload.volume.suffix() != 'object') {
294 egCore.pcrud.retrieve('acns',payload.volume.suffix()).then(function(s) {payload.volume.suffix(s)});
297 data.circ = payload.circ;
298 data.parent_circ = payload.parent_circ;
299 data.hold = payload.hold;
300 data.record = payload.record;
301 data.acp = payload.copy;
302 data.acn = payload.volume ? payload.volume : payload.copy ? payload.copy.call_number() : null;
303 data.au = payload.patron;
304 data.transit = payload.transit;
305 data.status = payload.status;
306 data.message = payload.message;
307 data.title = final_resp.evt[0].title;
308 data.author = final_resp.evt[0].author;
309 data.isbn = final_resp.evt[0].isbn;
310 data.route_to = final_resp.evt[0].route_to;
312 if (payload.circ) data.duration = payload.circ.duration();
313 if (payload.circ) data.circ_lib = payload.circ.circ_lib();
315 // for checkin, the mbts lives on the main circ
316 if (payload.circ && payload.circ.billable_transaction())
317 data.mbts = payload.circ.billable_transaction().summary();
319 // on renewals, the mbts lives on the parent circ
320 if (payload.parent_circ && payload.parent_circ.billable_transaction())
321 data.mbts = payload.parent_circ.billable_transaction().summary();
323 if (!data.route_to) {
325 data.route_to = data.transit.dest().shortname();
326 } else if (data.acp) {
327 data.route_to = data.acp.location().name();
332 (worklog_action == 'checkout' || worklog_action == 'noncat_checkout')
333 ? egCore.strings.EG_WORK_LOG_CHECKOUT
334 : (worklog_action == 'renew'
335 ? egCore.strings.EG_WORK_LOG_RENEW
336 : egCore.strings.EG_WORK_LOG_CHECKIN // worklog_action == 'checkin'
338 'action' : worklog_action,
339 'method' : worklog_method,
340 'response' : final_resp
347 service.handle_overridable_checkout_event = function(evt, params, options) {
349 if (options.override) {
350 // override attempt already made and failed.
351 // NOTE: I don't think we'll ever get here, since the
352 // override attempt should produce a perm failure...
353 angular.forEach(evt, function(e){ console.debug('override failed: ' + e.textcode); });
358 if (evt.filter(function(e){return !service.auto_override_checkout_events[e.textcode];}).length == 0) {
359 // user has already opted to override these type
360 // of events. Re-run the checkout w/ override.
361 options.override = true;
362 return service.checkout(params, options);
365 // Ask the user if they would like to override this event.
366 // Some events offer a stock override dialog, while others
367 // require additional context.
369 switch(evt[0].textcode) {
370 case 'COPY_NOT_AVAILABLE':
371 return service.copy_not_avail_dialog(evt, params, options);
372 case 'COPY_ALERT_MESSAGE':
373 return service.copy_alert_dialog(evt[0], params, options, 'checkout');
375 return service.override_dialog(evt, params, options, 'checkout');
379 service.handle_overridable_renew_event = function(evt, params, options) {
381 if (options.override) {
382 // override attempt already made and failed.
383 // NOTE: I don't think we'll ever get here, since the
384 // override attempt should produce a perm failure...
385 angular.forEach(evt, function(e){ console.debug('override failed: ' + e.textcode); });
390 // renewal auto-overrides are the same as checkout
391 if (evt.filter(function(e){return !service.auto_override_checkout_events[e.textcode];}).length == 0) {
392 // user has already opted to override these type
393 // of events. Re-run the renew w/ override.
394 options.override = true;
395 return service.renew(params, options);
398 // Ask the user if they would like to override this event.
399 // Some events offer a stock override dialog, while others
400 // require additional context.
402 switch(evt[0].textcode) {
403 case 'COPY_ALERT_MESSAGE':
404 return service.copy_alert_dialog(evt[0], params, options, 'renew');
406 return service.override_dialog(evt, params, options, 'renew');
411 service.handle_overridable_checkin_event = function(evt, params, options) {
413 if (options.override) {
414 // override attempt already made and failed.
415 // NOTE: I don't think we'll ever get here, since the
416 // override attempt should produce a perm failure...
417 angular.forEach(evt, function(e){ console.debug('override failed: ' + e.textcode); });
422 if (options.suppress_checkin_popups
423 && evt.filter(function(e){return service.checkin_suppress_overrides.indexOf(e.textcode) == -1;}).length == 0) {
424 // Events are suppressed. Re-run the checkin w/ override.
425 options.override = true;
426 return service.checkin(params, options);
429 // Ask the user if they would like to override this event.
430 // Some events offer a stock override dialog, while others
431 // require additional context.
433 switch(evt[0].textcode) {
434 case 'COPY_ALERT_MESSAGE':
435 return service.copy_alert_dialog(evt[0], params, options, 'checkin');
436 case 'HOLD_CAPTURE_DELAYED':
437 return service.hold_capture_delay_dialog(evt[0], params, options, 'checkin');
439 return service.override_dialog(evt, params, options, 'checkin');
444 service.handle_renew_resp = function(evt, params, options) {
446 var final_resp = {evt : evt, params : params, options : options};
448 // track the barcode regardless of whether it refers to a copy
449 angular.forEach(evt, function(e){ e.copy_barcode = params.copy_barcode; });
451 // Overridable Events
452 if (evt.filter(function(e){return service.renew_overridable_events.indexOf(e.textcode) > -1;}).length > 0)
453 return service.handle_overridable_renew_event(evt, params, options);
456 switch (evt[0].textcode) {
458 egCore.audio.play('info.renew');
459 return $q.when(final_resp);
461 case 'COPY_IN_TRANSIT':
462 case 'PATRON_CARD_INACTIVE':
463 case 'PATRON_INACTIVE':
464 case 'PATRON_ACCOUNT_EXPIRED':
465 case 'CIRC_CLAIMS_RETURNED':
466 egCore.audio.play('warning.renew');
467 return service.exit_alert(
468 egCore.strings[evt[0].textcode],
469 {barcode : params.copy_barcode}
473 egCore.audio.play('warning.renew.unknown');
474 return service.exit_alert(
475 egCore.strings.CHECKOUT_FAILED_GENERIC, {
476 barcode : params.copy_barcode,
477 textcode : evt[0].textcode,
485 service.handle_checkout_resp = function(evt, params, options) {
487 var final_resp = {evt : evt, params : params, options : options};
489 // track the barcode regardless of whether it refers to a copy
490 angular.forEach(evt, function(e){ e.copy_barcode = params.copy_barcode; });
492 // Overridable Events
493 if (evt.filter(function(e){return service.checkout_overridable_events.indexOf(e.textcode) > -1;}).length > 0)
494 return service.handle_overridable_checkout_event(evt, params, options);
497 switch (evt[0].textcode) {
499 egCore.audio.play('success.checkout');
500 return $q.when(final_resp);
502 case 'ITEM_NOT_CATALOGED':
503 egCore.audio.play('error.checkout.no_cataloged');
504 return service.precat_dialog(params, options);
506 case 'OPEN_CIRCULATION_EXISTS':
507 // auto_renew checked in service.checkout()
508 egCore.audio.play('error.checkout.open_circ');
509 return service.circ_exists_dialog(evt, params, options);
511 case 'COPY_IN_TRANSIT':
512 egCore.audio.play('warning.checkout.in_transit');
513 return service.copy_in_transit_dialog(evt, params, options);
515 case 'PATRON_CARD_INACTIVE':
516 case 'PATRON_INACTIVE':
517 case 'PATRON_ACCOUNT_EXPIRED':
518 case 'CIRC_CLAIMS_RETURNED':
519 egCore.audio.play('warning.checkout');
520 return service.exit_alert(
521 egCore.strings[evt[0].textcode],
522 {barcode : params.copy_barcode}
526 egCore.audio.play('error.checkout.unknown');
527 return service.exit_alert(
528 egCore.strings.CHECKOUT_FAILED_GENERIC, {
529 barcode : params.copy_barcode,
530 textcode : evt[0].textcode,
537 // returns a promise resolved with the list of circ mods
538 service.get_circ_mods = function() {
540 return $q.when(egCore.env.ccm.list);
542 return egCore.pcrud.retrieveAll('ccm', null, {atomic : true})
543 .then(function(list) {
544 egCore.env.absorbList(list, 'ccm');
549 // returns a promise resolved with the list of noncat types
550 service.get_noncat_types = function() {
552 return $q.when(egCore.env.cnct.list);
554 return egCore.pcrud.search('cnct',
556 egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
557 null, {atomic : true}
558 ).then(function(list) {
559 egCore.env.absorbList(list, 'cnct');
564 service.get_staff_penalty_types = function() {
566 return $q.when(egCore.env.csp.list);
567 return egCore.pcrud.search(
568 // id <= 100 are reserved for system use
569 'csp', {id : {'>': 100}}, {}, {atomic : true})
570 .then(function(penalties) {
571 return egCore.env.absorbList(penalties, 'csp').list;
575 // ideally all of these data should be returned with the response,
576 // but until then, grab what we need.
577 service.flesh_response_data = function(action, evt, params, options) {
580 if (!evt[0] || !(payload = evt[0].payload)) return $q.when();
582 promises.push(service.flesh_copy_location(payload.copy));
584 promises.push(service.flesh_acn_owning_lib(payload.volume));
585 promises.push(service.flesh_copy_circ_library(payload.copy));
586 promises.push(service.flesh_copy_circ_modifier(payload.copy));
588 service.flesh_copy_status(payload.copy)
591 // copy is in transit, but no transit was delivered
592 // in the payload. Do this here instead of below to
593 // ensure consistent copy status fleshiness
594 if (!payload.transit && payload.copy.status().id() == 6) { // in-transit
595 return service.find_copy_transit(evt, params, options)
596 .then(function(trans) {
598 trans.source(egCore.org.get(trans.source()));
599 trans.dest(egCore.org.get(trans.dest()));
600 payload.transit = trans;
608 // local flesh transit
609 if (transit = payload.transit) {
610 transit.source(egCore.org.get(transit.source()));
611 transit.dest(egCore.org.get(transit.dest()));
614 // TODO: renewal responses should include the patron
615 if (!payload.patron) {
617 if (payload.circ) user_id = payload.circ.usr();
618 if (payload.noncat_circ) user_id = payload.noncat_circ.patron();
621 egCore.pcrud.retrieve('au', user_id)
622 .then(function(user) {payload.patron = user})
627 // extract precat values
628 angular.forEach(evt, function(e){ e.title = payload.record ? payload.record.title() :
629 (payload.copy ? payload.copy.dummy_title() : null);});
631 angular.forEach(evt, function(e){ e.author = payload.record ? payload.record.author() :
632 (payload.copy ? payload.copy.dummy_author() : null);});
634 angular.forEach(evt, function(e){ e.isbn = payload.record ? payload.record.isbn() :
635 (payload.copy ? payload.copy.dummy_isbn() : null);});
637 return $q.all(promises);
640 service.flesh_acn_owning_lib = function(acn) {
641 if (!acn) return $q.when();
642 return $q.when(acn.owning_lib(egCore.org.get( acn.owning_lib() )));
645 service.flesh_copy_circ_library = function(copy) {
646 if (!copy) return $q.when();
648 return $q.when(copy.circ_lib(egCore.org.get( copy.circ_lib() )));
651 // fetches the full list of circ modifiers
652 service.flesh_copy_circ_modifier = function(copy) {
653 if (!copy) return $q.when();
655 return $q.when(copy.circ_modifier(egCore.env.ccm.map[copy.circ_modifier()]));
656 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
658 egCore.env.absorbList(list, 'ccm');
659 copy.circ_modifier(egCore.env.ccm.map[copy.circ_modifier()]);
664 // fetches the full list of copy statuses
665 service.flesh_copy_status = function(copy) {
666 if (!copy) return $q.when();
668 return $q.when(copy.status(egCore.env.ccs.map[copy.status()]));
669 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
671 egCore.env.absorbList(list, 'ccs');
672 copy.status(egCore.env.ccs.map[copy.status()]);
677 // there may be *many* copy locations and we may be handling items
678 // for other locations. Fetch copy locations as-needed and cache.
679 service.flesh_copy_location = function(copy) {
680 if (!copy) return $q.when();
681 if (angular.isObject(copy.location())) return $q.when(copy);
682 if (egCore.env.acpl) {
683 if (egCore.env.acpl.map[copy.location()]) {
684 copy.location(egCore.env.acpl.map[copy.location()]);
685 return $q.when(copy);
688 return egCore.pcrud.retrieve('acpl', copy.location())
689 .then(function(loc) {
690 egCore.env.absorbList([loc], 'acpl'); // append to cache
697 // fetch org unit addresses as needed.
698 service.get_org_addr = function(org_id, addr_type) {
699 var org = egCore.org.get(org_id);
700 var addr_id = org[addr_type]();
702 if (!addr_id) return $q.when(null);
704 if (egCore.env.aoa && egCore.env.aoa.map[addr_id])
705 return $q.when(egCore.env.aoa.map[addr_id]);
707 return egCore.pcrud.retrieve('aoa', addr_id).then(function(addr) {
708 egCore.env.absorbList([addr], 'aoa');
709 return egCore.env.aoa.map[addr_id];
713 service.exit_alert = function(msg, scope) {
714 return egAlertDialog.open(msg, scope).result.then(
715 function() {return $q.reject()});
718 // opens a dialog asking the user if they would like to override
719 // the returned event.
720 service.override_dialog = function(evt, params, options, action) {
721 if (!angular.isArray(evt)) evt = [evt];
723 egCore.audio.play('warning.circ.event_override');
724 var copy_alert = evt.filter(function(e) {
725 return e.textcode == 'COPY_ALERT_MESSAGE';
727 evt = evt.filter(function(e) {
728 return e.textcode !== 'COPY_ALERT_MESSAGE';
731 return $uibModal.open({
732 templateUrl: './circ/share/t_event_override_dialog',
735 ['$scope', '$uibModalInstance',
736 function($scope, $uibModalInstance) {
739 // Find the event, if any, that is for ITEM_ON_HOLDS_SHELF
740 // and grab the patron name of the owner.
741 $scope.holdEvent = evt.filter(function(e) {
742 return e.textcode === 'ITEM_ON_HOLDS_SHELF'
745 if ($scope.holdEvent.length > 0) {
746 // Ensure we have a scalar here
747 if (angular.isArray($scope.holdEvent)) {
748 $scope.holdEvent = $scope.holdEvent[0];
751 $scope.patronName = $scope.holdEvent.payload.patron_name;
752 $scope.holdID = $scope.holdEvent.payload.hold_id;
753 $scope.patronID = $scope.holdEvent.payload.patron_id;
756 $scope.auto_override =
757 evt.filter(function(e){
758 return service.checkout_auto_override_after_first.indexOf(evt.textcode) > -1;
760 $scope.copy_barcode = params.copy_barcode; // may be null
762 // Implementation note: Why not use a primitive here? It
763 // doesn't work. See:
764 // http://stackoverflow.com/questions/18642371/checkbox-not-binding-to-scope-in-angularjs
765 $scope.formdata = {clearHold : service.clearHold};
767 $scope.ok = function() {
768 // Handle the cancellation of the assciated hold here
769 if ($scope.formdata.clearHold && $scope.holdID) {
772 'open-ils.circ.hold.cancel',
773 egCore.auth.token(), $scope.holdID,
775 'Item checked out by other patron' // FIXME I18n
778 $uibModalInstance.close();
781 $scope.cancel = function ($event) {
782 $uibModalInstance.dismiss();
783 $event.preventDefault();
788 options.override = true;
790 if (copy_alert.length > 0) {
791 return service.copy_alert_dialog(copy_alert, params, options, action);
794 if (action == 'checkin') {
795 return service.checkin(params, options);
798 // checkout/renew support override-after-first
799 angular.forEach(evt, function(e){
800 if (service.checkout_auto_override_after_first.indexOf(e.textcode) > -1)
801 service.auto_override_checkout_events[e.textcode] = true;
804 return service[action](params, options);
809 service.copy_not_avail_dialog = function(evt, params, options) {
810 if (!angular.isArray(evt)) evt = [evt];
812 var copy_alert = evt.filter(function(e) {
813 return e.textcode == 'COPY_ALERT_MESSAGE';
815 evt = evt.filter(function(e) {
816 return e.textcode !== 'COPY_ALERT_MESSAGE';
820 return $uibModal.open({
821 templateUrl: './circ/share/t_copy_not_avail_dialog',
824 ['$scope','$uibModalInstance','copyStatus',
825 function($scope , $uibModalInstance , copyStatus) {
826 $scope.copyStatus = copyStatus;
827 $scope.ok = function() {$uibModalInstance.close()}
828 $scope.cancel = function() {$uibModalInstance.dismiss()}
831 copyStatus : function() {
832 return egCore.pcrud.retrieve(
833 'ccs', evt.payload.status());
838 options.override = true;
840 if (copy_alert.length > 0) {
841 return service.copy_alert_dialog(copy_alert, params, options, 'checkout');
844 return service.checkout(params, options);
849 // Opens a dialog allowing the user to fill in the desired non-cat count.
850 // Unlike other dialogs, which kickoff circ actions internally
851 // as a result of events, this dialog does not kick off any circ
852 // actions. It just collects the count and and resolves the promise.
854 // This assumes the caller has already handled the noncat-type
855 // selection and just needs to collect the count info.
856 service.noncat_dialog = function(params, options) {
857 var noncatMax = 99; // hard-coded max
859 // the caller should presumably have fetched the noncat_types via
860 // our API already, but fetch them again (from cache) to be safe.
861 return service.get_noncat_types().then(function() {
863 params.noncat = true;
864 var type = egCore.env.cnct.map[params.noncat_type];
866 return $uibModal.open({
867 templateUrl: './circ/share/t_noncat_dialog',
870 ['$scope', '$uibModalInstance',
871 function($scope, $uibModalInstance) {
872 $scope.focusMe = true;
875 $scope.noncatMax = noncatMax;
876 $scope.ok = function(count) { $uibModalInstance.close(count) }
877 $scope.cancel = function ($event) {
878 $uibModalInstance.dismiss()
879 $event.preventDefault();
884 if (count && count > 0 && count <= noncatMax) {
885 // NOTE: in Chrome, form validation ensure a valid number
886 params.noncat_count = count;
887 return $q.when(params);
896 // Opens a dialog allowing the user to fill in pre-cat copy info.
897 service.precat_dialog = function(params, options) {
899 return $uibModal.open({
900 templateUrl: './circ/share/t_precat_dialog',
903 ['$scope', '$uibModalInstance', 'circMods',
904 function($scope, $uibModalInstance, circMods) {
905 $scope.focusMe = true;
906 $scope.precatArgs = {
907 copy_barcode : params.copy_barcode
909 $scope.circModifiers = circMods;
910 $scope.ok = function(args) { $uibModalInstance.close(args) }
911 $scope.cancel = function () { $uibModalInstance.dismiss() }
913 // use this function as a keydown handler on form
914 // elements that should not submit the form on enter.
915 $scope.preventSubmit = function($event) {
916 if ($event.keyCode == 13)
917 $event.preventDefault();
921 circMods : function() {
922 return service.get_circ_mods();
927 if (!args || !args.dummy_title) return $q.reject();
928 if(args.circ_modifier == "") args.circ_modifier = null;
929 angular.forEach(args, function(val, key) {params[key] = val});
930 params.precat = true;
931 return service.checkout(params, options);
936 // find the open transit for the given copy barcode; flesh the org
938 service.find_copy_transit = function(evt, params, options) {
939 if (angular.isArray(evt)) evt = evt[0];
941 // NOTE: evt.payload.transit may exist, but it's not necessarily
942 // the transit we want, since a transit close + open in the API
943 // returns the closed transit.
945 return egCore.pcrud.search('atc',
946 { dest_recv_time : null, cancel_time : null},
948 flesh_fields : {atc : ['target_copy']},
952 barcode : params.copy_barcode,
958 order_by : {atc : 'source_send_time desc'},
959 }, {authoritative : true}
960 ).then(function(transit) {
961 transit.source(egCore.org.get(transit.source()));
962 transit.dest(egCore.org.get(transit.dest()));
967 service.copy_in_transit_dialog = function(evt, params, options) {
968 if (angular.isArray(evt)) evt = evt[0];
969 return $uibModal.open({
970 templateUrl: './circ/share/t_copy_in_transit_dialog',
973 ['$scope','$uibModalInstance','transit',
974 function($scope , $uibModalInstance , transit) {
975 $scope.transit = transit;
976 $scope.ok = function() { $uibModalInstance.close(transit) }
977 $scope.cancel = function() { $uibModalInstance.dismiss() }
980 // fetch the conflicting open transit w/ fleshed copy
981 transit : function() {
982 return service.find_copy_transit(evt, params, options);
987 // user chose to abort the transit then checkout
988 return service.abort_transit(transit.id())
990 return service.checkout(params, options);
996 service.abort_transit = function(transit_id) {
997 return egCore.net.request(
999 'open-ils.circ.transit.abort',
1000 egCore.auth.token(), {transitid : transit_id}
1001 ).then(function(resp) {
1002 if (evt = egCore.evt.parse(resp)) {
1010 service.last_copy_circ = function(copy_id) {
1011 return egCore.pcrud.search('circ',
1012 {target_copy : copy_id},
1013 {order_by : {circ : 'xact_start desc' }, limit : 1}
1017 service.circ_exists_dialog = function(evt, params, options) {
1018 if (angular.isArray(evt)) evt = evt[0];
1020 if (!evt.payload.old_circ) {
1021 return egCore.net.request(
1023 'open-ils.search.asset.copy.fleshed2.find_by_barcode',
1025 ).then(function(resp){
1027 if (egCore.evt.parse(resp)) {
1028 console.error(egCore.evt.parse(resp));
1030 return egCore.net.request(
1032 'open-ils.circ.copy_checkout_history.retrieve',
1033 egCore.auth.token(), resp.id(), 1
1034 ).then( function (circs) {
1035 evt.payload.old_circ = circs[0];
1036 return service.circ_exists_dialog_impl( evt, params, options );
1041 return service.circ_exists_dialog_impl( evt, params, options );
1045 service.circ_exists_dialog_impl = function (evt, params, options) {
1047 var openCirc = evt.payload.old_circ;
1048 var sameUser = openCirc.usr() == params.patron_id;
1050 return $uibModal.open({
1051 templateUrl: './circ/share/t_circ_exists_dialog',
1054 ['$scope','$uibModalInstance',
1055 function($scope , $uibModalInstance) {
1056 $scope.args = {forgive_fines : false};
1057 $scope.circDate = openCirc.xact_start();
1058 $scope.sameUser = sameUser;
1059 $scope.ok = function() { $uibModalInstance.close($scope.args) }
1060 $scope.cancel = function($event) {
1061 $uibModalInstance.dismiss();
1062 $event.preventDefault(); // form, avoid calling ok();
1068 params.void_overdues = args.forgive_fines;
1069 return service.renew(params, options);
1072 return service.checkin({
1073 barcode : params.copy_barcode,
1075 void_overdues : args.forgive_fines
1076 }).then(function(checkin_resp) {
1077 if (checkin_resp.evt[0].textcode == 'SUCCESS') {
1078 return service.checkout(params, options);
1080 alert(egCore.evt.parse(checkin_resp.evt[0]));
1088 service.batch_backdate = function(circ_ids, backdate) {
1089 return egCore.net.request(
1091 'open-ils.circ.post_checkin_backdate.batch',
1092 egCore.auth.token(), circ_ids, backdate);
1095 service.backdate_dialog = function(circ_ids) {
1096 return $uibModal.open({
1097 templateUrl: './circ/share/t_backdate_dialog',
1100 ['$scope','$uibModalInstance',
1101 function($scope , $uibModalInstance) {
1103 var today = new Date();
1105 num_circs : circ_ids.length,
1110 $scope.$watch('dialog.backdate', function(newval) {
1111 if (newval && newval > today)
1112 $scope.dialog.backdate = today;
1116 $scope.cancel = function() {
1117 $uibModalInstance.dismiss();
1120 $scope.ok = function() {
1122 var bd = $scope.dialog.backdate.toISOString().replace(/T.*/,'');
1123 service.batch_backdate(circ_ids, bd)
1125 function() { // on complete
1126 $uibModalInstance.close({backdate : bd});
1129 function(resp) { // on response
1130 console.debug('backdate returned ' + resp);
1132 $scope.num_processed++;
1134 console.error(egCore.evt.parse(resp));
1143 service.mark_claims_returned = function(barcode, date, override) {
1145 var method = 'open-ils.circ.circulation.set_claims_returned';
1146 if (override) method += '.override';
1148 console.debug('claims returned ' + method);
1150 return egCore.net.request(
1151 'open-ils.circ', method, egCore.auth.token(),
1152 {barcode : barcode, backdate : date})
1154 .then(function(resp) {
1156 if (resp == 1) { // success
1157 console.debug('claims returned succeeded for ' + barcode);
1160 } else if (evt = egCore.evt.parse(resp)) {
1161 console.debug('claims returned failed: ' + evt.toString());
1163 if (evt.textcode == 'PATRON_EXCEEDS_CLAIMS_RETURN_COUNT') {
1164 // TODO check perms before offering override option?
1166 if (override) return;// just to be safe
1168 return egConfirmDialog.open(
1169 egCore.strings.TOO_MANY_CLAIMS_RETURNED, '', {}
1170 ).result.then(function() {
1171 return service.mark_claims_returned(barcode, date, true);
1175 if (evt.textcode == 'PERM_FAILURE') {
1176 console.error('claims returned permission denied')
1177 // TODO: auth override dialog?
1183 service.mark_claims_returned_dialog = function(copy_barcodes) {
1184 if (!copy_barcodes.length) return;
1186 return $uibModal.open({
1187 templateUrl: './circ/share/t_mark_claims_returned_dialog',
1190 ['$scope','$uibModalInstance',
1191 function($scope , $uibModalInstance) {
1193 var today = new Date();
1195 barcodes : copy_barcodes,
1199 $scope.$watch('args.date', function(newval) {
1200 if (newval && newval > today)
1201 $scope.args.backdate = today;
1204 $scope.cancel = function() {$uibModalInstance.dismiss()}
1205 $scope.ok = function() {
1207 var date = $scope.args.date.toISOString().replace(/T.*/,'');
1209 var deferred = $q.defer();
1211 // serialize the action on each barcode so that the
1212 // caller will never see multiple alerts at the same time.
1213 function mark_one() {
1214 var bc = copy_barcodes.pop();
1217 $uibModalInstance.close();
1221 // finally -> continue even when one fails
1222 service.mark_claims_returned(bc, date)
1223 .finally(function(barcode) {
1224 if (barcode) deferred.notify(barcode);
1228 mark_one(); // kick it off
1229 return deferred.promise;
1235 // serially checks in each barcode with claims_never_checked_out set
1236 // returns promise, notified on each barcode, resolved after all
1237 // checkins are complete.
1238 service.mark_claims_never_checked_out = function(barcodes) {
1239 if (!barcodes.length) return;
1241 var deferred = $q.defer();
1242 egConfirmDialog.open(
1243 egCore.strings.MARK_NEVER_CHECKED_OUT, '', {barcodes : barcodes}
1245 ).result.then(function() {
1246 function mark_one() {
1247 var bc = barcodes.pop();
1249 if (!bc) { // all done
1255 {claims_never_checked_out : true, copy_barcode : bc})
1256 .finally(function() {
1257 deferred.notify(bc);
1264 return deferred.promise;
1267 service.mark_damaged = function(params) {
1268 if (!params) return $q.when();
1269 return $uibModal.open({
1270 templateUrl: './circ/share/t_mark_damaged',
1272 ['$scope', '$uibModalInstance', 'egCore', 'egBilling', 'egItem',
1273 function($scope, $uibModalInstance, egCore, egBilling, egItem) {
1274 var doRefresh = params.refresh;
1276 $scope.billArgs = {charge: params.charge};
1277 $scope.mode = 'charge';
1278 $scope.barcode = params.barcode;
1279 if (params.charge && params.charge > 0) {
1280 $scope.applyFine = "apply";
1283 $scope.circ = params.circ;
1284 $scope.circ_checkin_time = params.circ.checkin_time();
1285 $scope.circ_patron_name = params.circ.usr().family_name() + ", "
1286 + params.circ.usr().first_given_name() + " "
1287 + params.circ.usr().second_given_name();
1289 egBilling.fetchBillingTypes().then(function(res) {
1290 $scope.billingTypes = res;
1293 $scope.btnChargeFees = function() {
1294 $scope.mode = 'charge';
1295 $scope.billArgs.charge = params.charge;
1296 $scope.applyFine = "apply";
1298 $scope.btnWaiveFees = function() {
1299 $scope.mode = 'waive';
1300 $scope.billArgs.charge = 0;
1301 $scope.applyFine = "noapply";
1304 $scope.cancel = function ($event) {
1305 $uibModalInstance.dismiss();
1307 $scope.ok = function() {
1308 handle_mark_item_damaged();
1311 var handle_mark_item_damaged = function() {
1314 'open-ils.circ.mark_item_damaged',
1315 egCore.auth.token(), params.id, {
1316 apply_fines: $scope.applyFine,
1317 override_amount: $scope.billArgs.charge,
1318 override_btype: $scope.billArgs.type,
1319 override_note: $scope.billArgs.note,
1320 handle_checkin: !$scope.applyFine
1321 }).then(function(resp) {
1322 if (evt = egCore.evt.parse(resp)) {
1324 console.debug("mark damaged more information required. Pushing back.");
1325 service.mark_damaged({
1327 barcode: params.barcode,
1328 charge: evt.payload.charge,
1329 circ: evt.payload.circ,
1330 refresh: params.refresh
1332 console.error('mark damaged failed: ' + evt);
1334 }).then(function() {
1335 if (doRefresh) egItem.add_barcode_to_list(params.barcode);
1337 $uibModalInstance.close();
1343 service.mark_missing = function(copy_ids) {
1344 return egConfirmDialog.open(
1345 egCore.strings.MARK_MISSING_CONFIRM, '',
1346 { num_items : copy_ids.length,
1348 cancel : function() {}
1350 ).result.then(function() {
1352 angular.forEach(copy_ids, function(copy_id) {
1356 'open-ils.circ.mark_item_missing',
1357 egCore.auth.token(), copy_id
1358 ).then(function(resp) {
1359 if (evt = egCore.evt.parse(resp)) {
1360 console.error('mark missing failed: ' + evt);
1366 return $q.all(promises);
1372 // Mark circulations as lost via copy barcode. As each item is
1373 // processed, the returned promise is notified of the barcode.
1374 // No confirmation dialog is presented.
1375 service.mark_lost = function(copy_barcodes) {
1376 var deferred = $q.defer();
1379 angular.forEach(copy_barcodes, function(barcode) {
1383 'open-ils.circ.circulation.set_lost',
1384 egCore.auth.token(), {barcode : barcode}
1385 ).then(function(resp) {
1386 if (evt = egCore.evt.parse(resp)) {
1387 console.error("Mark lost failed: " + evt.toString());
1390 // inform the caller as each item is processed
1391 deferred.notify(barcode);
1396 $q.all(promises).then(function() {deferred.resolve()});
1397 return deferred.promise;
1400 service.abort_transits = function(transit_ids) {
1401 return egConfirmDialog.open(
1402 egCore.strings.ABORT_TRANSIT_CONFIRM, '',
1403 { num_transits : transit_ids.length,
1405 cancel : function() {}
1408 ).result.then(function() {
1410 angular.forEach(transit_ids, function(transit_id) {
1414 'open-ils.circ.transit.abort',
1415 egCore.auth.token(), {transitid : transit_id}
1416 ).then(function(resp) {
1417 if (evt = egCore.evt.parse(resp)) {
1418 console.error('abort transit failed: ' + evt);
1424 return $q.all(promises);
1428 service.add_copy_alerts = function(item_ids) {
1429 return egAddCopyAlertDialog.open({
1430 copy_ids : item_ids,
1431 ok : function() { },
1432 cancel : function() {}
1433 }).result.then(function() { });
1436 service.manage_copy_alerts = function(item_ids) {
1437 return egCopyAlertEditorDialog.open({
1438 copy_id : item_ids[0],
1439 ok : function() { },
1440 cancel : function() {}
1441 }).result.then(function() { });
1444 // alert when copy location alert_message is set.
1445 // This does not affect processing, it only produces a click-through
1446 service.handle_checkin_loc_alert = function(evt, params, options) {
1447 if (angular.isArray(evt)) evt = evt[0];
1449 var copy = evt && evt.payload ? evt.payload.copy : null;
1451 if (copy && !options.suppress_checkin_popups
1452 && copy.location().checkin_alert() == 't') {
1454 return egAlertDialog.open(
1455 egCore.strings.LOCATION_ALERT_MSG, {copy : copy}).result;
1461 service.handle_checkin_resp = function(evt, params, options) {
1462 if (!angular.isArray(evt)) evt = [evt];
1464 var final_resp = {evt : evt, params : params, options : options};
1466 var copy, hold, transit;
1467 if (evt[0].payload) {
1468 copy = evt[0].payload.copy;
1469 hold = evt[0].payload.hold;
1470 transit = evt[0].payload.transit;
1473 // track the barcode regardless of whether it's valid
1474 angular.forEach(evt, function(e){ e.copy_barcode = params.copy_barcode; });
1476 angular.forEach(evt, function(e){ console.debug('checkin event ' + e.textcode); });
1478 if (evt.filter(function(e){return service.checkin_overridable_events.indexOf(e.textcode) > -1;}).length > 0)
1479 return service.handle_overridable_checkin_event(evt, params, options);
1481 switch (evt[0].textcode) {
1486 switch(Number(copy.status().id())) {
1488 case 0: /* AVAILABLE */
1489 case 4: /* MISSING */
1490 case 7: /* RESHELVING */
1492 egCore.audio.play('success.checkin');
1494 // see if the copy location requires an alert
1495 return service.handle_checkin_loc_alert(evt, params, options)
1496 .then(function() {return final_resp});
1498 case 8: /* ON HOLDS SHELF */
1499 egCore.audio.play('info.checkin.holds_shelf');
1503 if (hold.pickup_lib() == egCore.auth.user().ws_ou()) {
1504 // inform user if the item is on the local holds shelf
1506 evt[0].route_to = egCore.strings.ROUTE_TO_HOLDS_SHELF;
1507 return service.route_dialog(
1508 './circ/share/t_hold_shelf_dialog',
1509 evt[0], params, options
1510 ).then(function() { return final_resp });
1513 // normally, if the hold was on the shelf at a
1514 // different location, it would be put into
1515 // transit, resulting in a ROUTE_ITEM event.
1516 egCore.audio.play('warning.checkin.wrong_shelf');
1517 return $q.when(final_resp);
1521 console.error('checkin: item on holds shelf, '
1522 + 'but hold info not returned from checkin');
1523 return $q.when(final_resp);
1526 case 11: /* CATALOGING */
1527 egCore.audio.play('info.checkin.cataloging');
1528 evt[0].route_to = egCore.strings.ROUTE_TO_CATALOGING;
1529 if (options.no_precat_alert)
1530 return $q.when(final_resp);
1531 return egAlertDialog.open(
1532 egCore.strings.PRECAT_CHECKIN_MSG, params)
1533 .result.then(function() {return final_resp});
1536 case 15: /* ON_RESERVATION_SHELF */
1537 egCore.audio.play('info.checkin.reservation');
1538 // TODO: show booking reservation dialog
1539 return $q.when(final_resp);
1542 egCore.audio.play('success.checkin');
1543 console.debug('Unusual checkin copy status (may have been set via copy alert): '
1544 + copy.status().id() + ' : ' + copy.status().name());
1545 return $q.when(final_resp);
1549 return service.route_dialog(
1550 './circ/share/t_transit_dialog',
1551 evt[0], params, options
1552 ).then(function() { return final_resp });
1554 case 'ASSET_COPY_NOT_FOUND':
1555 egCore.audio.play('error.checkin.not_found');
1556 return egAlertDialog.open(
1557 egCore.strings.UNCAT_ALERT_DIALOG, params)
1558 .result.then(function() {return final_resp});
1560 case 'ITEM_NOT_CATALOGED':
1561 egCore.audio.play('error.checkin.not_cataloged');
1562 evt[0].route_to = egCore.strings.ROUTE_TO_CATALOGING;
1563 if (options.no_precat_alert)
1564 return $q.when(final_resp);
1565 return egAlertDialog.open(
1566 egCore.strings.PRECAT_CHECKIN_MSG, params)
1567 .result.then(function() {return final_resp});
1570 egCore.audio.play('error.checkin.unknown');
1571 console.warn('unhandled checkin response : ' + evt[0].textcode);
1572 return $q.when(final_resp);
1576 // collect transit, address, and hold info that's not already
1577 // included in responses.
1578 service.collect_route_data = function(tmpl, evt, params, options) {
1579 if (angular.isArray(evt)) evt = evt[0];
1583 if (evt.org && !tmpl.match(/hold_shelf/)) {
1585 service.get_org_addr(evt.org, 'holds_address')
1586 .then(function(addr) { data.address = addr })
1590 if (evt.payload.hold) {
1592 egCore.pcrud.retrieve('au',
1593 evt.payload.hold.usr(), {
1595 flesh_fields : {'au' : ['card']}
1597 ).then(function(patron) {data.patron = patron})
1602 if (!tmpl.match(/hold_shelf/)) {
1603 var courier_deferred = $q.defer();
1604 promises.push(courier_deferred.promise);
1606 service.find_copy_transit(evt, params, options)
1607 .then(function(trans) {
1608 data.transit = trans;
1609 egCore.org.settings('lib.courier_code', trans.dest().id())
1611 data.dest_courier_code = s['lib.courier_code'];
1612 courier_deferred.resolve();
1618 return $q.all(promises).then(function() { return data });
1621 service.route_dialog = function(tmpl, evt, params, options) {
1622 if (angular.isArray(evt)) evt = evt[0];
1624 return service.collect_route_data(tmpl, evt, params, options)
1625 .then(function(data) {
1627 var template = data.transit ?
1628 (data.patron ? 'hold_transit_slip' : 'transit_slip') :
1630 if (service.never_auto_print[template]) {
1631 // do not show the dialog or print if the
1632 // disabled automatic print attempt type list includes
1633 // the specified template
1637 // All actions flow from the print data
1639 var print_context = {
1640 copy : egCore.idl.toHash(evt.payload.copy),
1642 author : evt.author,
1643 call_number : egCore.idl.toHash(evt.payload.volume)
1646 var acn = print_context.call_number; // fix up pre/suffixes
1647 if (acn.prefix == -1) acn.prefix = "";
1648 if (acn.suffix == -1) acn.suffix = "";
1651 // route_dialog includes the "route to holds shelf"
1652 // dialog, which has no transit
1653 print_context.transit = egCore.idl.toHash(data.transit);
1654 print_context.dest_courier_code = data.dest_courier_code;
1656 print_context.dest_address = egCore.idl.toHash(data.address);
1658 print_context.dest_location =
1659 egCore.idl.toHash(egCore.org.get(data.transit.dest()));
1663 print_context.hold = egCore.idl.toHash(evt.payload.hold);
1664 var notes = print_context.hold.notes;
1665 if(notes.length > 0){
1666 print_context.hold_notes = [];
1667 angular.forEach(notes, function(n){
1668 print_context.hold_notes.push(n);
1671 print_context.patron = egCore.idl.toHash(data.patron);
1674 var sound = 'info.checkin.transit';
1675 if (evt.payload.hold) sound += '.hold';
1676 egCore.audio.play(sound);
1678 function print_transit(template) {
1679 return egCore.print.print({
1680 context : 'default',
1681 template : template,
1682 scope : print_context
1686 // when auto-print is on, skip the dialog and go straight
1688 if (options.auto_print_holds_transits)
1689 return print_transit(template);
1691 return $uibModal.open({
1695 '$scope','$uibModalInstance',
1696 function($scope , $uibModalInstance) {
1698 $scope.today = new Date();
1700 // copy the print scope into the dialog scope
1701 angular.forEach(print_context, function(val, key) {
1705 $scope.ok = function() {$uibModalInstance.close()}
1707 $scope.print = function() {
1708 $uibModalInstance.close();
1709 print_transit(template);
1717 // action == what action to take if the user confirms the alert
1718 service.copy_alert_dialog = function(evt, params, options, action) {
1719 if (angular.isArray(evt)) evt = evt[0];
1720 if (!angular.isArray(evt.payload)) {
1721 return egConfirmDialog.open(
1722 egCore.strings.COPY_ALERT_MSG_DIALOG_TITLE,
1723 evt.payload, // payload == alert message text
1724 { copy_barcode : params.copy_barcode,
1726 cancel : function() {}
1728 ).result.then(function() {
1729 options.override = true;
1730 return service[action](params, options);
1732 } else { // we got a list of copy alert objects ...
1733 return egCopyAlertManagerDialog.open({
1734 alerts : evt.payload,
1736 ok : function(the_next_status) {
1737 if (the_next_status !== null) {
1738 params.next_copy_status = [ the_next_status ];
1739 params.capture = 'nocapture';
1742 cancel : function() {}
1743 }).result.then(function() {
1744 options.override = true;
1745 return service[action](params, options);
1750 // action == what action to take if the user confirms the alert
1751 service.hold_capture_delay_dialog = function(evt, params, options, action) {
1752 if (angular.isArray(evt)) evt = evt[0];
1753 return $uibModal.open({
1754 templateUrl: './circ/checkin/t_hold_verify',
1757 ['$scope','$uibModalInstance','params',
1758 function($scope , $uibModalInstance , params) {
1759 $scope.copy_barcode = params.copy_barcode;
1760 $scope.capture = function() {
1761 params.capture = 'capture';
1762 $uibModalInstance.close();
1764 $scope.nocapture = function() {
1765 params.capture = 'nocapture';
1766 $uibModalInstance.close();
1768 $scope.cancel = function() { $uibModalInstance.dismiss(); };
1771 params : function() {
1777 return service[action](params, options);
1782 // check the barcode. If it's no good, show the warning dialog
1783 // Resolves on success, rejected on error
1784 service.test_barcode = function(bc) {
1786 var ok = service.check_barcode(bc);
1787 if (ok) return $q.when();
1789 egCore.audio.play('warning.circ.bad_barcode');
1790 return $uibModal.open({
1791 templateUrl: './circ/share/t_bad_barcode_dialog',
1794 ['$scope', '$uibModalInstance',
1795 function($scope, $uibModalInstance) {
1796 $scope.barcode = bc;
1797 $scope.ok = function() { $uibModalInstance.close() }
1798 $scope.cancel = function() { $uibModalInstance.dismiss() }
1803 // check() and checkdigit() copied directly
1804 // from chrome/content/util/barcode.js
1806 service.check_barcode = function(bc) {
1807 if (bc != Number(bc)) return false;
1809 // "16.00" == Number("16.00"), but the . is bad.
1810 // Throw out any barcode that isn't just digits
1811 if (bc.search(/\D/) != -1) return false;
1812 var last_digit = bc.substr(bc.length-1);
1813 var stripped_barcode = bc.substr(0,bc.length-1);
1814 return service.barcode_checkdigit(stripped_barcode).toString() == last_digit;
1817 service.barcode_checkdigit = function(bc) {
1818 var reverse_barcode = bc.toString().split('').reverse();
1819 var check_sum = 0; var multiplier = 2;
1820 for (var i = 0; i < reverse_barcode.length; i++) {
1821 var digit = reverse_barcode[i];
1822 var product = digit * multiplier; product = product.toString();
1824 for (var j = 0; j < product.length; j++) {
1825 temp_sum += Number( product[j] );
1827 check_sum += Number( temp_sum );
1828 multiplier = ( multiplier == 2 ? 1 : 2 );
1830 check_sum = check_sum.toString();
1831 var next_multiple_of_10 = (check_sum.match(/(\d*)\d$/)[1] * 10) + 10;
1832 var check_digit = next_multiple_of_10 - Number(check_sum);
1833 if (check_digit == 10) check_digit = 0;
1837 service.handle_barcode_completion = function(barcode) {
1838 return egCore.net.request(
1840 'open-ils.actor.get_barcodes',
1841 egCore.auth.token(), egCore.auth.user().ws_ou(),
1844 .then(function(resp) {
1845 // TODO: handle event during barcode lookup
1846 if (evt = egCore.evt.parse(resp)) {
1847 console.error(evt.toString());
1851 // no matching barcodes: return the barcode as entered
1852 // by the user (so that, e.g., checkout can fall back to
1853 // precat/noncat handling)
1854 if (!resp || !resp[0]) {
1858 // exactly one matching barcode: return it
1859 if (resp.length == 1) {
1860 return resp[0].barcode;
1863 // multiple matching barcodes: let the user pick one
1864 console.debug('multiple matching barcodes');
1868 angular.forEach(resp, function(cp) {
1872 'open-ils.circ.copy_details.retrieve',
1873 egCore.auth.token(), cp.id
1874 ).then(function(r) {
1876 barcode: r.copy.barcode(),
1877 title: r.mvr.title(),
1878 org_name: egCore.org.get(r.copy.circ_lib()).name(),
1879 org_shortname: egCore.org.get(r.copy.circ_lib()).shortname()
1884 return $q.all(promises)
1886 return $uibModal.open({
1887 templateUrl: './circ/share/t_barcode_choice_dialog',
1890 ['$scope', '$uibModalInstance',
1891 function($scope, $uibModalInstance) {
1892 $scope.matches = matches;
1893 $scope.ok = function(barcode) {
1894 $uibModalInstance.close();
1895 final_barcode = barcode;
1897 $scope.cancel = function() {$uibModalInstance.dismiss()}
1899 }).result.then(function() { return final_barcode });
1904 service.create_penalty = function(user_id) {
1905 return $uibModal.open({
1906 templateUrl: './circ/share/t_new_message_dialog',
1909 ['$scope','$uibModalInstance','staffPenalties',
1910 function($scope , $uibModalInstance , staffPenalties) {
1911 $scope.focusNote = true;
1912 $scope.penalties = staffPenalties;
1913 $scope.require_initials = service.require_initials;
1914 $scope.args = {penalty : 21}; // default to Note
1915 $scope.setPenalty = function(id) {
1918 $scope.ok = function(count) { $uibModalInstance.close($scope.args) }
1919 $scope.cancel = function($event) {
1920 $uibModalInstance.dismiss();
1921 $event.preventDefault();
1924 resolve : { staffPenalties : service.get_staff_penalty_types }
1927 var pen = new egCore.idl.ausp();
1929 pen.org_unit(egCore.auth.user().ws_ou());
1930 pen.note(args.note);
1931 if (args.initials) pen.note(args.note + ' [' + args.initials + ']');
1932 if (args.custom_penalty) {
1933 pen.standing_penalty(args.custom_penalty);
1935 pen.standing_penalty(args.penalty);
1937 pen.staff(egCore.auth.user().id());
1938 pen.set_date('now');
1940 return egCore.net.request(
1942 'open-ils.actor.user.penalty.apply',
1943 egCore.auth.token(), pen
1949 // assumes, for now anyway, penalty type is fleshed onto usr_penalty.
1950 service.edit_penalty = function(usr_penalty) {
1951 return $uibModal.open({
1952 templateUrl: './circ/share/t_new_message_dialog',
1955 ['$scope','$uibModalInstance','staffPenalties',
1956 function($scope , $uibModalInstance , staffPenalties) {
1957 $scope.focusNote = true;
1958 $scope.penalties = staffPenalties;
1959 $scope.require_initials = service.require_initials;
1961 penalty : usr_penalty.standing_penalty().id(),
1962 note : usr_penalty.note()
1964 $scope.setPenalty = function(id) { args.penalty = id; }
1965 $scope.ok = function(count) { $uibModalInstance.close($scope.args) }
1966 $scope.cancel = function($event) {
1967 $uibModalInstance.dismiss();
1968 $event.preventDefault();
1971 resolve : { staffPenalties : service.get_staff_penalty_types }
1974 usr_penalty.note(args.note);
1975 if (args.initials) usr_penalty.note(args.note + ' [' + args.initials + ']');
1976 usr_penalty.standing_penalty(args.penalty);
1977 return egCore.pcrud.update(usr_penalty);