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,
23 in_flight_checkins: {}
26 egCore.startup.go().finally(function() {
28 'ui.staff.require_initials.patron_standing_penalty',
29 'ui.admin.work_log.max_entries',
30 'ui.admin.patron_log.max_entries',
31 'circ.staff_client.do_not_auto_attempt_print',
32 'circ.clear_hold_on_checkout'
33 ]).then(function(set) {
34 service.require_initials = Boolean(set['ui.staff.require_initials.patron_standing_penalty']);
35 service.clearHold = Boolean(set['circ.clear_hold_on_checkout']);
37 if (angular.isArray(set['circ.staff_client.do_not_auto_attempt_print'])) {
38 if (set['circ.staff_client.do_not_auto_attempt_print'].indexOf('Hold Slip') > 1)
39 service.never_auto_print['hold_shelf_slip'] = true;
40 if (set['circ.staff_client.do_not_auto_attempt_print'].indexOf('Hold/Transit Slip') > 1)
41 service.never_auto_print['hold_transit_slip'] = true;
42 if (set['circ.staff_client.do_not_auto_attempt_print'].indexOf('Transit Slip') > 1)
43 service.never_auto_print['transit_slip'] = true;
48 service.reset = function() {
49 service.auto_override_checkout_events = {};
52 // these events can be overridden by staff during checkout
53 service.checkout_overridable_events = [
54 'PATRON_EXCEEDS_OVERDUE_COUNT',
55 'PATRON_EXCEEDS_CHECKOUT_COUNT',
56 'PATRON_EXCEEDS_FINES',
58 'CIRC_EXCEEDS_COPY_RANGE',
59 'ITEM_DEPOSIT_REQUIRED',
60 'ITEM_RENTAL_FEE_REQUIRED',
61 'PATRON_EXCEEDS_LOST_COUNT',
62 'COPY_CIRC_NOT_ALLOWED',
66 'ITEM_ON_HOLDS_SHELF',
76 // after the first override of any of these events,
77 // auto-override them in subsequent calls.
78 service.checkout_auto_override_after_first = [
79 'PATRON_EXCEEDS_OVERDUE_COUNT',
81 'PATRON_EXCEEDS_LOST_COUNT',
82 'PATRON_EXCEEDS_CHECKOUT_COUNT',
83 'PATRON_EXCEEDS_FINES'
87 // overridable during renewal
88 service.renew_overridable_events = [
89 'PATRON_EXCEEDS_OVERDUE_COUNT',
90 'PATRON_EXCEEDS_LOST_COUNT',
91 'PATRON_EXCEEDS_CHECKOUT_COUNT',
92 'PATRON_EXCEEDS_FINES',
93 'CIRC_EXCEEDS_COPY_RANGE',
94 'ITEM_DEPOSIT_REQUIRED',
95 'ITEM_RENTAL_FEE_REQUIRED',
97 'COPY_CIRC_NOT_ALLOWED',
100 'COPY_NEEDED_FOR_HOLD',
101 'MAX_RENEWALS_REACHED',
102 'CIRC_CLAIMS_RETURNED',
112 // these checkin events do not produce alerts when
113 // options.suppress_alerts is in effect.
114 service.checkin_suppress_overrides = [
118 'PATRON_ACCOUNT_EXPIRED',
120 'CIRC_CLAIMS_RETURNED',
121 'COPY_ALERT_MESSAGE',
123 'COPY_STATUS_LOST_AND_PAID',
124 'COPY_STATUS_LONG_OVERDUE',
125 'COPY_STATUS_MISSING',
126 'PATRON_EXCEEDS_FINES'
129 // these events can be overridden by staff during checkin
130 service.checkin_overridable_events =
131 service.checkin_suppress_overrides.concat([
132 'HOLD_CAPTURE_DELAYED', // not technically overridable, but special prompt and param
133 'TRANSIT_CHECKIN_INTERVAL_BLOCK'
136 // Performs a checkout.
137 // Returns a promise resolved with the original params and options
138 // and the final checkout event (e.g. in the case of override).
139 // Rejected if the checkout cannot be completed.
141 // params : passed directly as arguments to the server API
142 // options : non-parameter controls. e.g. "override", "check_barcode"
143 service.checkout = function(params, options) {
144 if (!options) options = {};
145 params.new_copy_alerts = 1;
147 console.debug('egCirc.checkout() : '
148 + js2JSON(params) + ' : ' + js2JSON(options));
150 // handle barcode completion
151 return service.handle_barcode_completion(params.copy_barcode)
152 .then(function(barcode) {
153 console.debug('barcode after completion: ' + barcode);
154 params.copy_barcode = barcode;
156 var promise = options.check_barcode ?
157 service.test_barcode(params.copy_barcode) : $q.when();
159 // avoid re-check on override, etc.
160 delete options.check_barcode;
162 return promise.then(function() {
164 var method = 'open-ils.circ.checkout.full';
165 if (options.override) method += '.override';
167 return egCore.net.request(
168 'open-ils.circ', method, egCore.auth.token(), params
170 ).then(function(evt) {
172 if (!angular.isArray(evt)) evt = [evt];
174 if (evt[0].payload && evt[0].payload.auto_renew == 1) {
175 // open circulation found with auto-renew toggle on.
176 console.debug('Auto-renewing item ' + params.copy_barcode);
177 options.auto_renew = true;
178 return service.renew(params, options);
181 var action = params.noncat ? 'noncat_checkout' : 'checkout';
183 return service.flesh_response_data(action, evt, params, options)
185 return service.handle_checkout_resp(evt, params, options);
187 .then(function(final_resp) {
188 return service.munge_resp_data(final_resp,action,method)
195 // Performs a renewal.
196 // Returns a promise resolved with the original params and options
197 // and the final checkout event (e.g. in the case of override)
198 // Rejected if the renewal cannot be completed.
199 service.renew = function(params, options) {
200 if (!options) options = {};
201 params.new_copy_alerts = 1;
203 console.debug('egCirc.renew() : '
204 + js2JSON(params) + ' : ' + js2JSON(options));
206 // handle barcode completion
207 return service.handle_barcode_completion(params.copy_barcode)
208 .then(function(barcode) {
209 params.copy_barcode = barcode;
211 var promise = options.check_barcode ?
212 service.test_barcode(params.copy_barcode) : $q.when();
214 // avoid re-check on override, etc.
215 delete options.check_barcode;
217 return promise.then(function() {
219 var method = 'open-ils.circ.renew';
220 if (options.override) method += '.override';
222 return egCore.net.request(
223 'open-ils.circ', method, egCore.auth.token(), params
225 ).then(function(evt) {
227 if (!angular.isArray(evt)) evt = [evt];
229 return service.flesh_response_data(
230 'renew', evt, params, options)
232 return service.handle_renew_resp(evt, params, options);
234 .then(function(final_resp) {
235 final_resp.auto_renew = options.auto_renew;
236 return service.munge_resp_data(final_resp,'renew',method)
243 // Performs a checkin
244 // Returns a promise resolved with the original params and options,
245 // plus the final checkin event (e.g. in the case of override).
246 // Rejected if the checkin cannot be completed.
247 service.checkin = function(params, options) {
248 if (!options) options = {};
249 params.new_copy_alerts = 1;
251 console.debug('egCirc.checkin() : '
252 + js2JSON(params) + ' : ' + js2JSON(options));
254 // handle barcode completion
255 return service.handle_barcode_completion(params.copy_barcode)
256 .then(function(barcode) {
257 params.copy_barcode = barcode;
259 var promise = options.check_barcode ?
260 service.test_barcode(params.copy_barcode) : $q.when();
262 // avoid re-check on override, etc.
263 delete options.check_barcode;
265 return promise.then(function() {
267 var method = 'open-ils.circ.checkin';
268 if (options.override) method += '.override';
270 // Multiple checkin API calls should never be active
271 // for a single barcode.
272 if (service.in_flight_checkins[barcode]) {
273 console.error('Barcode ' + barcode
274 + ' is already in flight for checkin, skipping');
277 service.in_flight_checkins[barcode] = true;
279 return egCore.net.request(
280 'open-ils.circ', method, egCore.auth.token(), params
282 ).then(function(evt) {
283 delete service.in_flight_checkins[barcode];
285 if (!angular.isArray(evt)) evt = [evt];
286 return service.flesh_response_data(
287 'checkin', evt, params, options)
289 return service.handle_checkin_resp(evt, params, options);
291 .then(function(final_resp) {
292 return service.munge_resp_data(final_resp,'checkin',method)
294 }, function() {delete service.in_flight_checkins[barcode]});
299 // provide consistent formatting of the final response data
300 service.munge_resp_data = function(final_resp,worklog_action,worklog_method) {
301 var data = final_resp.data = {};
303 if (!final_resp.evt[0]) {
304 egCore.audio.play('error.unknown.no_event');
308 var payload = final_resp.evt[0].payload;
310 egCore.audio.play('error.unknown.no_payload');
314 // retrieve call number affixes prior to sending payload data to the grid
315 if (payload.volume && typeof payload.volume.prefix() != 'object') {
316 egCore.pcrud.retrieve('acnp',payload.volume.prefix()).then(function(p) {payload.volume.prefix(p)});
318 if (payload.volume && typeof payload.volume.suffix() != 'object') {
319 egCore.pcrud.retrieve('acns',payload.volume.suffix()).then(function(s) {payload.volume.suffix(s)});
322 data.circ = payload.circ;
323 data.parent_circ = payload.parent_circ;
324 data.hold = payload.hold;
325 data.record = payload.record;
326 data.acp = payload.copy;
327 data.acn = payload.volume ? payload.volume : payload.copy ? payload.copy.call_number() : null;
328 data.au = payload.patron;
329 data.transit = payload.transit;
330 data.status = payload.status;
331 data.message = payload.message;
332 data.title = final_resp.evt[0].title;
333 data.author = final_resp.evt[0].author;
334 data.isbn = final_resp.evt[0].isbn;
335 data.route_to = final_resp.evt[0].route_to;
337 if (payload.circ) data.duration = payload.circ.duration();
338 if (payload.circ) data.circ_lib = payload.circ.circ_lib();
340 // for checkin, the mbts lives on the main circ
341 if (payload.circ && payload.circ.billable_transaction())
342 data.mbts = payload.circ.billable_transaction().summary();
344 // on renewals, the mbts lives on the parent circ
345 if (payload.parent_circ && payload.parent_circ.billable_transaction())
346 data.mbts = payload.parent_circ.billable_transaction().summary();
348 if (!data.route_to) {
350 data.route_to = data.transit.dest().shortname();
351 } else if (data.acp) {
352 data.route_to = data.acp.location().name();
355 // allow us to get at the monograph parts associated with a copy
356 if (payload.copy && payload.copy.parts()) {
357 data._monograph_part = payload.copy.parts().map(function(part) {
363 (worklog_action == 'checkout' || worklog_action == 'noncat_checkout')
364 ? egCore.strings.EG_WORK_LOG_CHECKOUT
365 : (worklog_action == 'renew'
366 ? egCore.strings.EG_WORK_LOG_RENEW
367 : egCore.strings.EG_WORK_LOG_CHECKIN // worklog_action == 'checkin'
369 'action' : worklog_action,
370 'method' : worklog_method,
371 'response' : final_resp
378 service.handle_overridable_checkout_event = function(evt, params, options) {
380 if (options.override) {
381 // override attempt already made and failed.
382 // NOTE: I don't think we'll ever get here, since the
383 // override attempt should produce a perm failure...
384 angular.forEach(evt, function(e){ console.debug('override failed: ' + e.textcode); });
389 if (evt.filter(function(e){return !service.auto_override_checkout_events[e.textcode];}).length == 0) {
390 // user has already opted to override these type
391 // of events. Re-run the checkout w/ override.
392 options.override = true;
393 return service.checkout(params, options);
396 // Ask the user if they would like to override this event.
397 // Some events offer a stock override dialog, while others
398 // require additional context.
400 switch(evt[0].textcode) {
401 case 'COPY_NOT_AVAILABLE':
402 return service.copy_not_avail_dialog(evt, params, options);
403 case 'COPY_ALERT_MESSAGE':
404 return service.copy_alert_dialog(evt[0], params, options, 'checkout');
406 return service.override_dialog(evt, params, options, 'checkout');
410 service.handle_overridable_renew_event = function(evt, params, options) {
412 if (options.override) {
413 // override attempt already made and failed.
414 // NOTE: I don't think we'll ever get here, since the
415 // override attempt should produce a perm failure...
416 angular.forEach(evt, function(e){ console.debug('override failed: ' + e.textcode); });
421 // renewal auto-overrides are the same as checkout
422 if (evt.filter(function(e){return !service.auto_override_checkout_events[e.textcode];}).length == 0) {
423 // user has already opted to override these type
424 // of events. Re-run the renew w/ override.
425 options.override = true;
426 return service.renew(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, 'renew');
437 return service.override_dialog(evt, params, options, 'renew');
442 service.handle_overridable_checkin_event = function(evt, params, options) {
444 if (options.override) {
445 // override attempt already made and failed.
446 // NOTE: I don't think we'll ever get here, since the
447 // override attempt should produce a perm failure...
448 angular.forEach(evt, function(e){ console.debug('override failed: ' + e.textcode); });
453 if (options.suppress_checkin_popups
454 && evt.filter(function(e){return service.checkin_suppress_overrides.indexOf(e.textcode) == -1;}).length == 0) {
455 // Events are suppressed. Re-run the checkin w/ override.
456 options.override = true;
457 return service.checkin(params, options);
460 // Ask the user if they would like to override this event.
461 // Some events offer a stock override dialog, while others
462 // require additional context.
464 switch(evt[0].textcode) {
465 case 'COPY_ALERT_MESSAGE':
466 return service.copy_alert_dialog(evt[0], params, options, 'checkin');
467 case 'HOLD_CAPTURE_DELAYED':
468 return service.hold_capture_delay_dialog(evt[0], params, options, 'checkin');
470 return service.override_dialog(evt, params, options, 'checkin');
475 service.handle_renew_resp = function(evt, params, options) {
477 var final_resp = {evt : evt, params : params, options : options};
479 // track the barcode regardless of whether it refers to a copy
480 angular.forEach(evt, function(e){ e.copy_barcode = params.copy_barcode; });
482 // Overridable Events
483 if (evt.filter(function(e){return service.renew_overridable_events.indexOf(e.textcode) > -1;}).length > 0)
484 return service.handle_overridable_renew_event(evt, params, options);
487 switch (evt[0].textcode) {
489 egCore.audio.play('info.renew');
490 return $q.when(final_resp);
492 case 'COPY_IN_TRANSIT':
493 case 'PATRON_CARD_INACTIVE':
494 case 'PATRON_INACTIVE':
495 case 'PATRON_ACCOUNT_EXPIRED':
496 case 'CIRC_CLAIMS_RETURNED':
497 egCore.audio.play('warning.renew');
498 return service.exit_alert(
499 egCore.strings[evt[0].textcode],
500 {barcode : params.copy_barcode}
504 egCore.audio.play('warning.renew.unknown');
505 return service.exit_alert(
506 egCore.strings.CHECKOUT_FAILED_GENERIC, {
507 barcode : params.copy_barcode,
508 textcode : evt[0].textcode,
516 service.handle_checkout_resp = function(evt, params, options) {
518 var final_resp = {evt : evt, params : params, options : options};
520 // track the barcode regardless of whether it refers to a copy
521 angular.forEach(evt, function(e){ e.copy_barcode = params.copy_barcode; });
523 // Overridable Events
524 if (evt.filter(function(e){return service.checkout_overridable_events.indexOf(e.textcode) > -1;}).length > 0)
525 return service.handle_overridable_checkout_event(evt, params, options);
528 switch (evt[0].textcode) {
530 egCore.audio.play('success.checkout');
531 return $q.when(final_resp);
533 case 'ITEM_NOT_CATALOGED':
534 egCore.audio.play('error.checkout.no_cataloged');
535 return service.precat_dialog(params, options);
537 case 'OPEN_CIRCULATION_EXISTS':
538 // auto_renew checked in service.checkout()
539 egCore.audio.play('error.checkout.open_circ');
540 return service.circ_exists_dialog(evt, params, options);
542 case 'COPY_IN_TRANSIT':
543 egCore.audio.play('warning.checkout.in_transit');
544 return service.copy_in_transit_dialog(evt, params, options);
546 case 'PATRON_CARD_INACTIVE':
547 case 'PATRON_INACTIVE':
548 case 'PATRON_ACCOUNT_EXPIRED':
549 case 'CIRC_CLAIMS_RETURNED':
550 egCore.audio.play('warning.checkout');
551 return service.exit_alert(
552 egCore.strings[evt[0].textcode],
553 {barcode : params.copy_barcode}
557 egCore.audio.play('error.checkout.unknown');
558 return service.exit_alert(
559 egCore.strings.CHECKOUT_FAILED_GENERIC, {
560 barcode : params.copy_barcode,
561 textcode : evt[0].textcode,
568 // returns a promise resolved with the list of circ mods
569 service.get_circ_mods = function() {
571 return $q.when(egCore.env.ccm.list);
573 return egCore.pcrud.retrieveAll('ccm', null, {atomic : true})
574 .then(function(list) {
575 egCore.env.absorbList(list, 'ccm');
580 // returns a promise resolved with the list of noncat types
581 service.get_noncat_types = function() {
583 return $q.when(egCore.env.cnct.list);
585 return egCore.pcrud.search('cnct',
587 egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
588 null, {atomic : true}
589 ).then(function(list) {
590 egCore.env.absorbList(list, 'cnct');
595 service.get_staff_penalty_types = function() {
597 return $q.when(egCore.env.csp.list);
598 return egCore.pcrud.search(
599 // id <= 100 are reserved for system use
600 'csp', {id : {'>': 100}}, {}, {atomic : true})
601 .then(function(penalties) {
602 return egCore.env.absorbList(penalties, 'csp').list;
606 // ideally all of these data should be returned with the response,
607 // but until then, grab what we need.
608 service.flesh_response_data = function(action, evt, params, options) {
611 if (!evt[0] || !(payload = evt[0].payload)) return $q.when();
613 promises.push(service.flesh_copy_location(payload.copy));
615 promises.push(service.flesh_acn_owning_lib(payload.volume));
616 promises.push(service.flesh_copy_circ_library(payload.copy));
617 promises.push(service.flesh_copy_circ_modifier(payload.copy));
619 service.flesh_copy_status(payload.copy)
622 // copy is in transit, but no transit was delivered
623 // in the payload. Do this here instead of below to
624 // ensure consistent copy status fleshiness
625 if (!payload.transit && payload.copy.status().id() == 6) { // in-transit
626 return service.find_copy_transit(evt, params, options)
627 .then(function(trans) {
629 trans.source(egCore.org.get(trans.source()));
630 trans.dest(egCore.org.get(trans.dest()));
631 payload.transit = trans;
639 // local flesh transit
640 if (transit = payload.transit) {
641 transit.source(egCore.org.get(transit.source()));
642 transit.dest(egCore.org.get(transit.dest()));
645 // TODO: renewal responses should include the patron
646 if (!payload.patron) {
648 if (payload.circ) user_id = payload.circ.usr();
649 if (payload.noncat_circ) user_id = payload.noncat_circ.patron();
652 egCore.pcrud.retrieve('au', user_id)
653 .then(function(user) {payload.patron = user})
658 // extract precat values
659 angular.forEach(evt, function(e){ e.title = payload.record ? payload.record.title() :
660 (payload.copy ? payload.copy.dummy_title() : null);});
662 angular.forEach(evt, function(e){ e.author = payload.record ? payload.record.author() :
663 (payload.copy ? payload.copy.dummy_author() : null);});
665 angular.forEach(evt, function(e){ e.isbn = payload.record ? payload.record.isbn() :
666 (payload.copy ? payload.copy.dummy_isbn() : null);});
668 return $q.all(promises);
671 service.flesh_acn_owning_lib = function(acn) {
672 if (!acn) return $q.when();
673 return $q.when(acn.owning_lib(egCore.org.get( acn.owning_lib() )));
676 service.flesh_copy_circ_library = function(copy) {
677 if (!copy) return $q.when();
679 return $q.when(copy.circ_lib(egCore.org.get( copy.circ_lib() )));
682 // fetches the full list of circ modifiers
683 service.flesh_copy_circ_modifier = function(copy) {
684 if (!copy) return $q.when();
686 return $q.when(copy.circ_modifier(egCore.env.ccm.map[copy.circ_modifier()]));
687 return egCore.pcrud.retrieveAll('ccm', {}, {atomic : true}).then(
689 egCore.env.absorbList(list, 'ccm');
690 copy.circ_modifier(egCore.env.ccm.map[copy.circ_modifier()]);
695 // fetches the full list of copy statuses
696 service.flesh_copy_status = function(copy) {
697 if (!copy) return $q.when();
699 return $q.when(copy.status(egCore.env.ccs.map[copy.status()]));
700 return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}).then(
702 egCore.env.absorbList(list, 'ccs');
703 copy.status(egCore.env.ccs.map[copy.status()]);
708 // there may be *many* copy locations and we may be handling items
709 // for other locations. Fetch copy locations as-needed and cache.
710 service.flesh_copy_location = function(copy) {
711 if (!copy) return $q.when();
712 if (angular.isObject(copy.location())) return $q.when(copy);
713 if (egCore.env.acpl) {
714 if (egCore.env.acpl.map[copy.location()]) {
715 copy.location(egCore.env.acpl.map[copy.location()]);
716 return $q.when(copy);
719 return egCore.pcrud.retrieve('acpl', copy.location())
720 .then(function(loc) {
721 egCore.env.absorbList([loc], 'acpl'); // append to cache
728 // fetch org unit addresses as needed.
729 service.get_org_addr = function(org_id, addr_type) {
730 var org = egCore.org.get(org_id);
731 var addr_id = org[addr_type]();
733 if (!addr_id) return $q.when(null);
735 if (egCore.env.aoa && egCore.env.aoa.map[addr_id])
736 return $q.when(egCore.env.aoa.map[addr_id]);
738 return egCore.pcrud.retrieve('aoa', addr_id).then(function(addr) {
739 egCore.env.absorbList([addr], 'aoa');
740 return egCore.env.aoa.map[addr_id];
744 service.exit_alert = function(msg, scope) {
745 return egAlertDialog.open(msg, scope).result.then(
746 function() {return $q.reject()});
749 // opens a dialog asking the user if they would like to override
750 // the returned event.
751 service.override_dialog = function(evt, params, options, action) {
752 if (!angular.isArray(evt)) evt = [evt];
754 egCore.audio.play('warning.circ.event_override');
755 var copy_alert = evt.filter(function(e) {
756 return e.textcode == 'COPY_ALERT_MESSAGE';
758 evt = evt.filter(function(e) {
759 return e.textcode !== 'COPY_ALERT_MESSAGE';
762 return $uibModal.open({
763 templateUrl: './circ/share/t_event_override_dialog',
766 ['$scope', '$uibModalInstance',
767 function($scope, $uibModalInstance) {
770 // Find the event, if any, that is for ITEM_ON_HOLDS_SHELF
771 // and grab the patron name of the owner.
772 $scope.holdEvent = evt.filter(function(e) {
773 return e.textcode === 'ITEM_ON_HOLDS_SHELF'
776 if ($scope.holdEvent.length > 0) {
777 // Ensure we have a scalar here
778 if (angular.isArray($scope.holdEvent)) {
779 $scope.holdEvent = $scope.holdEvent[0];
782 $scope.patronName = $scope.holdEvent.payload.patron_name;
783 $scope.holdID = $scope.holdEvent.payload.hold_id;
784 $scope.patronID = $scope.holdEvent.payload.patron_id;
787 $scope.auto_override =
788 evt.filter(function(e){
789 return service.checkout_auto_override_after_first.indexOf(evt.textcode) > -1;
791 $scope.copy_barcode = params.copy_barcode; // may be null
793 // Implementation note: Why not use a primitive here? It
794 // doesn't work. See:
795 // http://stackoverflow.com/questions/18642371/checkbox-not-binding-to-scope-in-angularjs
796 $scope.formdata = {clearHold : service.clearHold};
798 $scope.ok = function() {
799 // Handle the cancellation of the assciated hold here
800 if ($scope.formdata.clearHold && $scope.holdID) {
803 'open-ils.circ.hold.cancel',
804 egCore.auth.token(), $scope.holdID,
806 'Item checked out by other patron' // FIXME I18n
809 $uibModalInstance.close();
812 $scope.cancel = function ($event) {
813 $uibModalInstance.dismiss();
814 $event.preventDefault();
819 options.override = true;
821 if (copy_alert.length > 0) {
822 return service.copy_alert_dialog(copy_alert, params, options, action);
825 if (action == 'checkin') {
826 return service.checkin(params, options);
829 // checkout/renew support override-after-first
830 angular.forEach(evt, function(e){
831 if (service.checkout_auto_override_after_first.indexOf(e.textcode) > -1)
832 service.auto_override_checkout_events[e.textcode] = true;
835 return service[action](params, options);
840 service.copy_not_avail_dialog = function(evt, params, options) {
841 if (!angular.isArray(evt)) evt = [evt];
843 var copy_alert = evt.filter(function(e) {
844 return e.textcode == 'COPY_ALERT_MESSAGE';
846 evt = evt.filter(function(e) {
847 return e.textcode !== 'COPY_ALERT_MESSAGE';
851 return $uibModal.open({
852 templateUrl: './circ/share/t_copy_not_avail_dialog',
855 ['$scope','$uibModalInstance','copyStatus',
856 function($scope , $uibModalInstance , copyStatus) {
857 $scope.copyStatus = copyStatus;
858 $scope.ok = function() {$uibModalInstance.close()}
859 $scope.cancel = function() {$uibModalInstance.dismiss()}
862 copyStatus : function() {
863 return egCore.pcrud.retrieve(
864 'ccs', evt.payload.status());
869 options.override = true;
871 if (copy_alert.length > 0) {
872 return service.copy_alert_dialog(copy_alert, params, options, 'checkout');
875 return service.checkout(params, options);
880 // Opens a dialog allowing the user to fill in the desired non-cat count.
881 // Unlike other dialogs, which kickoff circ actions internally
882 // as a result of events, this dialog does not kick off any circ
883 // actions. It just collects the count and and resolves the promise.
885 // This assumes the caller has already handled the noncat-type
886 // selection and just needs to collect the count info.
887 service.noncat_dialog = function(params, options) {
888 var noncatMax = 99; // hard-coded max
890 // the caller should presumably have fetched the noncat_types via
891 // our API already, but fetch them again (from cache) to be safe.
892 return service.get_noncat_types().then(function() {
894 params.noncat = true;
895 var type = egCore.env.cnct.map[params.noncat_type];
897 return $uibModal.open({
898 templateUrl: './circ/share/t_noncat_dialog',
901 ['$scope', '$uibModalInstance',
902 function($scope, $uibModalInstance) {
903 $scope.focusMe = true;
906 $scope.noncatMax = noncatMax;
907 $scope.ok = function(count) { $uibModalInstance.close(count) }
908 $scope.cancel = function ($event) {
909 $uibModalInstance.dismiss()
910 $event.preventDefault();
915 if (count && count > 0 && count <= noncatMax) {
916 // NOTE: in Chrome, form validation ensure a valid number
917 params.noncat_count = count;
918 return $q.when(params);
927 // Opens a dialog allowing the user to fill in pre-cat copy info.
928 service.precat_dialog = function(params, options) {
930 return $uibModal.open({
931 templateUrl: './circ/share/t_precat_dialog',
934 ['$scope', '$uibModalInstance', 'circMods',
935 function($scope, $uibModalInstance, circMods) {
936 $scope.focusMe = true;
937 $scope.precatArgs = {
938 copy_barcode : params.copy_barcode
940 $scope.circModifiers = circMods;
941 $scope.ok = function(args) { $uibModalInstance.close(args) }
942 $scope.cancel = function () { $uibModalInstance.dismiss() }
944 // use this function as a keydown handler on form
945 // elements that should not submit the form on enter.
946 $scope.preventSubmit = function($event) {
947 if ($event.keyCode == 13)
948 $event.preventDefault();
952 circMods : function() {
953 return service.get_circ_mods();
958 if (!args || !args.dummy_title) return $q.reject();
959 if(args.circ_modifier == "") args.circ_modifier = null;
960 angular.forEach(args, function(val, key) {params[key] = val});
961 params.precat = true;
962 return service.checkout(params, options);
967 // find the open transit for the given copy barcode; flesh the org
969 service.find_copy_transit = function(evt, params, options) {
970 if (angular.isArray(evt)) evt = evt[0];
972 // NOTE: evt.payload.transit may exist, but it's not necessarily
973 // the transit we want, since a transit close + open in the API
974 // returns the closed transit.
976 return egCore.pcrud.search('atc',
977 { dest_recv_time : null, cancel_time : null},
979 flesh_fields : {atc : ['target_copy']},
983 barcode : params.copy_barcode,
989 order_by : {atc : 'source_send_time desc'},
990 }, {authoritative : true}
991 ).then(function(transit) {
992 transit.source(egCore.org.get(transit.source()));
993 transit.dest(egCore.org.get(transit.dest()));
998 service.copy_in_transit_dialog = function(evt, params, options) {
999 if (angular.isArray(evt)) evt = evt[0];
1000 return $uibModal.open({
1001 templateUrl: './circ/share/t_copy_in_transit_dialog',
1004 ['$scope','$uibModalInstance','transit',
1005 function($scope , $uibModalInstance , transit) {
1006 $scope.transit = transit;
1007 $scope.ok = function() { $uibModalInstance.close(transit) }
1008 $scope.cancel = function() { $uibModalInstance.dismiss() }
1011 // fetch the conflicting open transit w/ fleshed copy
1012 transit : function() {
1013 return service.find_copy_transit(evt, params, options);
1018 // user chose to abort the transit then checkout
1019 return service.abort_transit(transit.id())
1021 return service.checkout(params, options);
1027 service.abort_transit = function(transit_id) {
1028 return egCore.net.request(
1030 'open-ils.circ.transit.abort',
1031 egCore.auth.token(), {transitid : transit_id}
1032 ).then(function(resp) {
1033 if (evt = egCore.evt.parse(resp)) {
1041 service.last_copy_circ = function(copy_id) {
1042 return egCore.pcrud.search('circ',
1043 {target_copy : copy_id},
1044 {order_by : {circ : 'xact_start desc' }, limit : 1}
1048 service.circ_exists_dialog = function(evt, params, options) {
1049 if (angular.isArray(evt)) evt = evt[0];
1051 if (!evt.payload.old_circ) {
1052 return egCore.net.request(
1054 'open-ils.search.asset.copy.fleshed2.find_by_barcode',
1056 ).then(function(resp){
1058 if (egCore.evt.parse(resp)) {
1059 console.error(egCore.evt.parse(resp));
1061 return egCore.net.request(
1063 'open-ils.circ.copy_checkout_history.retrieve',
1064 egCore.auth.token(), resp.id(), 1
1065 ).then( function (circs) {
1066 evt.payload.old_circ = circs[0];
1067 return service.circ_exists_dialog_impl( evt, params, options );
1072 return service.circ_exists_dialog_impl( evt, params, options );
1076 service.circ_exists_dialog_impl = function (evt, params, options) {
1078 var openCirc = evt.payload.old_circ;
1079 var sameUser = openCirc.usr() == params.patron_id;
1081 return $uibModal.open({
1082 templateUrl: './circ/share/t_circ_exists_dialog',
1085 ['$scope','$uibModalInstance',
1086 function($scope , $uibModalInstance) {
1087 $scope.args = {forgive_fines : false};
1088 $scope.circDate = openCirc.xact_start();
1089 $scope.sameUser = sameUser;
1090 $scope.ok = function() { $uibModalInstance.close($scope.args) }
1091 $scope.cancel = function($event) {
1092 $uibModalInstance.dismiss();
1093 $event.preventDefault(); // form, avoid calling ok();
1099 params.void_overdues = args.forgive_fines;
1100 return service.renew(params, options);
1103 return service.checkin({
1104 barcode : params.copy_barcode,
1106 void_overdues : args.forgive_fines
1107 }).then(function(checkin_resp) {
1108 if (checkin_resp.evt[0].textcode == 'SUCCESS') {
1109 return service.checkout(params, options);
1111 alert(egCore.evt.parse(checkin_resp.evt[0]));
1119 service.batch_backdate = function(circ_ids, backdate) {
1120 return egCore.net.request(
1122 'open-ils.circ.post_checkin_backdate.batch',
1123 egCore.auth.token(), circ_ids, backdate);
1126 service.backdate_dialog = function(circ_ids) {
1127 return $uibModal.open({
1128 templateUrl: './circ/share/t_backdate_dialog',
1131 ['$scope','$uibModalInstance',
1132 function($scope , $uibModalInstance) {
1134 var today = new Date();
1136 num_circs : circ_ids.length,
1141 $scope.$watch('dialog.backdate', function(newval) {
1142 if (newval && newval > today)
1143 $scope.dialog.backdate = today;
1147 $scope.cancel = function() {
1148 $uibModalInstance.dismiss();
1151 $scope.ok = function() {
1153 var bd = $scope.dialog.backdate.toISOString().replace(/T.*/,'');
1154 service.batch_backdate(circ_ids, bd)
1156 function() { // on complete
1157 $uibModalInstance.close({backdate : bd});
1160 function(resp) { // on response
1161 console.debug('backdate returned ' + resp);
1163 $scope.num_processed++;
1165 console.error(egCore.evt.parse(resp));
1174 service.mark_claims_returned = function(barcode, date, override) {
1176 var method = 'open-ils.circ.circulation.set_claims_returned';
1177 if (override) method += '.override';
1179 console.debug('claims returned ' + method);
1181 return egCore.net.request(
1182 'open-ils.circ', method, egCore.auth.token(),
1183 {barcode : barcode, backdate : date})
1185 .then(function(resp) {
1187 if (resp == 1) { // success
1188 console.debug('claims returned succeeded for ' + barcode);
1191 } else if (evt = egCore.evt.parse(resp)) {
1192 console.debug('claims returned failed: ' + evt.toString());
1194 if (evt.textcode == 'PATRON_EXCEEDS_CLAIMS_RETURN_COUNT') {
1195 // TODO check perms before offering override option?
1197 if (override) return;// just to be safe
1199 return egConfirmDialog.open(
1200 egCore.strings.TOO_MANY_CLAIMS_RETURNED, '', {}
1201 ).result.then(function() {
1202 return service.mark_claims_returned(barcode, date, true);
1206 if (evt.textcode == 'PERM_FAILURE') {
1207 console.error('claims returned permission denied')
1208 // TODO: auth override dialog?
1214 service.mark_claims_returned_dialog = function(copy_barcodes) {
1215 if (!copy_barcodes.length) return;
1217 return $uibModal.open({
1218 templateUrl: './circ/share/t_mark_claims_returned_dialog',
1221 ['$scope','$uibModalInstance',
1222 function($scope , $uibModalInstance) {
1224 var today = new Date();
1226 barcodes : copy_barcodes,
1230 $scope.$watch('args.date', function(newval) {
1231 if (newval && newval > today)
1232 $scope.args.backdate = today;
1235 $scope.cancel = function() {$uibModalInstance.dismiss()}
1236 $scope.ok = function() {
1238 var date = $scope.args.date.toISOString().replace(/T.*/,'');
1240 var deferred = $q.defer();
1242 // serialize the action on each barcode so that the
1243 // caller will never see multiple alerts at the same time.
1244 function mark_one() {
1245 var bc = copy_barcodes.pop();
1248 $uibModalInstance.close();
1252 // finally -> continue even when one fails
1253 service.mark_claims_returned(bc, date)
1254 .finally(function(barcode) {
1255 if (barcode) deferred.notify(barcode);
1259 mark_one(); // kick it off
1260 return deferred.promise;
1266 // serially checks in each barcode with claims_never_checked_out set
1267 // returns promise, notified on each barcode, resolved after all
1268 // checkins are complete.
1269 service.mark_claims_never_checked_out = function(barcodes) {
1270 if (!barcodes.length) return;
1272 var deferred = $q.defer();
1273 egConfirmDialog.open(
1274 egCore.strings.MARK_NEVER_CHECKED_OUT, '', {barcodes : barcodes}
1276 ).result.then(function() {
1277 function mark_one() {
1278 var bc = barcodes.pop();
1280 if (!bc) { // all done
1286 {claims_never_checked_out : true, copy_barcode : bc})
1287 .finally(function() {
1288 deferred.notify(bc);
1295 return deferred.promise;
1298 service.mark_damaged = function(params) {
1299 if (!params) return $q.when();
1300 return $uibModal.open({
1301 templateUrl: './circ/share/t_mark_damaged',
1303 ['$scope', '$uibModalInstance', 'egCore', 'egBilling', 'egItem',
1304 function($scope, $uibModalInstance, egCore, egBilling, egItem) {
1305 var doRefresh = params.refresh;
1307 $scope.billArgs = {charge: params.charge};
1308 $scope.mode = 'charge';
1309 $scope.barcode = params.barcode;
1310 if (params.charge && params.charge > 0) {
1311 $scope.applyFine = "apply";
1314 $scope.circ = params.circ;
1315 $scope.circ_checkin_time = params.circ.checkin_time();
1316 $scope.circ_patron_name = params.circ.usr().family_name() + ", "
1317 + params.circ.usr().first_given_name() + " "
1318 + params.circ.usr().second_given_name();
1320 egBilling.fetchBillingTypes().then(function(res) {
1321 $scope.billingTypes = res;
1324 $scope.btnChargeFees = function() {
1325 $scope.mode = 'charge';
1326 $scope.billArgs.charge = params.charge;
1327 $scope.applyFine = "apply";
1329 $scope.btnWaiveFees = function() {
1330 $scope.mode = 'waive';
1331 $scope.billArgs.charge = 0;
1332 $scope.applyFine = "noapply";
1335 $scope.cancel = function ($event) {
1336 $uibModalInstance.dismiss();
1338 $scope.ok = function() {
1339 handle_mark_item_damaged();
1342 var handle_mark_item_damaged = function() {
1345 'open-ils.circ.mark_item_damaged',
1346 egCore.auth.token(), params.id, {
1347 apply_fines: $scope.applyFine,
1348 override_amount: $scope.billArgs.charge,
1349 override_btype: $scope.billArgs.type,
1350 override_note: $scope.billArgs.note,
1351 handle_checkin: !$scope.applyFine
1352 }).then(function(resp) {
1353 if (evt = egCore.evt.parse(resp)) {
1355 console.debug("mark damaged more information required. Pushing back.");
1356 service.mark_damaged({
1358 barcode: params.barcode,
1359 charge: evt.payload.charge,
1360 circ: evt.payload.circ,
1361 refresh: params.refresh
1363 console.error('mark damaged failed: ' + evt);
1365 }).then(function() {
1366 if (doRefresh) egItem.add_barcode_to_list(params.barcode);
1368 $uibModalInstance.close();
1374 service.mark_missing = function(copy_ids) {
1375 return egConfirmDialog.open(
1376 egCore.strings.MARK_MISSING_CONFIRM, '',
1377 { num_items : copy_ids.length,
1379 cancel : function() {}
1381 ).result.then(function() {
1383 angular.forEach(copy_ids, function(copy_id) {
1387 'open-ils.circ.mark_item_missing',
1388 egCore.auth.token(), copy_id
1389 ).then(function(resp) {
1390 if (evt = egCore.evt.parse(resp)) {
1391 console.error('mark missing failed: ' + evt);
1397 return $q.all(promises);
1403 // Mark circulations as lost via copy barcode. As each item is
1404 // processed, the returned promise is notified of the barcode.
1405 // No confirmation dialog is presented.
1406 service.mark_lost = function(copy_barcodes) {
1407 var deferred = $q.defer();
1410 angular.forEach(copy_barcodes, function(barcode) {
1414 'open-ils.circ.circulation.set_lost',
1415 egCore.auth.token(), {barcode : barcode}
1416 ).then(function(resp) {
1417 if (evt = egCore.evt.parse(resp)) {
1418 console.error("Mark lost failed: " + evt.toString());
1421 // inform the caller as each item is processed
1422 deferred.notify(barcode);
1427 $q.all(promises).then(function() {deferred.resolve()});
1428 return deferred.promise;
1431 service.abort_transits = function(transit_ids) {
1432 return egConfirmDialog.open(
1433 egCore.strings.ABORT_TRANSIT_CONFIRM, '',
1434 { num_transits : transit_ids.length,
1436 cancel : function() {}
1439 ).result.then(function() {
1441 angular.forEach(transit_ids, function(transit_id) {
1445 'open-ils.circ.transit.abort',
1446 egCore.auth.token(), {transitid : transit_id}
1447 ).then(function(resp) {
1448 if (evt = egCore.evt.parse(resp)) {
1449 console.error('abort transit failed: ' + evt);
1455 return $q.all(promises);
1459 service.add_copy_alerts = function(item_ids) {
1460 return egAddCopyAlertDialog.open({
1461 copy_ids : item_ids,
1462 ok : function() { },
1463 cancel : function() {}
1464 }).result.then(function() { });
1467 service.manage_copy_alerts = function(item_ids) {
1468 return egCopyAlertEditorDialog.open({
1469 copy_id : item_ids[0],
1470 ok : function() { },
1471 cancel : function() {}
1472 }).result.then(function() { });
1475 // alert when copy location alert_message is set.
1476 // This does not affect processing, it only produces a click-through
1477 service.handle_checkin_loc_alert = function(evt, params, options) {
1478 if (angular.isArray(evt)) evt = evt[0];
1480 var copy = evt && evt.payload ? evt.payload.copy : null;
1482 if (copy && !options.suppress_checkin_popups
1483 && copy.location().checkin_alert() == 't') {
1485 return egAlertDialog.open(
1486 egCore.strings.LOCATION_ALERT_MSG, {copy : copy}).result;
1492 service.handle_checkin_resp = function(evt, params, options) {
1493 if (!angular.isArray(evt)) evt = [evt];
1495 var final_resp = {evt : evt, params : params, options : options};
1497 var copy, hold, transit;
1498 if (evt[0].payload) {
1499 copy = evt[0].payload.copy;
1500 hold = evt[0].payload.hold;
1501 transit = evt[0].payload.transit;
1504 // track the barcode regardless of whether it's valid
1505 angular.forEach(evt, function(e){ e.copy_barcode = params.copy_barcode; });
1507 angular.forEach(evt, function(e){ console.debug('checkin event ' + e.textcode); });
1509 if (evt.filter(function(e){return service.checkin_overridable_events.indexOf(e.textcode) > -1;}).length > 0)
1510 return service.handle_overridable_checkin_event(evt, params, options);
1512 switch (evt[0].textcode) {
1517 switch(Number(copy.status().id())) {
1519 case 0: /* AVAILABLE */
1520 case 4: /* MISSING */
1521 case 7: /* RESHELVING */
1523 egCore.audio.play('success.checkin');
1525 // see if the copy location requires an alert
1526 return service.handle_checkin_loc_alert(evt, params, options)
1527 .then(function() {return final_resp});
1529 case 8: /* ON HOLDS SHELF */
1530 egCore.audio.play('info.checkin.holds_shelf');
1534 if (hold.pickup_lib() == egCore.auth.user().ws_ou()) {
1535 // inform user if the item is on the local holds shelf
1537 evt[0].route_to = egCore.strings.ROUTE_TO_HOLDS_SHELF;
1538 return service.route_dialog(
1539 './circ/share/t_hold_shelf_dialog',
1540 evt[0], params, options
1541 ).then(function() { return final_resp });
1544 // normally, if the hold was on the shelf at a
1545 // different location, it would be put into
1546 // transit, resulting in a ROUTE_ITEM event.
1547 egCore.audio.play('warning.checkin.wrong_shelf');
1548 return $q.when(final_resp);
1552 console.error('checkin: item on holds shelf, '
1553 + 'but hold info not returned from checkin');
1554 return $q.when(final_resp);
1557 case 11: /* CATALOGING */
1558 egCore.audio.play('info.checkin.cataloging');
1559 evt[0].route_to = egCore.strings.ROUTE_TO_CATALOGING;
1560 if (options.no_precat_alert)
1561 return $q.when(final_resp);
1562 return egAlertDialog.open(
1563 egCore.strings.PRECAT_CHECKIN_MSG, params)
1564 .result.then(function() {return final_resp});
1567 case 15: /* ON_RESERVATION_SHELF */
1568 egCore.audio.play('info.checkin.reservation');
1569 // TODO: show booking reservation dialog
1570 return $q.when(final_resp);
1573 egCore.audio.play('success.checkin');
1574 console.debug('Unusual checkin copy status (may have been set via copy alert): '
1575 + copy.status().id() + ' : ' + copy.status().name());
1576 return $q.when(final_resp);
1580 return service.route_dialog(
1581 './circ/share/t_transit_dialog',
1582 evt[0], params, options
1583 ).then(function() { return final_resp });
1585 case 'ASSET_COPY_NOT_FOUND':
1586 egCore.audio.play('error.checkin.not_found');
1587 return egAlertDialog.open(
1588 egCore.strings.UNCAT_ALERT_DIALOG, params)
1589 .result.then(function() {return final_resp});
1591 case 'ITEM_NOT_CATALOGED':
1592 egCore.audio.play('error.checkin.not_cataloged');
1593 evt[0].route_to = egCore.strings.ROUTE_TO_CATALOGING;
1594 if (options.no_precat_alert)
1595 return $q.when(final_resp);
1596 return egAlertDialog.open(
1597 egCore.strings.PRECAT_CHECKIN_MSG, params)
1598 .result.then(function() {return final_resp});
1601 egCore.audio.play('error.checkin.unknown');
1602 console.warn('unhandled checkin response : ' + evt[0].textcode);
1603 return $q.when(final_resp);
1607 // collect transit, address, and hold info that's not already
1608 // included in responses.
1609 service.collect_route_data = function(tmpl, evt, params, options) {
1610 if (angular.isArray(evt)) evt = evt[0];
1614 if (evt.org && !tmpl.match(/hold_shelf/)) {
1616 service.get_org_addr(evt.org, 'holds_address')
1617 .then(function(addr) { data.address = addr })
1621 if (evt.payload.hold) {
1623 egCore.pcrud.retrieve('au',
1624 evt.payload.hold.usr(), {
1626 flesh_fields : {'au' : ['card']}
1628 ).then(function(patron) {data.patron = patron})
1633 if (!tmpl.match(/hold_shelf/)) {
1634 var courier_deferred = $q.defer();
1635 promises.push(courier_deferred.promise);
1637 service.find_copy_transit(evt, params, options)
1638 .then(function(trans) {
1639 data.transit = trans;
1640 egCore.org.settings('lib.courier_code', trans.dest().id())
1642 data.dest_courier_code = s['lib.courier_code'];
1643 courier_deferred.resolve();
1649 return $q.all(promises).then(function() { return data });
1652 service.route_dialog = function(tmpl, evt, params, options) {
1653 if (angular.isArray(evt)) evt = evt[0];
1655 return service.collect_route_data(tmpl, evt, params, options)
1656 .then(function(data) {
1658 var template = data.transit ?
1659 (data.patron ? 'hold_transit_slip' : 'transit_slip') :
1661 if (service.never_auto_print[template]) {
1662 // do not show the dialog or print if the
1663 // disabled automatic print attempt type list includes
1664 // the specified template
1668 // All actions flow from the print data
1670 var print_context = {
1671 copy : egCore.idl.toHash(evt.payload.copy),
1673 author : evt.author,
1674 call_number : egCore.idl.toHash(evt.payload.volume)
1677 var acn = print_context.call_number; // fix up pre/suffixes
1678 if (acn.prefix == -1) acn.prefix = "";
1679 if (acn.suffix == -1) acn.suffix = "";
1682 // route_dialog includes the "route to holds shelf"
1683 // dialog, which has no transit
1684 print_context.transit = egCore.idl.toHash(data.transit);
1685 print_context.dest_courier_code = data.dest_courier_code;
1687 print_context.dest_address = egCore.idl.toHash(data.address);
1689 print_context.dest_location =
1690 egCore.idl.toHash(egCore.org.get(data.transit.dest()));
1694 print_context.hold = egCore.idl.toHash(evt.payload.hold);
1695 var notes = print_context.hold.notes;
1696 if(notes.length > 0){
1697 print_context.hold_notes = [];
1698 angular.forEach(notes, function(n){
1699 print_context.hold_notes.push(n);
1702 print_context.patron = egCore.idl.toHash(data.patron);
1705 var sound = 'info.checkin.transit';
1706 if (evt.payload.hold) sound += '.hold';
1707 egCore.audio.play(sound);
1709 function print_transit(template) {
1710 return egCore.print.print({
1711 context : 'default',
1712 template : template,
1713 scope : print_context
1717 // when auto-print is on, skip the dialog and go straight
1719 if (options.auto_print_holds_transits)
1720 return print_transit(template);
1722 return $uibModal.open({
1726 '$scope','$uibModalInstance',
1727 function($scope , $uibModalInstance) {
1729 $scope.today = new Date();
1731 // copy the print scope into the dialog scope
1732 angular.forEach(print_context, function(val, key) {
1736 $scope.ok = function() {$uibModalInstance.close()}
1738 $scope.print = function() {
1739 $uibModalInstance.close();
1740 print_transit(template);
1748 // action == what action to take if the user confirms the alert
1749 service.copy_alert_dialog = function(evt, params, options, action) {
1750 if (angular.isArray(evt)) evt = evt[0];
1751 if (!angular.isArray(evt.payload)) {
1752 return egConfirmDialog.open(
1753 egCore.strings.COPY_ALERT_MSG_DIALOG_TITLE,
1754 evt.payload, // payload == alert message text
1755 { copy_barcode : params.copy_barcode,
1757 cancel : function() {}
1759 ).result.then(function() {
1760 options.override = true;
1761 return service[action](params, options);
1763 } else { // we got a list of copy alert objects ...
1764 return egCopyAlertManagerDialog.open({
1765 alerts : evt.payload,
1767 ok : function(the_next_status) {
1768 if (the_next_status !== null) {
1769 params.next_copy_status = [ the_next_status ];
1770 params.capture = 'nocapture';
1773 cancel : function() {}
1774 }).result.then(function() {
1775 options.override = true;
1776 return service[action](params, options);
1781 // action == what action to take if the user confirms the alert
1782 service.hold_capture_delay_dialog = function(evt, params, options, action) {
1783 if (angular.isArray(evt)) evt = evt[0];
1784 return $uibModal.open({
1785 templateUrl: './circ/checkin/t_hold_verify',
1788 ['$scope','$uibModalInstance','params',
1789 function($scope , $uibModalInstance , params) {
1790 $scope.copy_barcode = params.copy_barcode;
1791 $scope.capture = function() {
1792 params.capture = 'capture';
1793 $uibModalInstance.close();
1795 $scope.nocapture = function() {
1796 params.capture = 'nocapture';
1797 $uibModalInstance.close();
1799 $scope.cancel = function() { $uibModalInstance.dismiss(); };
1802 params : function() {
1808 return service[action](params, options);
1813 // check the barcode. If it's no good, show the warning dialog
1814 // Resolves on success, rejected on error
1815 service.test_barcode = function(bc) {
1817 var ok = service.check_barcode(bc);
1818 if (ok) return $q.when();
1820 egCore.audio.play('warning.circ.bad_barcode');
1821 return $uibModal.open({
1822 templateUrl: './circ/share/t_bad_barcode_dialog',
1825 ['$scope', '$uibModalInstance',
1826 function($scope, $uibModalInstance) {
1827 $scope.barcode = bc;
1828 $scope.ok = function() { $uibModalInstance.close() }
1829 $scope.cancel = function() { $uibModalInstance.dismiss() }
1834 // check() and checkdigit() copied directly
1835 // from chrome/content/util/barcode.js
1837 service.check_barcode = function(bc) {
1838 if (bc != Number(bc)) return false;
1840 // "16.00" == Number("16.00"), but the . is bad.
1841 // Throw out any barcode that isn't just digits
1842 if (bc.search(/\D/) != -1) return false;
1843 var last_digit = bc.substr(bc.length-1);
1844 var stripped_barcode = bc.substr(0,bc.length-1);
1845 return service.barcode_checkdigit(stripped_barcode).toString() == last_digit;
1848 service.barcode_checkdigit = function(bc) {
1849 var reverse_barcode = bc.toString().split('').reverse();
1850 var check_sum = 0; var multiplier = 2;
1851 for (var i = 0; i < reverse_barcode.length; i++) {
1852 var digit = reverse_barcode[i];
1853 var product = digit * multiplier; product = product.toString();
1855 for (var j = 0; j < product.length; j++) {
1856 temp_sum += Number( product[j] );
1858 check_sum += Number( temp_sum );
1859 multiplier = ( multiplier == 2 ? 1 : 2 );
1861 check_sum = check_sum.toString();
1862 var next_multiple_of_10 = (check_sum.match(/(\d*)\d$/)[1] * 10) + 10;
1863 var check_digit = next_multiple_of_10 - Number(check_sum);
1864 if (check_digit == 10) check_digit = 0;
1868 service.handle_barcode_completion = function(barcode) {
1869 return egCore.net.request(
1871 'open-ils.actor.get_barcodes',
1872 egCore.auth.token(), egCore.auth.user().ws_ou(),
1875 .then(function(resp) {
1876 // TODO: handle event during barcode lookup
1877 if (evt = egCore.evt.parse(resp)) {
1878 console.error(evt.toString());
1882 // no matching barcodes: return the barcode as entered
1883 // by the user (so that, e.g., checkout can fall back to
1884 // precat/noncat handling)
1885 if (!resp || !resp[0]) {
1889 // exactly one matching barcode: return it
1890 if (resp.length == 1) {
1891 return resp[0].barcode;
1894 // multiple matching barcodes: let the user pick one
1895 console.debug('multiple matching barcodes');
1899 angular.forEach(resp, function(cp) {
1903 'open-ils.circ.copy_details.retrieve',
1904 egCore.auth.token(), cp.id
1905 ).then(function(r) {
1907 barcode: r.copy.barcode(),
1908 title: r.mvr.title(),
1909 org_name: egCore.org.get(r.copy.circ_lib()).name(),
1910 org_shortname: egCore.org.get(r.copy.circ_lib()).shortname()
1915 return $q.all(promises)
1917 return $uibModal.open({
1918 templateUrl: './circ/share/t_barcode_choice_dialog',
1921 ['$scope', '$uibModalInstance',
1922 function($scope, $uibModalInstance) {
1923 $scope.matches = matches;
1924 $scope.ok = function(barcode) {
1925 $uibModalInstance.close();
1926 final_barcode = barcode;
1928 $scope.cancel = function() {$uibModalInstance.dismiss()}
1930 }).result.then(function() { return final_barcode });
1935 service.create_penalty = function(user_id) {
1936 return $uibModal.open({
1937 templateUrl: './circ/share/t_new_message_dialog',
1940 ['$scope','$uibModalInstance','staffPenalties',
1941 function($scope , $uibModalInstance , staffPenalties) {
1942 $scope.focusNote = true;
1943 $scope.penalties = staffPenalties;
1944 $scope.require_initials = service.require_initials;
1945 $scope.args = {penalty : 21}; // default to Note
1946 $scope.setPenalty = function(id) {
1949 $scope.ok = function(count) { $uibModalInstance.close($scope.args) }
1950 $scope.cancel = function($event) {
1951 $uibModalInstance.dismiss();
1952 $event.preventDefault();
1955 resolve : { staffPenalties : service.get_staff_penalty_types }
1958 var pen = new egCore.idl.ausp();
1960 pen.org_unit(egCore.auth.user().ws_ou());
1961 pen.note(args.note);
1962 if (args.initials) pen.note(args.note + ' [' + args.initials + ']');
1963 if (args.custom_penalty) {
1964 pen.standing_penalty(args.custom_penalty);
1966 pen.standing_penalty(args.penalty);
1968 pen.staff(egCore.auth.user().id());
1969 pen.set_date('now');
1971 return egCore.net.request(
1973 'open-ils.actor.user.penalty.apply',
1974 egCore.auth.token(), pen
1980 // assumes, for now anyway, penalty type is fleshed onto usr_penalty.
1981 service.edit_penalty = function(usr_penalty) {
1982 return $uibModal.open({
1983 templateUrl: './circ/share/t_new_message_dialog',
1986 ['$scope','$uibModalInstance','staffPenalties',
1987 function($scope , $uibModalInstance , staffPenalties) {
1988 $scope.focusNote = true;
1989 $scope.penalties = staffPenalties;
1990 $scope.require_initials = service.require_initials;
1992 penalty : usr_penalty.standing_penalty().id(),
1993 note : usr_penalty.note()
1995 $scope.setPenalty = function(id) { args.penalty = id; }
1996 $scope.ok = function(count) { $uibModalInstance.close($scope.args) }
1997 $scope.cancel = function($event) {
1998 $uibModalInstance.dismiss();
1999 $event.preventDefault();
2002 resolve : { staffPenalties : service.get_staff_penalty_types }
2005 usr_penalty.note(args.note);
2006 if (args.initials) usr_penalty.note(args.note + ' [' + args.initials + ']');
2007 usr_penalty.standing_penalty(args.penalty);
2008 return egCore.pcrud.update(usr_penalty);