1 dojo.require('dojo.date.locale');
2 dojo.require('dojo.date.stamp');
3 dojo.require('openils.CGI');
4 dojo.require('openils.Util');
5 dojo.require('openils.User');
6 dojo.require('openils.Event');
7 dojo.require('openils.widget.ProgressDialog');
9 dojo.requireLocalization('openils.circ', 'selfcheck');
10 var localeStrings = dojo.i18n.getLocalization('openils.circ', 'selfcheck');
13 const SET_BARCODE_REGEX = 'opac.barcode_regex';
14 const SET_PATRON_TIMEOUT = 'circ.selfcheck.patron_login_timeout';
15 const SET_AUTO_OVERRIDE_EVENTS = 'circ.selfcheck.auto_override_checkout_events';
16 const SET_PATRON_PASSWORD_REQUIRED = 'circ.selfcheck.patron_password_required';
17 const SET_AUTO_RENEW_INTERVAL = 'circ.checkout_auto_renew_age';
18 const SET_WORKSTATION_REQUIRED = 'circ.selfcheck.workstation_required';
19 const SET_ALERT_POPUP = 'circ.selfcheck.alert.popup';
20 const SET_ALERT_SOUND = 'circ.selfcheck.alert.sound';
22 function SelfCheckManager() {
24 this.cgi = new openils.CGI();
26 this.workstation = null;
27 this.authtoken = null;
30 this.patronBarcodeRegex = null;
35 // During renewals, keep track of the ID of the previous circulation.
36 // Previous circ is used for tracking failed renewals (for receipts).
39 // current item barcode
40 this.itemBarcode = null;
42 // are we currently performing a renewal?
43 this.isRenewal = false;
45 // dict of org unit settings for "here"
46 this.orgSettings = {};
48 // Construct a mock checkout for debugging purposes
49 if(this.mockCheckouts = this.cgi.param('mock-circ')) {
53 record : new fieldmapper.mvr(),
54 copy : new fieldmapper.acp(),
55 circ : new fieldmapper.circ()
59 this.mockCheckout.payload.record.title('Jazz improvisation for guitar');
60 this.mockCheckout.payload.record.author('Wise, Les');
61 this.mockCheckout.payload.record.isbn('0634033565');
62 this.mockCheckout.payload.copy.barcode('123456789');
63 this.mockCheckout.payload.circ.renewal_remaining(1);
64 this.mockCheckout.payload.circ.parent_circ(1);
65 this.mockCheckout.payload.circ.due_date('2012-12-21');
72 * Fetch the org-unit settings, initialize the display, etc.
74 SelfCheckManager.prototype.init = function() {
76 this.staff = openils.User.user;
77 this.workstation = openils.User.workstation;
78 this.authtoken = openils.User.authtoken;
79 this.loadOrgSettings();
81 this.circTbody = dojo.byId('oils-selfck-circ-tbody');
82 this.itemsOutTbody = dojo.byId('oils-selfck-circ-out-tbody');
84 // workstation is required but none provided
85 if(this.orgSettings[SET_WORKSTATION_REQUIRED] && !this.workstation) {
86 alert(dojo.string.substitute(localeStrings.WORKSTATION_REQUIRED));
91 // connect onclick handlers to the various navigation links
93 'oils-selfck-hold-details-link' : function() { self.drawHoldsPage(); },
94 'oils-selfck-pay-fines-link' : function() { self.drawFinesPage(); },
95 'oils-selfck-nav-home' : function() { self.drawCircPage(); },
96 'oils-selfck-nav-logout' : function() { self.logoutPatron(); },
97 'oils-selfck-nav-logout-print' : function() { self.logoutPatron(true); },
98 'oils-selfck-items-out-details-link' : function() { self.drawItemsOutPage(); },
99 'oils-selfck-print-list-link' : function() { self.printList(); }
102 for(var id in linkHandlers)
103 dojo.connect(dojo.byId(id), 'onclick', linkHandlers[id]);
106 if(this.cgi.param('patron')) {
108 // Patron barcode via cgi param. Mainly used for debugging and
109 // only works if password is not required by policy
110 this.loginPatron(this.cgi.param('patron'));
113 this.drawLoginPage();
117 * To test printing, pass a URL param of 'testprint'. The value for the param
118 * should be a JSON string like so: [{circ:<circ_id>}, ...]
120 var testPrint = this.cgi.param('testprint');
122 this.checkouts = JSON2js(testPrint);
123 this.printSessionReceipt();
129 * Loads the org unit settings
131 SelfCheckManager.prototype.loadOrgSettings = function() {
133 var settings = fieldmapper.aou.fetchOrgSettingBatch(
134 this.staff.ws_ou(), [
139 SET_AUTO_OVERRIDE_EVENTS,
140 SET_PATRON_PASSWORD_REQUIRED,
141 SET_AUTO_RENEW_INTERVAL,
142 SET_WORKSTATION_REQUIRED
148 this.orgSettings[k] = settings[k].value;
151 if(settings[SET_BARCODE_REGEX])
152 this.patronBarcodeRegex = new RegExp(settings[SET_BARCODE_REGEX].value);
155 SelfCheckManager.prototype.drawLoginPage = function() {
158 var bcHandler = function(barcode) {
159 // handle patron barcode entry
161 if(self.orgSettings[SET_PATRON_PASSWORD_REQUIRED]) {
163 // password is required. wire up the scan box to read it
165 msg : 'Please enter your password', // TODO i18n
166 handler : function(pw) { self.loginPatron(barcode, pw); },
171 // password is not required, go ahead and login
172 self.loginPatron(barcode);
177 msg : 'Please log in with your library barcode.', // TODO
185 SelfCheckManager.prototype.loginPatron = function(barcode, passwd) {
187 if(this.orgSettings[SET_PATRON_PASSWORD_REQUIRED]) {
190 // would only happen in dev/debug mode when using the patron= param
191 alert('password required by org setting. remove patron= from URL');
195 // patron password is required. Verify it.
197 var res = fieldmapper.standardRequest(
198 ['open-ils.actor', 'open-ils.actor.verify_user_password'],
199 {params : [this.authtoken, barcode, null, hex_md5(passwd)]}
203 // user-not-found results in login failure
205 dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]),
206 false, 'login-failure'
208 this.drawLoginPage();
213 // retrieve the fleshed user by barcode
214 this.patron = fieldmapper.standardRequest(
215 ['open-ils.actor', 'open-ils.actor.user.fleshed.retrieve_by_barcode'],
216 {params : [this.authtoken, barcode]}
219 var evt = openils.Event.parse(this.patron);
222 dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]),
223 false, 'login-failure'
225 this.drawLoginPage();
229 this.handleAlert('', false, 'login-success');
230 dojo.byId('oils-selfck-user-banner').innerHTML = 'Welcome, ' + this.patron.first_given_name(); // TODO i18n
236 SelfCheckManager.prototype.handleAlert = function(message, shouldPopup, sound) {
238 console.log("Handling alert " + message);
240 dojo.byId('oils-selfck-status-div').innerHTML = message;
242 if(shouldPopup && this.orgSettings[SET_ALERT_POPUP])
245 if(sound && this.orgSettings[SET_ALERT_SOUND])
246 openils.Util.playAudioUrl(SelfCheckManager.audioConfig[sound]);
251 * Manages the main input box
252 * @param msg The context message to display with the box
253 * @param clearOnly Don't update the context message, just clear the value and re-focus
254 * @param handler Optional "on-enter" handler.
256 SelfCheckManager.prototype.updateScanBox = function(args) {
260 selfckScanBox.domNode.select();
262 selfckScanBox.attr('value', '');
266 selfckScanBox.domNode.setAttribute('type', 'password');
268 selfckScanBox.domNode.setAttribute('type', '');
272 selfckScanBox.attr('value', args.value);
275 dojo.byId('oils-selfck-scan-text').innerHTML = args.msg;
277 if(selfckScanBox._lastHandler && (args.handler || args.clearHandler)) {
278 dojo.disconnect(selfckScanBox._lastHandler);
282 selfckScanBox._lastHandler = dojo.connect(
286 if(e.keyCode != dojo.keys.ENTER)
288 args.handler(selfckScanBox.attr('value'));
293 selfckScanBox.focus();
297 * Sets up the checkout/renewal interface
299 SelfCheckManager.prototype.drawCircPage = function() {
301 openils.Util.show('oils-selfck-circ-tbody');
302 this.goToTab('checkout');
304 while(this.itemsOutTbody.childNodes[0])
305 this.itemsOutTbody.removeChild(this.itemsOutTbody.childNodes[0]);
309 msg : 'Please enter an item barcode', // TODO i18n
310 handler : function(barcode) { self.checkout(barcode); }
313 if(!this.circTemplate)
314 this.circTemplate = this.circTbody.removeChild(dojo.byId('oils-selfck-circ-row'));
316 // items out, holds, and fines summaries
319 fieldmapper.standardRequest(
320 ['open-ils.actor', 'open-ils.actor.user.fines.summary'],
322 params : [this.authtoken, this.patron.id()],
323 oncomplete : function(r) {
324 var summary = openils.Util.readResponse(r);
325 dojo.byId('oils-selfck-fines-total').innerHTML =
326 dojo.string.substitute(
327 localeStrings.TOTAL_FINES_ACCOUNT,
328 [summary.balance_owed()]
335 this.updateHoldsSummary();
338 this.updateCircSummary();
340 // render mock checkouts for debugging?
341 if(this.mockCheckouts) {
342 for(var i in [1,2,3])
343 this.displayCheckout(this.mockCheckout, 'checkout');
348 SelfCheckManager.prototype.drawItemsOutPage = function() {
349 openils.Util.hide('oils-selfck-circ-tbody');
351 this.goToTab('items_out');
353 while(this.itemsOutTbody.childNodes[0])
354 this.itemsOutTbody.removeChild(this.itemsOutTbody.childNodes[0]);
356 progressDialog.show(true);
359 fieldmapper.standardRequest(
360 ['open-ils.circ', 'open-ils.circ.actor.user.checked_out.atomic'],
363 params : [this.authtoken, this.patron.id()],
364 oncomplete : function(r) {
366 var resp = openils.Util.readResponse(r);
368 var circs = resp.sort(
370 if(a.circ.due_date() > b.circ.due_date())
376 progressDialog.hide();
381 self.itemsOut.push(circ.circ.id());
382 self.displayCheckout(
384 (circ.circ.parent_circ()) ? 'renew' : 'checkout',
395 SelfCheckManager.prototype.goToTab = function(name) {
398 openils.Util.hide('oils-selfck-payment-page');
399 openils.Util.hide('oils-selfck-holds-page');
400 openils.Util.hide('oils-selfck-circ-page');
404 openils.Util.show('oils-selfck-circ-page');
407 openils.Util.show('oils-selfck-circ-page');
410 openils.Util.show('oils-selfck-holds-page');
413 openils.Util.show('oils-selfck-payment-page');
419 SelfCheckManager.prototype.printList = function() {
420 switch(this.tabName) {
422 this.printSessionReceipt();
425 this.printItemsOutReceipt();
428 this.printHoldsReceipt();
431 this.printFinesReceipt();
436 SelfCheckManager.prototype.updateHoldsSummary = function() {
438 if(!this.holdsSummary) {
439 var summary = fieldmapper.standardRequest(
440 ['open-ils.circ', 'open-ils.circ.holds.user_summary'],
441 {params : [this.authtoken, this.patron.id()]}
444 this.holdsSummary = {};
445 this.holdsSummary.ready = Number(summary['4']);
446 this.holdsSummary.total = 0;
448 for(var i in summary)
449 this.holdsSummary.total += Number(summary[i]);
452 dojo.byId('oils-selfck-holds-total').innerHTML =
453 dojo.string.substitute(
454 localeStrings.TOTAL_HOLDS,
455 [this.holdsSummary.total]
458 dojo.byId('oils-selfck-holds-ready').innerHTML =
459 dojo.string.substitute(
460 localeStrings.HOLDS_READY_FOR_PICKUP,
461 [this.holdsSummary.ready]
466 SelfCheckManager.prototype.updateCircSummary = function(increment) {
468 if(!this.circSummary) {
470 var summary = fieldmapper.standardRequest(
471 ['open-ils.actor', 'open-ils.actor.user.checked_out.count'],
472 {params : [this.authtoken, this.patron.id()]}
476 total : Number(summary.out) + Number(summary.overdue),
477 overdue : Number(summary.overdue),
483 // local checkout occurred. Add to the total and the session.
484 this.circSummary.total += 1;
485 this.circSummary.session += 1;
488 dojo.byId('oils-selfck-circ-account-total').innerHTML =
489 dojo.string.substitute(
490 localeStrings.TOTAL_ITEMS_ACCOUNT,
491 [this.circSummary.total]
494 dojo.byId('oils-selfck-circ-session-total').innerHTML =
495 dojo.string.substitute(
496 localeStrings.TOTAL_ITEMS_SESSION,
497 [this.circSummary.session]
502 SelfCheckManager.prototype.drawHoldsPage = function() {
504 // TODO add option to hid scanBox
505 // this.updateScanBox(...)
507 this.goToTab('holds');
509 this.holdTbody = dojo.byId('oils-selfck-hold-tbody');
510 if(!this.holdTemplate)
511 this.holdTemplate = this.holdTbody.removeChild(dojo.byId('oils-selfck-hold-row'));
512 while(this.holdTbody.childNodes[0])
513 this.holdTbody.removeChild(this.holdTbody.childNodes[0]);
515 progressDialog.show(true);
518 fieldmapper.standardRequest( // fetch the hold IDs
520 ['open-ils.circ', 'open-ils.circ.holds.id_list.retrieve'],
522 params : [this.authtoken, this.patron.id()],
524 oncomplete : function(r) {
525 var ids = openils.Util.readResponse(r);
526 if(!ids || ids.length == 0) {
527 progressDialog.hide();
531 fieldmapper.standardRequest( // fetch the hold objects with fleshed details
532 ['open-ils.circ', 'open-ils.circ.hold.details.batch.retrieve.atomic'],
534 params : [self.authtoken, ids],
536 oncomplete : function(rr) {
537 self.drawHolds(openils.Util.readResponse(rr));
547 * Fetch and add a single hold to the list of holds
549 SelfCheckManager.prototype.drawHolds = function(holds) {
552 // sort available holds to the top of the list
553 // followed by queue position order
555 if(a.status == 4) return -1;
556 if(a.queue_position < b.queue_position) return -1;
563 progressDialog.hide();
565 for(var i in holds) {
568 var row = this.holdTemplate.cloneNode(true);
570 if(data.mvr.isbn()) {
571 this.byName(row, 'jacket').setAttribute('src', '/opac/extras/ac/jacket/small/' + data.mvr.isbn());
574 this.byName(row, 'title').innerHTML = data.mvr.title();
575 this.byName(row, 'author').innerHTML = data.mvr.author();
577 if(data.status == 4) {
579 // hold is ready for pickup
580 this.byName(row, 'status').innerHTML = localeStrings.HOLD_STATUS_READY;
584 // hold is still pending
585 this.byName(row, 'status').innerHTML =
586 dojo.string.substitute(
587 localeStrings.HOLD_STATUS_WAITING,
588 [data.queue_position, data.potential_copies]
592 this.holdTbody.appendChild(row);
597 SelfCheckManager.prototype.drawFinesPage = function() {
599 // TODO add option to hid scanBox
600 // this.updateScanBox(...)
602 this.goToTab('fines');
603 progressDialog.show(true);
605 this.finesTbody = dojo.byId('oils-selfck-fines-tbody');
606 if(!this.finesTemplate)
607 this.finesTemplate = this.finesTbody.removeChild(dojo.byId('oils-selfck-fines-row'));
608 while(this.finesTbody.childNodes[0])
609 this.finesTbody.removeChild(this.finesTbody.childNodes[0]);
612 var handler = function(dataList) {
613 for(var i in dataList) {
614 var data = dataList[i];
615 var row = self.finesTemplate.cloneNode(true);
616 var type = data.transaction.xact_type();
617 if(type == 'circulation') {
618 self.byName(row, 'type').innerHTML = type;
619 self.byName(row, 'details').innerHTML = data.record.title();
620 } else if(type == 'grocery') {
621 self.byName(row, 'type').innerHTML = 'Miscellaneous'; // Go ahead and head off any confusion around "grocery". TODO i18n
622 self.byName(row, 'details').innerHTML = data.transaction.last_billing_type();
624 self.byName(row, 'total_owed').innerHTML = data.transaction.total_owed();
625 self.byName(row, 'total_paid').innerHTML = data.transaction.total_paid();
626 self.byName(row, 'balance').innerHTML = data.transaction.balance_owed();
627 self.finesTbody.appendChild(row);
631 fieldmapper.standardRequest(
632 ['open-ils.actor', 'open-ils.actor.user.transactions.have_balance.fleshed'],
634 params : [this.authtoken, this.patron.id()],
635 oncomplete : function(r) {
636 progressDialog.hide();
637 handler(openils.Util.readResponse(r));
645 * Check out a single item. If the item is already checked
646 * out to the patron, redirect to renew()
648 SelfCheckManager.prototype.checkout = function(barcode, override) {
650 this.prevCirc = null;
653 this.updateScanbox(null, true);
657 if(this.mockCheckouts) {
658 // if we're in mock-checkout mode, just insert another
659 // fake circ into the table and get out of here.
660 this.displayCheckout(this.mockCheckout, 'checkout');
664 // TODO see if it's a patron barcode
665 // TODO see if this item has already been checked out in this session
667 var method = 'open-ils.circ.checkout.full';
668 if(override) method += '.override';
670 console.log("Checkout out item " + barcode + " with method " + method);
672 var result = fieldmapper.standardRequest(
673 ['open-ils.circ', 'open-ils.circ.checkout.full'],
676 patron_id : this.patron.id(),
677 copy_barcode : barcode
682 console.log(js2JSON(result));
684 var stat = this.handleXactResult('checkout', barcode, result);
687 this.checkout(barcode, true);
688 } else if(stat.renew) {
694 SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
696 var displayText = '';
698 // If true, the display message is important enough to pop up. Whether or not
699 // an alert() actually occurs, depends on org unit settings
704 // TODO handle lost/missing/etc checkin+checkout override steps
706 var payload = result.payload || {};
708 if(result.textcode == 'NO_SESSION') {
710 return this.logoutStaff();
712 } else if(result.textcode == 'SUCCESS') {
714 if(action == 'checkout') {
716 displayText = dojo.string.substitute(localeStrings.CHECKOUT_SUCCESS, [item]);
717 this.displayCheckout(result, 'checkout');
719 if(payload.holds_fulfilled && payload.holds_fulfilled.length) {
720 // A hold was fulfilled, update the hold numbers in the circ summary
721 console.log("fulfilled hold " + payload.holds_fulfilled + " during checkout");
722 this.holdsSummary = null;
723 this.updateHoldsSummary();
726 this.updateCircSummary(true);
728 } else if(action == 'renew') {
730 displayText = dojo.string.substitute(localeStrings.RENEW_SUCCESS, [item]);
731 this.displayCheckout(result, 'renew');
734 this.checkouts.push({circ : result.payload.circ.id()});
735 sound = 'checkout-success';
736 this.updateScanBox();
738 } else if(result.textcode == 'OPEN_CIRCULATION_EXISTS' && action == 'checkout') {
740 // Server says the item is already checked out. If it's checked out to the
741 // current user, we may need to renew it.
743 if(payload.old_circ) {
746 old_circ refers to the previous checkout IFF it's for the same user.
747 If no auto-renew interval is not defined, assume we should renew it
748 If an auto-renew interval is defined and the payload comes back with
749 auto_renew set to true, do the renewal. Otherwise, let the patron know
750 the item is already checked out to them. */
752 if( !this.orgSettings[SET_AUTO_RENEW_INTERVAL] ||
753 (this.orgSettings[SET_AUTO_RENEW_INTERVAL] && payload.auto_renew) ) {
754 this.prevCirc = payload.old_circ.id();
755 return { renew : true };
759 sound = 'checkout-failure';
760 displayText = dojo.string.substitute(localeStrings.ALREADY_OUT, [item]);
764 // item is checked out to some other user
766 sound = 'checkout-failure';
767 displayText = dojo.string.substitute(localeStrings.OPEN_CIRCULATION_EXISTS, [item]);
770 this.updateScanBox({select:true});
774 var overrideEvents = this.orgSettings[SET_AUTO_OVERRIDE_EVENTS];
776 if(overrideEvents && overrideEvents.length) {
778 // see if the events we received are all in the list of
779 // events to override
781 if(!result.length) result = [result];
784 for(var i = 0; i < result.length; i++) {
785 var match = overrideEvents.filter(
786 function(e) { return (e == result[i].textcode); })[0];
794 return { override : true };
797 this.updateScanBox({select : true});
799 sound = 'checkout-failure';
801 if(action == 'renew')
802 this.checkouts.push({circ : this.prevCirc, renewal_failure : true});
807 switch(result.textcode) {
809 // TODO custom handler for blocking penalties
811 case 'MAX_RENEWALS_REACHED' :
812 displayText = dojo.string.substitute(
813 localeStrings.MAX_RENEWALS, [item]);
816 case 'ITEM_NOT_CATALOGED' :
817 displayText = dojo.string.substitute(
818 localeStrings.ITEM_NOT_CATALOGED, [item]);
821 case 'OPEN_CIRCULATION_EXISTS' :
822 displayText = dojo.string.substitute(
823 localeStrings.OPEN_CIRCULATION_EXISTS, [item]);
827 console.error('Unhandled event ' + result.textcode);
829 if(action == 'checkout' || action == 'renew') {
830 displayText = dojo.string.substitute(
831 localeStrings.GENERIC_CIRC_FAILURE, [item]);
833 displayText = dojo.string.substitute(
834 localeStrings.UNKNOWN_ERROR, [result.textcode]);
839 this.handleAlert(displayText, popup, sound);
847 SelfCheckManager.prototype.renew = function(barcode, override) {
849 var method = 'open-ils.circ.renew';
850 if(override) method += '.override';
852 console.log("Renewing item " + barcode + " with method " + method);
854 var result = fieldmapper.standardRequest(
855 ['open-ils.circ', method],
858 patron_id : this.patron.id(),
859 copy_barcode : barcode
864 console.log(js2JSON(result));
866 var stat = this.handleXactResult('renew', barcode, result);
869 this.renew(barcode, true);
873 * Display the result of a checkout or renewal in the items out table
875 SelfCheckManager.prototype.displayCheckout = function(evt, type, itemsOut) {
877 var copy = evt.payload.copy;
878 var record = evt.payload.record;
879 var circ = evt.payload.circ;
880 var row = this.circTemplate.cloneNode(true);
883 this.byName(row, 'jacket').setAttribute('src', '/opac/extras/ac/jacket/small/' + record.isbn());
886 this.byName(row, 'barcode').innerHTML = copy.barcode();
887 this.byName(row, 'title').innerHTML = record.title();
888 this.byName(row, 'author').innerHTML = record.author();
889 this.byName(row, 'remaining').innerHTML = circ.renewal_remaining();
890 openils.Util.show(this.byName(row, type));
892 var date = dojo.date.stamp.fromISOString(circ.due_date());
893 this.byName(row, 'due_date').innerHTML =
894 dojo.date.locale.format(date, {selector : 'date'});
896 // put new circs at the top of the list
897 var tbody = this.circTbody;
898 if(itemsOut) tbody = this.itemsOutTbody;
899 tbody.insertBefore(row, tbody.getElementsByTagName('tr')[0]);
903 SelfCheckManager.prototype.byName = function(node, name) {
904 return dojo.query('[name=' + name+']', node)[0];
908 SelfCheckManager.prototype.initPrinter = function() {
909 try { // Mozilla only
910 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
911 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
912 netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesRead');
913 netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesWrite');
914 var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
916 pref.setBoolPref('print.always_print_silent', true);
918 console.log("Unable to initialize auto-printing");
923 * Print a receipt for this session's checkouts
925 SelfCheckManager.prototype.printSessionReceipt = function(callback) {
928 var circCtx = []; // circ context data. in this case, renewal_failure info
930 // collect the circs and failure info
934 circIds.push(blob.circ);
935 circCtx.push({renewal_failure:blob.renewal_failure});
943 'format.selfcheck.checkout',
950 fieldmapper.standardRequest(
951 ['open-ils.circ', 'open-ils.circ.fire_circ_trigger_events'],
955 oncomplete : function(r) {
956 var resp = openils.Util.readResponse(r);
957 var output = resp.template_output();
959 self.printData(output.data(), self.checkouts.length, callback);
961 var error = resp.error_output();
963 throw new Error("Error creating receipt: " + error.data());
965 throw new Error("No receipt data returned from server");
973 SelfCheckManager.prototype.printData = function(data, numItems, callback) {
975 var win = window.open('', '', 'resizable,width=700,height=500,scrollbars=1');
976 win.document.body.innerHTML = data;
980 * There is no way to know when the browser is done printing.
981 * Make a best guess at when to close the print window by basing
982 * the setTimeout wait on the number of items to be printed plus
985 var sleepTime = 1000;
987 sleepTime += (numItems / 2) * 1000;
991 win.close(); // close the print window
993 callback(); // fire optional post-print callback
1001 * Print a receipt for this user's items out
1003 SelfCheckManager.prototype.printItemsOutReceipt = function(callback) {
1005 if(!this.itemsOut.length) return;
1007 progressDialog.show(true);
1013 'format.selfcheck.items_out',
1019 fieldmapper.standardRequest(
1020 ['open-ils.circ', 'open-ils.circ.fire_circ_trigger_events'],
1024 oncomplete : function(r) {
1025 progressDialog.hide();
1026 var resp = openils.Util.readResponse(r);
1027 var output = resp.template_output();
1029 self.printData(output.data(), self.itemsOut.length, callback);
1031 var error = resp.error_output();
1033 throw new Error("Error creating receipt: " + error.data());
1035 throw new Error("No receipt data returned from server");
1044 * Print a receipt for this user's items out
1046 SelfCheckManager.prototype.printHoldsReceipt = function(callback) {
1048 if(!this.holds.length) return;
1050 progressDialog.show(true);
1055 dojo.forEach(this.holds,
1057 holdIds.push(data.hold.id());
1058 if(data.status == 4) {
1059 holdData.push({ready : true});
1062 queue_position : data.queue_position,
1063 potential_copies : data.potential_copies
1073 'format.selfcheck.holds',
1080 fieldmapper.standardRequest(
1081 ['open-ils.circ', 'open-ils.circ.fire_hold_trigger_events'],
1085 oncomplete : function(r) {
1086 progressDialog.hide();
1087 var resp = openils.Util.readResponse(r);
1088 var output = resp.template_output();
1090 self.printData(output.data(), self.holds.length, callback);
1092 var error = resp.error_output();
1094 throw new Error("Error creating receipt: " + error.data());
1096 throw new Error("No receipt data returned from server");
1108 * Logout the patron and return to the login page
1110 SelfCheckManager.prototype.logoutPatron = function(print) {
1111 if(print && this.checkouts.length) {
1112 this.printSessionReceipt(
1114 location.href = location.href;
1118 location.href = location.href;
1124 * Fire up the manager on page load
1126 openils.Util.addOnLoad(
1128 new SelfCheckManager().init();