1 /* The code in this file relies on common.js */
3 dojo.require("dojo.cookie");
4 dojo.require("openils.Util");
5 dojo.require("openils.User");
6 dojo.require("openils.CGI");
7 dojo.require("openils.XUL");
8 dojo.require("openils.PermaCrud");
10 JSAN.use("util.error");
11 var _error = new util.error();
14 function _generic_onmethoderror(r, stat, stat_text) {
15 _error.standard_unexpected_error_alert(
16 dojo.byId("commonStrings").getString("common.error"),
17 stat + ":" + stat_text
23 return dojo.byId("serialStrings").getString("batch_receive." + k).
28 return dojo.byId("serialStrings").
29 getFormattedString("batch_receive." + k, args).replace("\\n", "\n");
32 function BatchReceiver() {
35 this.init = function(authtoken, bib_id, sub_id) {
37 this.user = new openils.User({"authtoken": authtoken});
38 this.pcrud = new openils.PermaCrud({"authtoken": authtoken});
39 this.authtoken = authtoken;
42 hide("batch_receive_sub");
43 hide("batch_receive_entry");
44 hide("batch_receive_bibdata_bits");
45 hide("batch_receive_sub_bits");
46 hide("batch_receive_issuance_bits");
47 hide("batch_receive_issuance");
49 dojo.byId("bib_lookup_submit").disabled = false;
50 dojo.byId("bib_search_term").value = "";
53 show("batch_receive_bib");
54 dojo.byId("bib_search_term").focus();
57 if (!this.entry_tbody) {
58 this.entry_tbody = dojo.byId("entry_tbody");
59 this.template = this.entry_tbody.removeChild(
60 dojo.byId("entry_template")
64 this._clear_entry_batch_row();
66 this._call_number_cache = null;
67 this._prepared_call_number_controls = {};
68 this._location_by_lib = {};
69 this._copy_template_cache = {};
70 this._wants_print_routing = {};
72 /* empty the entry receiving table if we're starting over */
73 if (this.item_cache) {
74 for (var id in this.item_cache) {
75 this.finish_receipt(this.item_cache[id]);
76 hard_empty(this.entry_tbody);
78 /* XXX incredibly, running hard_empty() more than once seems to be
79 * good and necessary. There's a bug under the covers somewhere,
80 * but this keeps it out of sight for the moment. */
81 hard_empty(this.entry_tbody);
83 hard_empty(this.entry_tbody);
89 this.bib_lookup(bib_id, null, true, sub_id);
94 this._clear_entry_batch_row = function() {
96 dojo.byId("entry_batch_row").childNodes,
98 if (node.nodeType == 1 &&
99 node.getAttribute("name") != "barcode")
105 this._show_bibdata_bits = function() {
106 hard_empty("title_here");
107 dojo.byId("title_here").appendChild(T(this.bibdata.mvr.title()));
108 hard_empty("author_here");
110 if (this.bibdata.mvr.author()) {
111 dojo.byId("author_here").appendChild(T(this.bibdata.mvr.author()));
112 show("author_here_holder");
114 hide("author_here_holder");
117 show("batch_receive_bibdata_bits");
120 this._sub_label = function(sub) {
121 /* XXX use a formatting string from serial.properties */
122 return sub.id() + ": (" + sub.owning_lib().shortname() + ") " +
123 D(sub.start_date()) + " - " + D(sub.end_date());
126 this._show_sub_bits = function() {
127 hard_empty("sublabel_here");
129 T(this._sub_label(this.sub)),
133 hide("batch_receive_sub");
134 show("batch_receive_sub_bits");
137 this._show_issuance_bits = function() {
138 hide("batch_receive_issuance");
139 hard_empty("issuance_label_here");
141 T(this.issuance.label()),
142 "issuance_label_here",
145 show("batch_receive_issuance_bits");
148 this._get_receivable_issuances = function() {
153 fieldmapper.standardRequest(
154 ["open-ils.serial", "open-ils.serial.issuances.receivable"], {
155 "params": [this.authtoken, this.sub.id()],
157 "onresponse": function(r) {
158 if (r = openils.Util.readResponse(r))
161 "onmethoderror": _generic_onmethoderror
172 this._build_circ_modifier_dropdown = function() {
173 if (!this._built_circ_modifier_dropdown) {
174 var menulist = dojo.create("menulist");
175 var menupopup = dojo.create("menupopup", null, menulist, "only");
177 "menuitem", {"value": 0, "label": S("none")},
182 fieldmapper.standardRequest(
183 ["open-ils.circ", "open-ils.circ.circ_modifier.retrieve.all"],{
184 "params": [{"full": true}],
186 "onresponse": function(r) {
187 if (mods = openils.Util.readResponse(r)) {
190 return a.code() > b.code() ? 1 :
191 b.code() > a.code() ? -1 :
199 "label": document.getElementById('commonStrings').getFormattedString('staff.circ_modifier.display',[mod.code(),mod.name(),mod.description()])
206 "onmethoderror": _generic_onmethoderror
210 /* in this case, discard menulist and menupopup */
211 this._built_circ_modifier_dropdown =
212 dojo.create("description", {"value": "-"});
214 this._built_circ_modifier_dropdown = menulist;
218 return dojo.clone(this._built_circ_modifier_dropdown);
221 this._extend_circ_modifier_for_batch = function(control) {
223 "menuitem", {"value": -1, "label": "---"},
224 dojo.query("menupopup", control)[0],
231 this._build_location_dropdown = function(locs, add_unset_value) {
232 var menulist = dojo.create("menulist");
233 var menupopup = dojo.create("menupopup", null, menulist, "only");
235 if (add_unset_value) {
237 "menuitem", {"value": -1, "label": "---"}, menupopup, "first"
245 "value": loc.id(), "label": loc.name()
254 this._get_locations_for_lib = function(lib) {
255 if (!this._location_by_lib[lib]) {
256 fieldmapper.standardRequest(
257 ["open-ils.circ", "open-ils.circ.copy_location.retrieve.all"],{
258 "params": [lib, false, true],
260 "onresponse": function(r) {
261 if (locs = openils.Util.readResponse(r))
262 self._location_by_lib[lib] = locs;
264 "onmethoderror": _generic_onmethoderror
269 return this._location_by_lib[lib];
272 this._build_call_number_control = function(item) {
273 /* In any case, give a dropdown of call numbers related to the
274 * same bre as the subscription relates to. */
275 if (!this._call_number_cache) {
276 this._call_number_cache = this.pcrud.search(
278 "record": this.sub.record_entry()
280 "order_by": {"acn": "label"}, /* XXX wrong sorting? */
285 if (typeof item == "undefined") {
286 /* In this case, no further limiting of call numbers for now,
287 * although ideally it might be nice to limit to call numbers
288 * with owning_lib matching the holding_lib of the distribs
289 * that ultimately relate to the items. */
291 var menulist = dojo.create("menulist", {
292 "editable": "true", "className": "cn"
294 var menupopup = dojo.create("menupopup", null, menulist, "only");
296 openils.Util.uniqueObjects(this._call_number_cache, "label").
301 "value": cn.label(), "label": cn.label()
309 /* In this case, limit call numbers by owning_lib matching
310 * distributions's holding_lib. */
312 var lib = item.stream().distribution().holding_lib().id();
313 if (!this._prepared_call_number_controls[lib]) {
314 var menulist = dojo.create("menulist", {
315 "editable": "true", "className": "cn"
317 var menupopup = dojo.create("menupopup", null, menulist,"only");
318 this._call_number_cache.filter(
319 function(cn) { return cn.owning_lib() == lib; }
324 "value": cn.label(), "label": cn.label()
329 this._prepared_call_number_controls[lib] = menulist;
331 return dojo.clone(this._prepared_call_number_controls[lib]);
335 this._build_batch_location_dropdown = function() {
336 var menulist = dojo.create("menulist");
337 var menupopup = dojo.create("menupopup",null,menulist);
338 dojo.create("menuitem", {"value": -1, "label": "---"}, menupopup);
340 fieldmapper.standardRequest(
342 "open-ils.circ.copy_location.retrieve.distinct.atomic"],{
345 "onresponse": function(r) {
346 if (list = openils.Util.readResponse(r)) {
351 "value": locname, "label": locname
358 "onmethoderror": _generic_onmethoderror
365 this._build_print_routing_toggle = function(item) {
367 var checkbox = dojo.create(
369 "oncommand": function(ev) {
370 self._print_routing(item.id(), ev.target.checked);
372 "checked": start.toString()
375 this._print_routing(item.id(), start);
379 this._build_receive_toggle = function(item) {
382 "oncommand": function(ev) {
383 self._disable_row(item.id(), !ev.target.checked);
386 "name": "receive_" + item.id()
391 this._disable_row = function(item_id, disabled) {
392 var row = this.rows[item_id];
394 "textbox,menulist,checkbox:not([name^='receive_'])", row
396 function(element) { element.disabled = disabled; }
398 this._row_disabled(row, disabled);
401 this._row_disabled = function(row, disabled) {
402 if (typeof(row) == "string") row = this.rows[row];
404 var checkbox = dojo.query("checkbox", row)[1];
406 if (typeof(disabled) != "undefined")
407 checkbox.checked = !disabled;
409 return !checkbox.checked;
412 this._row_print_routing_disabled = function(row, disabled) {
413 if (typeof(row) == "string") row = this.rows[row];
415 var checkbox = dojo.query("checkbox", row)[0];
417 if (typeof(disabled) != "undefined") {
418 checkbox.checked = !disabled;
419 checkbox.doCommand();
422 return !checkbox.checked;
425 this._row_field_value = function(row, field, value) {
426 if (typeof(row) == "string") row = this.rows[row];
428 var node = dojo.query("*", node_by_name(field, row))[0];
430 if (typeof(value) == "undefined") {
433 /* XXX The new two lines /should/ each do the same thing, but
434 * apparently they don't. With only one or the other, I get
435 * skipped fields when this is called by the code that
436 * pre-populates fields based on copy templates. This may
437 * have something to do with Dojo and XUL not getting along
439 dojo.attr(node, "value", value);
444 this._print_routing = function(id, value) {
445 this._wants_print_routing[id] = value;
448 this._user_wants_autogen = function() {
449 return dojo.byId("autogen_barcodes").checked;
452 this._get_autogen_potentials = function(item_id) {
453 var hit_a_wall = false;
455 return [openils.Util.objectProperties(this.rows).sort(num_sort).filter(
459 } else if (id <= item_id || self._row_disabled(id)) {
461 } else if (self._row_field_value(id, "barcode")) {
471 this._prepare_autogen_control = function() {
472 dojo.attr("autogen_barcodes",
473 "command", function(ev) {
474 if (!ev.target.checked) {
475 var list = self._have_autogen_barcodes();
476 if (list.length && confirm(S("autogen_barcodes.remove"))) {
479 self._row_field_value(id, "barcode", "");
480 self.rows[id]._has_autogen_barcode = false;
489 this._have_autogen_barcodes = function() {
491 for (var id in this.rows)
492 if (this.rows[id]._has_autogen_barcode) list.push(id);
496 this._cn_exists_but_not_for_lib = function(lib, value) {
497 var exists = this._call_number_cache.filter(
498 function(cn) { return cn.label() == value }
500 var for_lib = exists.filter(
501 function(cn) { return cn.owning_lib() == lib; }
503 return (exists.length && !for_lib.length);
506 this._call_number_confirm_for_lib = function(lib, value) {
507 if (!this._has_confirmed_cn_for)
508 this._has_confirmed_cn_for = {};
510 if (typeof(this._has_confirmed_cn_for[lib.id()]) == "undefined") {
511 if (this._cn_exists_but_not_for_lib(lib.id(), value)) {
512 this._has_confirmed_cn_for[lib.id()] = confirm(
513 F("cn_for_lib", [lib.shortname()])
516 this._has_confirmed_cn_for[lib.id()] = true;
520 return this._has_confirmed_cn_for[lib.id()];
523 this._confirm_row_field_application = function(id, key, value) {
524 if (key == "call_number") { /* XXX make a dispatch table so we can do
525 this for other fields too */
526 return this._call_number_confirm_for_lib(
527 this.item_cache[id].stream().distribution().holding_lib(),
535 this._location_by_name = function(id, value) {
536 var lib = this.item_cache[id].stream().distribution().
538 var winners = this._location_by_lib[lib].filter(
539 function(loc) { return loc.name() == value; }
541 if (winners.length) {
542 return winners[0].id();
548 this._set_all_enabled_rows = function(key, value) {
549 /* do NOT do trimming here, set whitespace as is. */
550 for (var id in this.rows) {
551 if (!this._row_disabled(id)) {
552 if (this._confirm_row_field_application(id, key, value)) {
553 if (key == "location") /* kludge for this field */ {
554 if (actual = this._location_by_name(id, value))
555 this._row_field_value(id, key, actual);
557 this._row_field_value(id, key, value);
564 this.print_routing_lists = function(streams) {
565 fieldmapper.standardRequest(
567 "open-ils.serial.routing_list_users.fleshed_and_ordered.atomic"],{
569 this.authtoken, streams.map(function(o) { return o.id(); })
572 "oncomplete": function(r) {
573 if ((r = openils.Util.readResponse(r)) && r.length) {
574 openils.XUL.newTabEasy(
575 "SERIAL_PRINT_ROUTING_LIST_USERS",
576 S("print_routing_list_users"), {
577 "show_print_button": false, /* we supply one */
578 "routing_list_data": {
579 "streams": streams, "mvr": self.bibdata.mvr,
580 "issuance": self.issuance, "users": r
582 }, true /* wrap_in_browser */
586 "onmethoderror": _generic_onmethoderror
591 this.bib_lookup = function(bib_search_term, evt, is_actual_id, sub_id) {
592 if (evt && evt.keyCode != 13) return;
594 if (!bib_search_term) {
595 var bib_search_term = dojo.byId("bib_search_term").value.trim();
596 if (!bib_search_term.length) {
597 alert(S("bib_lookup.empty"));
602 hide("batch_receive_sub");
603 hide("batch_receive_entry");
606 dojo.byId("bib_lookup_submit").disabled = true;
607 fieldmapper.standardRequest(
609 "open-ils.serial.biblio.record_entry.by_identifier.atomic"], {
612 "require_subscriptions": true,
614 "is_actual_id": is_actual_id
618 "oncomplete": function(r) {
619 /* These two things better come before readResponse(),
620 * which can throw exceptions. */
622 dojo.byId("bib_lookup_submit").disabled = false;
624 var list = openils.Util.readResponse(r, false, true);
625 if (list && list.length) {
626 if (list.length > 1) {
627 /* XXX TODO just let the user pick one from a list,
628 * although this circumstance seems really
629 * unlikely. It just can't happen for TCN, and
630 * wouldn't be likely for ISxN or UPC... ? */
631 alert(S("bib_lookup.multiple"));
633 self.bibdata = list[0];
634 self._show_bibdata_bits();
635 self.choose_subscription(sub_id);
638 alert(S("bib_lookup.not_found"));
642 dojo.byId("bib_search_term").reset();
643 dojo.byId("bib_search_term").focus();
647 "onmethoderror": _generic_onmethoderror
652 this.choose_subscription = function(sub_id) {
653 hide("batch_receive_bib");
654 hide("batch_receive_entry");
655 hide("batch_receive_sub_bits");
656 hide("batch_receive_issuance");
658 var subs = this.bibdata.bre.subscriptions();
661 this.choose_issuance(
662 subs.filter(function(o) { return o.id() == sub_id; })[0]
664 } else if (subs.length > 1) {
665 var menulist = dojo.create("menulist", {"id": "sub_chooser"});
666 var menupopup = dojo.create("menupopup", {}, menulist, "only");
668 this.bibdata.bre.subscriptions().forEach(
672 "label": self._sub_label(sub),
679 hard_empty(dojo.byId("sub_chooser_here"));
681 dojo.place(menulist, dojo.byId("sub_chooser_here"), "only");
682 show("batch_receive_sub");
684 this.choose_issuance(subs[0]);
688 this.choose_issuance = function(sub) {
689 hide("batch_receive_bib");
690 hide("batch_receive_entry");
691 hide("batch_receive_sub");
693 if (typeof(sub) == "undefined") { /* sub chosen from menu */
694 var sub_id = dojo.byId("sub_chooser").value;
695 this.sub = this.bibdata.bre.subscriptions().filter(
696 function(o) { return o.id() == sub_id; }
698 } else { /* only one sub possible, passed in directly */
702 this._show_sub_bits();
704 this.issuances = this._get_receivable_issuances(); /* sync */
706 if (this.issuances.length > 1) {
707 var menulist = dojo.create("menulist", {"id": "issuance_chooser"});
708 var menupopup = dojo.create("menupopup", {}, menulist, "only");
712 if (a.date_published()>b.date_published()) return 1;
713 else if (b.date_published()>a.date_published()) return -1;
720 "label": issuance.label(),
721 "value": issuance.id()
727 hard_empty("issuance_chooser_here");
728 dojo.place(menulist, dojo.byId("issuance_chooser_here"), "only");
730 show("batch_receive_issuance");
731 } else if (this.issuances.length) {
732 this.load_entry_form(this.issuances[0]);
734 alert(S("issuance_lookup.none"));
740 this._update_copy_template_cache = function() {
741 var templates_needed = openils.Util.uniqueElements(
742 openils.Util.objectProperties(this.item_cache).map(
744 return self.item_cache[id].stream().distribution().
745 receive_unit_template();
749 function(id) { return !self._copy_template_cache[id]; }
752 if (templates_needed.length) {
753 this.pcrud.search("act", {"id": templates_needed}).forEach(
755 self._copy_template_cache[tmpl.id()] = tmpl;
761 this.apply_copy_templates = function() {
762 this._update_copy_template_cache(); /* sync */
764 for (var id in this.item_cache) {
765 var item = this.item_cache[id];
767 item.stream().distribution().receive_unit_template();
768 var template = this._copy_template_cache[template_id];
770 var row = this.rows[id];
772 var tmpl_mod = template.circ_modifier();
773 var tmpl_loc = template.location();
774 var tmpl_price = template.price();
775 if (tmpl_mod != null) {
776 this._row_field_value(
777 row, "circ_modifier", tmpl_mod == "" ? 0 : tmpl_mod
781 this._row_field_value(row, "location", tmpl_loc);
783 this._row_field_value(row, "price", tmpl_price);
787 this.load_entry_form = function(issuance) {
788 if (typeof(issuance) == "undefined") {
789 var issuance_id = dojo.byId("issuance_chooser").value;
790 this.issuance = this.issuances.filter(
791 function(o) { return o.id() == issuance_id; }
794 this.issuance = issuance;
797 this._show_issuance_bits();
798 this._prepare_autogen_control();
802 fieldmapper.standardRequest(
804 "open-ils.serial.items.receivable.by_issuance.atomic"], {
805 "params": [this.authtoken, this.issuance.id()],
807 "onresponse": function(r) {
810 if (list = openils.Util.readResponse(r, false, true)) {
815 list.forEach(function(o) {self.add_entry_row(o);});
817 self.build_batch_entry_row();
819 var recv_with_units =
820 dojo.byId("batch_receive_with_units");
821 recv_with_units.doCommand();
822 if (recv_with_units.checked)
823 self.apply_copy_templates();
825 show("batch_receive_entry");
828 alert(S("item_lookup.none"));
829 if (self.issuances.length) self.choose_issuance();
834 "onmethoderror": _generic_onmethoderror
839 this.toggle_receive_with_units = function(ev) {
840 var head_row = dojo.byId("batch_receive_entry_thead");
841 var batch_row = dojo.byId("entry_batch_row");
844 "barcode", "call_number", "price", "location", "circ_modifier"
847 var table_cell_func = ev.target.checked ?
848 show_table_cell : hide_table_cell;
851 if (batch_row) table_cell_func(node_by_name(key, batch_row));
852 if (head_row) table_cell_func(node_by_name(key, head_row));
854 for (var id in self.rows) {
855 table_cell_func(node_by_name(key, self.rows[id]));
860 if (!ev.target.checked) {
861 /* XXX As of the time of this writing, a blank barcode field will
862 * avoid unit creation */
863 this._set_all_enabled_rows("barcode", "");
867 this.toggle_all_receive = function(checked) {
868 for (var id in this.rows) {
869 this._disable_row(id, !checked);
873 this.toggle_all_print_routing = function(checked) {
874 for (var id in this.rows) {
875 this._row_print_routing_disabled(id, !checked);
879 this.build_batch_entry_row = function() {
880 var row = dojo.byId("entry_batch_row");
882 this.batch_controls = {};
884 node_by_name("note", row).appendChild(
885 this.batch_controls.note = dojo.create("textbox", {"size": 20})
888 node_by_name("location", row).appendChild(
889 this.batch_controls.location =
890 this._build_batch_location_dropdown()
893 node_by_name("circ_modifier", row).appendChild(
894 this.batch_controls.circ_modifier =
895 this._extend_circ_modifier_for_batch(
896 this._build_circ_modifier_dropdown() /* for all OUs */
900 node_by_name("call_number", row).appendChild(
901 this.batch_controls.call_number = this._build_call_number_control()
904 node_by_name("price", row).appendChild(
905 this.batch_controls.price = dojo.create("textbox", {"size": 9})
908 node_by_name("print_routing", row).appendChild(
911 "oncommand": function(ev) {
912 self.toggle_all_print_routing(ev.target.checked);
919 node_by_name("receive", row).appendChild(
922 "oncommand": function(ev) {
923 self.toggle_all_receive(ev.target.checked);
930 node_by_name("apply", row).appendChild(
931 dojo.create("button", {
933 "oncommand": function() { self.apply_batch_values(); }
938 this.apply_batch_values = function() {
939 var row = dojo.byId("entry_batch_row");
941 for (var key in this.batch_controls) {
942 var value = this.batch_controls[key].value;
943 if (value != "" && value != -1)
944 this._set_all_enabled_rows(key, value);
947 /* XXX genericize for all fields? */
948 delete this._has_confirmed_cn_for;
951 this.add_entry_row = function(item) {
952 this.item_cache[item.id()] = item;
953 var row = this.rows[item.id()] = dojo.clone(this.template);
955 function n(s) { return node_by_name(s, row); } /* typing saver */
957 var stream_dist_label = item.stream().distribution().label();
958 if (item.stream().routing_label())
959 stream_dist_label += " / " + item.stream().routing_label();
961 n("holding_lib").appendChild(
964 "value": item.stream().distribution().
965 holding_lib().shortname(),
966 "tooltiptext": stream_dist_label
971 n("barcode").appendChild(
975 "tabindex": 10000 + Number(item.id()), /* is this right? */
976 "onchange": function() {
977 self.autogen_if_appropriate(this, item.id());
983 n("location").appendChild(
984 this._build_location_dropdown(
985 this._get_locations_for_lib(
986 item.stream().distribution().holding_lib().id()
991 n("note").appendChild(dojo.create("textbox", {"size": 20}));
992 n("circ_modifier").appendChild(this._build_circ_modifier_dropdown());
993 n("call_number").appendChild(this._build_call_number_control(item));
994 n("price").appendChild(dojo.create("textbox", {"size": 9}));
995 n("print_routing").appendChild(this._build_print_routing_toggle(item));
996 n("receive").appendChild(this._build_receive_toggle(item));
998 this.entry_tbody.appendChild(row);
1001 this.receive = function() {
1003 var confirmed_missing_units = false;
1005 for (var id in this.rows) {
1006 if (this._row_disabled(id))
1009 var item = this.item_cache[id];
1011 /* Don't trim() call_number field, as existing call numbers
1012 * are yielded by their label field, not by id, and if
1013 * they start or end in spaces, we'll unintentionally create
1014 * a new, different CN if we trim that */
1015 var cn_string = this._row_field_value(id, "call_number");
1016 var barcode = this._row_field_value(id, "barcode");
1017 if (barcode && barcode.trim) barcode = barcode.trim();
1019 if (barcode && cn_string.length) {
1020 var unit = new sunit();
1021 unit.barcode(barcode);
1023 ["price", "location", "circ_modifier"].forEach(
1025 var value = self._row_field_value(id, field);
1027 unit[field](value.trim ? value.trim() : value);
1031 unit.call_number(cn_string);
1033 } else if (barcode && !cn_string.length) {
1034 alert(S("missing_cn"));
1036 } else if (!confirmed_missing_units) {
1038 (!dojo.byId("batch_receive_with_units").checked) ||
1039 confirm(S("missing_units"))
1041 confirmed_missing_units = true;
1047 var note_value = this._row_field_value(id, "note").trim();
1049 var note = new sin();
1052 note.title(S("receive_time_note"));
1053 note.value(note_value);
1062 fieldmapper.standardRequest(
1063 ["open-ils.serial", "open-ils.serial.receive_items.one_unit_per"],{
1064 "params": [this.authtoken, items, this.sub.record_entry()],
1066 "oncomplete": function(r) {
1068 var streams_for_printing = [];
1069 while (item_id = openils.Util.readResponse(r)) {
1070 if (self._wants_print_routing[item_id]) {
1071 streams_for_printing.push(
1072 self.item_cache[item_id].stream()
1075 self.finish_receipt(item_id);
1077 if (streams_for_printing.length)
1078 self.print_routing_lists(streams_for_printing);
1086 (dump ? dump : console.log)(E);
1089 "onmethoderror": _generic_onmethoderror
1094 this.finish_receipt = function(item_id) {
1095 hard_empty(this.rows[item_id]);
1096 dojo.destroy(this.rows[item_id]);
1097 delete this.rows[item_id];
1098 delete this.item_cache[item_id];
1101 this.autogen_if_appropriate = function(textbox, item_id) {
1102 if (this._user_wants_autogen() && textbox.value) {
1103 var kvlist = this._get_autogen_potentials(item_id);
1104 var list = kvlist[0];
1105 var question = kvlist[1];
1107 if (question && !confirm(S("autogen_barcodes.questionable")))
1112 fieldmapper.standardRequest(
1113 ["open-ils.cat", "open-ils.cat.item.barcode.autogen"], {
1115 this.authtoken, textbox.value, list.length
1118 "onresponse": function(r) {
1119 r = openils.Util.readResponse(r, false, true);
1121 for (var i = 0; i < r.length; i++) {
1122 var row = self.rows[list[i]];
1123 self._row_field_value(
1124 row, "barcode", r[i]
1126 row._has_autogen_barcode = true;
1130 "onmethoderror": _generic_onmethoderror
1137 } /* do nothing for empty list */
1141 this.init.apply(this, arguments);
1144 function my_init() {
1145 var cgi = new openils.CGI();
1146 var authtoken = (typeof ses == "function" ? ses() : 0) ||
1147 cgi.param("ses") || dojo.cookie("ses");
1148 if(!authtoken && openils.XUL.isXUL()) {
1149 var stash = openils.XUL.getStash();
1150 authtoken = stash.session.key;
1152 batch_receiver = new BatchReceiver(
1154 cgi.param("docid") || null, cgi.param("subid") || null