1 dojo.require('dojo.date.locale');
2 dojo.require('dojo.date.stamp');
3 dojo.require('dijit.form.Button');
4 dojo.require('dijit.form.TextBox');
5 dojo.require('dijit.form.FilteringSelect');
6 dojo.require('dijit.form.Textarea');
7 dojo.require('dijit.Tooltip');
8 dojo.require('dijit.ProgressBar');
9 dojo.require('openils.User');
10 dojo.require('openils.Util');
11 dojo.require('openils.acq.Lineitem');
12 dojo.require('openils.acq.PO');
13 dojo.require('openils.acq.Picklist');
14 dojo.require('openils.widget.AutoFieldWidget');
15 dojo.require('dojo.data.ItemFileReadStore');
16 dojo.require('openils.widget.ProgressDialog');
17 dojo.require('openils.PermaCrud');
18 dojo.require('openils.XUL');
20 dojo.requireLocalization('openils.acq', 'acq');
21 var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
22 const XUL_OPAC_WRAPPER = 'chrome://open_ils_staff_client/content/cat/opac.xul';
23 var li_exportable_attrs = ["issn", "isbn", "upc"];
25 function nodeByName(name, context) {
26 return dojo.query('[name='+name+']', context)[0];
30 var liDetailBatchFields = ['fund', 'owning_lib', 'location', 'collection_code', 'circ_modifier', 'cn_label'];
31 var liDetailFields = liDetailBatchFields.concat(['barcode', 'note']);
33 function AcqLiTable() {
39 this.realDfaCache = {};
40 this.virtDfaCounts = {};
43 this.toggleState = false;
44 this.tbody = dojo.byId('acq-lit-tbody');
47 this.authtoken = openils.User.authtoken;
48 this.pcrud = new openils.PermaCrud();
49 this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
50 this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
51 this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
52 this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
53 this.copyBatchWidgets = {};
54 this.liNotesTbody = dojo.byId('acq-lit-notes-tbody');
55 this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row'));
56 this.realCopiesTbody = dojo.byId('acq-lit-real-copies-tbody');
57 this.realCopiesRow = this.realCopiesTbody.removeChild(dojo.byId('acq-lit-real-copies-row'));
58 this._copy_fields_for_acqdf = ['owning_lib', 'location'];
60 dojo.connect(acqLitLiActionsSelector, 'onChange',
62 self.applySelectedLiAction(this.attr('value'))
63 acqLitLiActionsSelector.attr('value', '_');
66 acqLitCreatePoSubmit.onClick = function() {
67 acqLitPoCreateDialog.hide();
68 self._createPO(acqLitPoCreateDialog.getValues());
71 acqLitSavePlButton.onClick = function() {
72 acqLitSavePlDialog.hide();
73 self._savePl(acqLitSavePlDialog.getValues());
76 acqLitCancelLiStateButton.onClick = function() {
77 acqLitChangeLiStateDialog.hide();
79 acqLitSaveLiStateButton.onClick = function() {
80 acqLitChangeLiStateDialog.hide();
81 self._updateLiState(acqLitChangeLiStateDialog.getValues(), acqLitChangeLiStateDialog.attr('state'));
85 //dojo.byId('acq-lit-notes-new-button').onclick = function(){acqLitCreateLiNoteDialog.show();}
87 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
88 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
89 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
90 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
91 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
93 this.reset = function() {
94 while(self.tbody.childNodes[0])
95 self.tbody.removeChild(self.tbody.childNodes[0]);
100 this.setNext = function(handler) {
101 var link = dojo.byId('acq-lit-next');
103 dojo.style(link, 'visibility', 'visible');
104 link.onclick = handler;
106 dojo.style(link, 'visibility', 'hidden');
110 this.setPrev = function(handler) {
111 var link = dojo.byId('acq-lit-prev');
113 dojo.style(link, 'visibility', 'visible');
114 link.onclick = handler;
116 dojo.style(link, 'visibility', 'hidden');
120 this.show = function(div) {
121 openils.Util.hide('acq-lit-table-div');
122 openils.Util.hide('acq-lit-info-div');
123 openils.Util.hide('acq-lit-li-details');
124 openils.Util.hide('acq-lit-notes-div');
125 openils.Util.hide('acq-lit-real-copies-div');
128 openils.Util.show('acq-lit-table-div');
131 openils.Util.show('acq-lit-info-div');
134 openils.Util.show('acq-lit-li-details');
137 openils.Util.show('acq-lit-real-copies-div');
140 openils.Util.show('acq-lit-notes-div');
144 openils.Util.show(div);
148 this.hide = function() {
152 this.toggleSelect = function() {
154 dojo.forEach(self.selectors, function(i){i.checked = false});
156 dojo.forEach(self.selectors, function(i){i.checked = true});
157 self.toggleState = !self.toggleState;
161 /** @param all If true, assume all are selected */
162 this.getSelected = function(all) {
164 dojo.forEach(self.selectors,
167 selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
173 this.setRowAttr = function(td, liWrapper, field, type) {
174 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
175 td.appendChild(document.createTextNode(val));
179 * Inserts a single lineitem into the growing table of lineitems
180 * @param {Object} li The lineitem object to insert
182 this.addLineitem = function(li, skip_final_placement) {
183 this.liCache[li.id()] = li;
185 // sort the lineitem notes on edit_time
186 if(!li.lineitem_notes()) li.lineitem_notes([]);
188 var liWrapper = new openils.acq.Lineitem({lineitem:li});
189 var row = self.rowTemplate.cloneNode(true);
190 row.setAttribute('li', li.id());
191 var tds = dojo.query('[attr]', row);
192 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
193 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
195 var isbn = liWrapper.findAttr('isbn', 'lineitem_marc_attr_definition');
197 // XXX media prefix for added content
198 dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
201 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
202 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
203 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
205 this.updateLiNotesCount(li, row);
207 // show which PO this lineitem is a member of
208 if(li.purchase_order() && !this.isPO) {
210 this.poCache[li.purchase_order()] =
211 this.poCache[li.purchase_order()] ||
212 fieldmapper.standardRequest(
213 ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
215 this.authtoken, li.purchase_order(), {
216 "flesh_price_summary": true,
217 "flesh_lineitem_count": true
220 if(po && !this.isMeta) {
221 openils.Util.show(nodeByName('po', row), 'inline');
222 var link = nodeByName('po_link', row);
223 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
224 link.innerHTML = 'PO: ' + po.name(); // TODO i18n
228 // show which picklist this lineitem is a member of
229 if(li.picklist() && (this.isPO || this.isMeta)) {
231 this.plCache[li.picklist()] =
232 this.plCache[li.picklist()] ||
233 fieldmapper.standardRequest(
234 ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
235 {params: [this.authtoken, li.picklist()]});
237 openils.Util.show(nodeByName('pl', row), 'inline');
238 var link = nodeByName('pl_link', row);
239 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
240 link.innerHTML = 'PL: '+pl.name(); // TODO i18n
244 var countNode = nodeByName('count', row);
245 var count = li.item_count() || 0;
246 if (typeof(this._copy_count_cb) == "function") {
247 this._copy_count_cb(li.id(), count);
249 countNode.innerHTML = count;
250 countNode.id = 'acq-lit-copy-count-label-' + li.id();
253 nodeByName('li_state', row).innerHTML = li.state(); // TODO i18n state labels
255 var priceInput = dojo.query('[name=price]', row)[0];
256 var priceData = liWrapper.getPrice();
257 priceInput.value = (priceData) ? priceData.price : '';
258 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
260 // show either "mark received" or "unreceive" as appropriate
261 this.updateLiReceivedness(li, row);
263 if (!skip_final_placement) {
264 self.tbody.appendChild(row);
265 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
271 this.updateLiNotesCount = function(li, row) {
272 if (typeof(row) == "undefined")
273 row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
275 var has_notes = (li.lineitem_notes().filter(
276 function(o) { return Boolean (o.alert_text()); }
279 /* U+2691 is the code point for a filled-in flag character */
280 nodeByName("notes_alert_flag", row).innerHTML =
281 has_notes ? "⚑" : "";
282 nodeByName("noteslink", row).style.fontStyle =
283 has_notes ? "italic" : "normal";
284 nodeByName("notes_count", row).innerHTML = li.lineitem_notes().length;
287 this.updateLiReceivedness = function(li, row) {
288 if (typeof(row) == "undefined")
289 row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
291 var recv_link = nodeByName("receive_link", row);
292 var unrecv_link = nodeByName("unreceive_link", row);
293 var real_copies_link = nodeByName("real_copies_link", row);
295 /* handle row coloring for based on LI state */
296 openils.Util.removeCSSClass(row, /^oils-acq-li-state-/);
297 openils.Util.addCSSClass(row, "oils-acq-li-state-" + li.state());
299 /* handle links that appear/disappear based on whether LI is received */
304 openils.Util.hide(real_copies_link);
305 openils.Util.hide(unrecv_link);
306 openils.Util.show(recv_link, "inline");
307 recv_link.onclick = function() {
308 if (self.checkLiAlerts(li.id()))
309 self.issueReceive(li);
313 openils.Util.hide(recv_link);
314 openils.Util.show(unrecv_link, "inline");
315 unrecv_link.onclick = function() {
316 if (confirm(localeStrings.UNRECEIVE_LI))
317 self.issueReceive(li, /* rollback */ true);
319 // TODO we should allow editing before receipt, in which case the
320 // test should be "if 1 or more real (acp) copies exist
321 openils.Util.show(real_copies_link);
322 real_copies_link.onclick = function() {
323 self.showRealCopies(li);
329 openils.Util.hide(recv_link);
330 openils.Util.hide(unrecv_link);
331 openils.Util.hide(real_copies_link);
335 this._setAlertStore = function() {
336 acqLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
338 "data": acqliat.toStoreData(
340 "acqliat", {"id": {"!=": null}}
345 acqLitAlertAlertText.setValue(); /* make the store "live" */
346 acqLitAlertAlertText._store_ready = true;
350 * Draws and shows the lineitem notes pane
352 this.drawLiNotes = function(li) {
355 if (!acqLitAlertAlertText._store_ready)
356 this._setAlertStore();
359 li.lineitem_notes().sort(
361 if(a.edit_time() < b.edit_time()) return 1;
367 while(this.liNotesTbody.childNodes[0])
368 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
371 acqLitCreateLiNoteSubmit.onClick = function() {
372 var value = acqLitCreateNoteText.attr('value');
374 var note = new fieldmapper.acqlin();
377 note.lineitem(li.id());
379 self.updateLiNotes(li, note);
382 acqLitCreateAlertSubmit.onClick = function() {
383 if (!acqLitAlertAlertText.item) {
384 alert(localeStrings.ALERT_UNSELECTED);
388 var alert_text = new fieldmapper.acqliat().fromStoreItem(
389 acqLitAlertAlertText.item
391 var value = acqLitAlertNoteValue.attr("value") || "";
393 var note = new fieldmapper.acqlin();
395 note.lineitem(li.id());
397 note.alert_text(alert_text);
399 self.updateLiNotes(li, note);
402 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
406 * Draws a single lineitem note in the notes pane
408 this.addLiNote = function(li, note) {
409 if(note.isdeleted()) return;
411 var row = self.liNotesRow.cloneNode(true);
412 nodeByName("value", row).innerHTML = note.value();
413 if (note.alert_text())
414 nodeByName("alert_code", row).innerHTML = note.alert_text().code();
416 nodeByName("delete", row).onclick = function() {
417 note.isdeleted(true);
418 self.liNotesTbody.removeChild(row);
419 self.updateLiNotes(li);
422 if(note.edit_time()) {
423 nodeByName("edit_time", row).innerHTML =
424 dojo.date.locale.format(
425 dojo.date.stamp.fromISOString(note.edit_time()),
426 {formatLength:'short'});
429 self.liNotesTbody.appendChild(row);
433 * Updates any new/changed/deleted notes on the server
435 this.updateLiNotes = function(li, newNote) {
441 notes = li.lineitem_notes().filter(
443 if(note.ischanged() || note.isnew() || note.isdeleted())
449 if(notes.length == 0) return;
450 progressDialog.show();
452 fieldmapper.standardRequest(
453 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
455 params : [this.authtoken, notes],
456 onresponse : function(r) {
457 var resp = openils.Util.readResponse(r);
462 // remove the old changed notes
464 dojo.forEach(li.lineitem_notes(),
466 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
470 li.lineitem_notes(list);
473 progressDialog.hide();
474 self.updateLiNotesCount(li);
475 self.drawLiNotes(li);
479 progressDialog.update(resp);
480 var newnote = resp.note;
482 if(!newnote.isdeleted()) {
483 newnote.isnew(false);
484 newnote.ischanged(false);
485 li.lineitem_notes().push(newnote);
492 this.updateLiPrice = function(input, li) {
494 var price = input.value;
495 var liWrapper = new openils.acq.Lineitem({lineitem:li});
496 var oldPrice = liWrapper.getPrice() || null;
498 if(oldPrice) oldPrice = oldPrice.price;
499 if(price == oldPrice) return;
501 fieldmapper.standardRequest(
502 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
504 params : [this.authtoken, li.id(), price],
505 oncomplete : function(r) {
506 openils.Util.readResponse(r);
512 this.removeLineitem = function(liId) {
513 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
514 delete this.liCache[liId];
515 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
518 this.drawInfo = function(liId) {
520 openils.acq.Lineitem.fetchAttrDefs(
522 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
527 this._fetchLineitem = function(liId, handler) {
529 var li = this.liCache[liId];
530 if(li && li.marc() && li.lineitem_details())
533 fieldmapper.standardRequest(
534 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
537 params: [self.authtoken, liId, {
539 flesh_li_details: true,
540 flesh_fund_debit: true }],
542 oncomplete: function(r) {
543 var li = openils.Util.readResponse(r);
550 this._drawInfo = function(li) {
552 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
555 openils.Util.hide('acq-lit-marc-order-record-label');
556 openils.Util.hide(acqLitEditOrderMarc.domNode);
557 openils.Util.show('acq-lit-marc-real-record-label');
559 openils.Util.show('acq-lit-marc-order-record-label');
560 openils.Util.show(acqLitEditOrderMarc.domNode);
561 openils.Util.hide('acq-lit-marc-real-record-label');
564 this.drawMarcHTML(li);
565 this.infoTbody = dojo.byId('acq-lit-info-tbody');
568 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
569 while(this.infoTbody.childNodes[0])
570 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
572 for(var i = 0; i < li.attributes().length; i++) {
573 var attr = li.attributes()[i];
574 var row = this.infoRow.cloneNode(true);
576 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
577 var name = openils.acq.Lineitem.attrDefs[type].filter(
579 return (a.code() == attr.attr_name());
581 ).pop().description();
583 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
584 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
585 this.infoTbody.appendChild(row);
589 openils.Util.show('acq-lit-info-cat-link');
590 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
592 if(openils.XUL.isXUL()) {
594 var makeRecTab = function() {
597 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
600 show_nav_buttons : true,
601 show_print_button : true,
602 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
606 link.setAttribute('href', 'javascript:void(0);');
607 link.onclick = makeRecTab;
610 var href = link.getAttribute('href');
612 link.setAttribute('href', href + li.eg_bib_id());
615 openils.Util.hide('acq-lit-info-cat-link');
619 this.drawMarcHTML = function(li) {
620 var params = [null, true, li.marc()];
622 params = [li.eg_bib_id(), true];
624 fieldmapper.standardRequest(
625 ['open-ils.search', 'open-ils.search.biblio.record.html'],
628 oncomplete: function(r) {
629 dojo.byId('acq-lit-marc-div').innerHTML =
630 openils.Util.readResponse(r);
636 this.drawCopies = function(liId) {
640 this.copyWidgetCache = {};
641 this.oldCopyWidgetCache = {};
642 this.virtDfaCounts = {};
643 this.realDfaCache = {};
646 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
647 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
648 acqLitCopyCountInput.attr('value', '0');
650 while(this.copyTbody.childNodes[0])
651 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
653 this._drawBatchCopyWidgets();
655 this._drawDistribApplied(liId);
657 this._fetchDistribFormulas(
659 openils.acq.Lineitem.fetchAttrDefs(
661 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
668 this._saveDistribAppliedTemplates = function() {
669 if (!this._appliedDistribTemplate) {
670 this._appliedDistribTemplate =
671 dojo.byId("acq-lit-distrib-applied-tbody").
672 removeChild(dojo.byId("acq-lit-distrib-applied-row"));
673 dojo.attr(this._appliedDistribTemplate, "id");
677 this._drawDistribApplied = function(liId) {
678 /* Build this table while hidden to prevent rendering artifacts */
679 openils.Util.hide("acq-lit-distrib-applied-tbody");
681 this._saveDistribAppliedTemplates();
683 /* Remove any rows in the table from previous populations */
684 dojo.query("tr[formula]", "acq-lit-distrib-applied-tbody").
685 forEach(dojo.destroy);
687 /* Unregister all dijits previously created (for some reason this isn't
688 * covered by the above destroy calls). */
689 dijit.registry.forEach(
690 function(w) { if (/^dfa-/.test(w.id)) w.destroyRecursive(); }
693 /* Populate the table with our liId */
695 fieldmapper.standardRequest(
697 "open-ils.acq.distribution_formula_application.ranged.retrieve"],
700 "params": [self.authtoken, liId],
701 "onresponse": function(r) {
702 var dfa = openils.Util.readResponse(r);
705 self.realDfaCache[dfa.id()] = dfa;
706 self._drawDistribAppliedUnit(dfa);
709 "oncomplete": function() {
710 /* Reveal built table */
713 "acq-lit-distrib-applied-tbody", "table-row-group"
721 this._drawDistribAppliedUnit = function(dfa) {
723 var row = dojo.query(
724 'tr[formula="' + dfa.formula().id() + '"]',
725 "acq-lit-distrib-applied-tbody"
730 row = dojo.clone(this._appliedDistribTemplate);
731 dojo.attr(row, "formula", dfa.formula().id());
732 dojo.query("th", row)[0].innerHTML = dfa.formula().name();
735 var td = dojo.query("td", row)[0];
737 dojo.create("span", {"id": "dfa-button-" + dfa.id()}, td, "last");
738 dojo.create("span", {"id": "dfa-tip-" + dfa.id()}, td, "last");
741 dojo.place(row, "acq-lit-distrib-applied-tbody", "last");
743 new dijit.form.Button(
745 "onClick": function() {
746 if (confirm(localeStrings.EXPLAIN_DFA_MGMT))
750 /* XXX I /cannot/ make the following work in as a CSS class
751 * for some reason. So frustrating... */
752 "style": function(id) {
754 "font-weight: bold; color: #c00;" :
756 }(dfa.id()) + "margin: 0 6px;display: inline;"
757 }, "dfa-button-" + dfa.id()
761 "connectId": ["dfa-button-" + dfa.id()],
762 "label": dojo.string.substitute(
763 localeStrings.DFA_TIP, dfa.id() > 0 ? [
764 openils.User.formalName(dfa.creator()),
765 dojo.date.locale.format(
766 dojo.date.stamp.fromISOString(dfa.create_time()),
767 {"formatLength":"short"}
769 ] : [localeStrings.ITS_YOU, localeStrings.JUST_NOW]
771 }, "dfa-tip-" + dfa.id()
775 this.deleteDfa = function(dfa) {
776 if (dfa.id() > 0) { /* real */
780 "oncomplete": function() {
781 self._removeDistribApplied(dfa.id());
782 delete self.realDfaCache[dfa.id()];
786 } else { /* virtual */
787 if (--(this.virtDfaCounts[dfa.formula().id()]) < 0)
788 this.virtDfaCounts[dfa.formula().id()] = 0;
789 /* hasn't been saved yet, so no need to do anything server side */
790 this._removeDistribApplied(dfa.id());
795 this._removeDistribApplied = function(dfaId) {
796 var re = new RegExp("^dfa-\\w+-" + String(dfaId));
797 dijit.registry.forEach(
798 function(w) { if (re.test(w.id)) w.destroyRecursive(); }
800 this._removeDistribAppliedEmptyRows();
803 this._removeAllDistribAppliedVirtual = function() {
804 /* Unregister dijits */
805 dijit.registry.forEach(
806 function(w) { if (/^dfa-\w+--/.test(w.id)) w.destroyRecursive(); }
808 this._removeDistribAppliedEmptyRows();
811 this._removeDistribAppliedEmptyRows = function() {
812 /* Remove any rows with no DFA at all */
813 dojo.query("tr[formula] td", "acq-lit-distrib-applied-tbody").forEach(
815 if (o.childNodes.length < 1) dojo.destroy(o.parentNode);
821 * Insert a new row into the distribution formula selection form
823 this._addDistribFormulaRow = function() {
826 if (!self.distribForms) {
827 // no formulas, hide the form
828 openils.Util.hide('acq-lit-distrib-formula-tbody');
832 if(!this.distribFormulaTemplate)
833 this.distribFormulaTemplate =
834 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
836 var row = this.distribFormulaTemplate.cloneNode(true);
837 dojo.place(row, "acq-lit-distrib-formula-tbody", "only");
839 this.dfSelector = new dijit.form.FilteringSelect(
840 {"labelAttr": "dynLabel", "labelType": "html"},
841 nodeByName("selector", row)
843 this._updateFormulaStore();
844 this.dfSelector.fetchProperties =
845 {"sort": [{"attribute": "use_count", "descending": true}]};
847 var apply = new dijit.form.Button(
848 {"label": localeStrings.APPLY},
849 nodeByName('set_button', row)
852 var reset = new dijit.form.Button(
853 {"label": localeStrings.RESET_FORMULAE, "disabled": true},
854 nodeByName("reset_button", row)
857 dojo.connect(apply, 'onClick',
859 var form_id = self.dfSelector.attr("value");
861 self._applyDistribFormula(form_id);
862 reset.attr("disabled", false);
866 dojo.connect(reset, 'onClick',
868 self.restoreCopyFieldsBeforeDF();
869 self.virtDfaCounts = {};
872 self._updateFormulaStore();
873 self._removeAllDistribAppliedVirtual();
874 reset.attr("disabled", "true");
881 * Applies a distrib formula to the current set of copies
883 this._applyDistribFormula = function(formula) {
886 formula = this.distribForms.filter(
887 function(form) { return form.id() == formula; }
890 var copyRows = dojo.query('tr', self.copyTbody);
892 if (this.dfeOffset >= copyRows.length) {
893 alert(localeStrings.OUT_OF_COPIES);
897 var entries_applied = 0;
899 var rowIndex = this.dfeOffset;
900 rowIndex < copyRows.length;
904 var row = copyRows[rowIndex];
905 var copy_id = row.getAttribute('copy_id');
906 var copyWidgets = this.copyWidgetCache[copy_id];
907 var entryIndex = this.dfeOffset;
910 // find the correct entry for the current row
911 dojo.forEach(formula.entries(),
914 entryIndex += e.item_count();
915 if(entryIndex > rowIndex)
923 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
924 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
927 this.saveCopyFieldsBeforeDF(copy_id);
928 this._copy_fields_for_acqdf.forEach(
931 copyWidgets[field].attr('value', (entry[field]()));
938 if (entries_applied) {
939 this.virtDfaCounts[formula.id()] =
940 ++(this.virtDfaCounts[formula.id()]) || 1;
941 this._updateFormulaStore();
942 this._drawDistribAppliedUnit(
944 var dfa = new acqdfa();
945 dfa.formula(df); dfa.id(self.virtDfaId--); return dfa;
948 this.dfeOffset += entries_applied;
953 * This function updates the DF store for the dropdown so that use_counts
954 * can reflect DF applications from this session before they're saved
957 this._updateFormulaStore = function() {
958 this.dfSelector.store = new dojo.data.ItemFileReadStore(
960 "data": self._labelFormulasWithCounts(
961 acqdf.toStoreData(self.distribForms)
967 this.saveCopyFieldsBeforeDF = function(copy_id) {
969 if (!this.oldCopyWidgetCache[copy_id]) {
970 var copyWidgets = this.copyWidgetCache[copy_id];
972 this.oldCopyWidgetCache[copy_id] = {};
973 this._copy_fields_for_acqdf.forEach(
975 self.oldCopyWidgetCache[copy_id][f] =
976 copyWidgets[f].attr("value");
982 this.restoreCopyFieldsBeforeDF = function() {
984 for (var copy_id in this.oldCopyWidgetCache) {
985 this._copy_fields_for_acqdf.forEach(
987 self.copyWidgetCache[copy_id][f].attr(
988 "value", self.oldCopyWidgetCache[copy_id][f]
995 this._labelFormulasWithCounts = function(store_data) {
996 for (var key in store_data.items) {
997 var obj = store_data.items[key];
998 obj.use_count = Number(obj.use_count); /* needed for sorting */
1000 if (this.virtDfaCounts[obj.id])
1001 obj.use_count = obj.use_count + Number(this.virtDfaCounts[obj.id]);
1003 obj.dynLabel = "<span class='acq-lit-distrib-form-use-count'>[" +
1004 obj.use_count + "]</span> " + obj.name;
1010 * This method formerly would not refetch the DF formulas if they'd been
1011 * loaded already, but now it always re-fetches, since use_count changes.
1013 this._fetchDistribFormulas = function(onload) {
1014 fieldmapper.standardRequest(
1016 "open-ils.acq.distribution_formula.ranged.retrieve.atomic"],
1019 "params": [openils.User.authtoken],
1020 "oncomplete": function(r) {
1021 self.distribForms = openils.Util.readResponse(r);
1022 if(!self.distribForms || self.distribForms.length == 0) {
1023 self.distribForms = [];
1025 self._addDistribFormulaRow();
1032 this._drawBatchCopyWidgets = function() {
1033 var row = this.copyBatchRow;
1034 dojo.forEach(liDetailBatchFields,
1036 if(self.copyBatchRowDrawn) {
1037 self.copyBatchWidgets[field].attr('value', null);
1039 var widget = new openils.widget.AutoFieldWidget({
1042 parentNode : dojo.query('[name='+field+']', row)[0],
1043 orgLimitPerms : ['CREATE_PICKLIST'],
1044 dijitArgs : {required:false},
1049 self.copyBatchWidgets[field] = w;
1055 this.copyBatchRowDrawn = true;
1058 this.batchCopyUpdate = function() {
1060 for(var k in this.copyWidgetCache) {
1061 var cache = this.copyWidgetCache[k];
1062 dojo.forEach(liDetailBatchFields, function(f) {
1063 var newval = self.copyBatchWidgets[f].attr('value');
1064 if(newval) cache[f].attr('value', newval);
1069 this._drawCopies = function(li) {
1072 // this button sets the total number of copies for a given lineitem
1073 acqLitAddCopyCount.onClick = function() {
1074 var count = acqLitCopyCountInput.attr('value');
1077 while(self.copyCount() < count)
1080 // delete rows if necessary
1081 var diff = self.copyCount() - count;
1083 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
1084 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
1085 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
1087 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1093 if(li.lineitem_details().length > 0) {
1094 dojo.forEach(li.lineitem_details(),
1096 self.addCopy(li, copy);
1104 this.copyCount = function() {
1106 for(var id in this.copyCache) {
1107 if(!this.copyCache[id].isdeleted())
1113 this.virtCopyId = -1;
1114 this.addCopy = function(li, copy) {
1115 var row = this.copyRow.cloneNode(true);
1116 this.copyTbody.appendChild(row);
1120 copy = new fieldmapper.acqlid();
1122 copy.id(this.virtCopyId--);
1123 copy.lineitem(li.id());
1126 this.copyCache[copy.id()] = copy;
1127 row.setAttribute('copy_id', copy.id());
1128 self.copyWidgetCache[copy.id()] = {};
1130 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1132 dojo.forEach(liDetailFields,
1134 var widget = new openils.widget.AutoFieldWidget({
1138 parentNode : dojo.query('[name='+field+']', row)[0],
1139 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
1140 readOnly : Boolean(copy.eg_copy_id())
1143 // make sure we capture the value from any async widgets
1145 copy[field](ww.getFormattedValue())
1146 self.copyWidgetCache[copy.id()][field] = w;
1149 dojo.connect(widget.widget, 'onChange',
1151 if(copy.isnew() || val != copy[field]()) {
1152 // prevent setting ischanged() automatically on widget load for existing copies
1153 copy[field](widget.getFormattedValue())
1154 copy.ischanged(true);
1161 this.updateLidReceivedness(copy, row);
1164 this.updateLidReceivedness = function(copy, row) {
1165 if (typeof(row) == "undefined") {
1167 'tr[copy_id="' + copy.id() + '"]', this.copyTbody
1172 var recv_link = nodeByName("receive", row);
1173 var unrecv_link = nodeByName("unreceive", row);
1174 var del_link = nodeByName("delete", row);
1177 openils.Util.hide(del_link.parentNode);
1179 /* Avoid showing (un)receive links for virtual copies */
1180 if (copy.id() > 0) {
1181 if(copy.recv_time()) {
1182 openils.Util.hide(recv_link);
1183 openils.Util.show(unrecv_link);
1184 unrecv_link.onclick = function() {
1185 if (confirm(localeStrings.UNRECEIVE_LID))
1186 self.issueReceive(copy, /* rollback */ true);
1189 openils.Util.hide(unrecv_link);
1190 openils.Util.show(recv_link);
1191 recv_link.onclick = function() {
1192 if (self.checkLiAlerts(copy.lineitem()))
1193 self.issueReceive(copy);
1197 openils.Util.hide(unrecv_link);
1198 openils.Util.hide(recv_link);
1201 openils.Util.hide(unrecv_link);
1202 openils.Util.hide(recv_link);
1204 del_link.onclick = function() { self.deleteCopy(row) };
1205 openils.Util.show(del_link.parentNode);
1209 this._confirmAlert = function(li, lin) {
1211 dojo.string.substitute(
1212 localeStrings.CONFIRM_LI_ALERT, [
1213 (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1214 "title", "lineitem_marc_attr_definition"
1216 lin.alert_text().code(),
1217 lin.alert_text().description() || "",
1224 this.checkLiAlerts = function(li_id) {
1225 var li = this.liCache[li_id];
1227 var alert_notes = li.lineitem_notes().filter(
1228 function(o) { return Boolean(o.alert_text()); }
1231 /* this is _intentionally_ not done in a call to forEach() ... */
1232 for (var i = 0; i < alert_notes.length; i++) {
1233 if (this.noteAcks[alert_notes[i].id()])
1235 else if (!this._confirmAlert(li, alert_notes[i]))
1238 this.noteAcks[alert_notes[i].id()] = true;
1244 this.deleteCopy = function(row) {
1245 var copy = this.copyCache[row.getAttribute('copy_id')];
1246 copy.isdeleted(true);
1248 delete this.copyCache[copy.id()];
1249 this.copyTbody.removeChild(row);
1252 this._virtDfaCountsAsList = function() {
1254 for (var key in this.virtDfaCounts) {
1255 for (var i = 0; i < this.virtDfaCounts[key]; i++)
1261 this.saveCopyChanges = function(liId) {
1267 for(var id in this.copyCache) {
1268 var c = this.copyCache[id];
1269 if(!c.isdeleted()) total++;
1270 if(c.isnew() || c.ischanged() || c.isdeleted()) {
1271 if(c.id() < 0) c.id(null);
1276 if (typeof(this._copy_count_cb) == "function") {
1277 this._copy_count_cb(liId, total);
1280 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
1283 if (copies.length > 0) {
1284 openils.Util.show("acq-lit-update-copies-progress");
1285 fieldmapper.standardRequest(
1286 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
1288 params: [openils.User.authtoken, copies],
1289 onresponse: function(r) {
1290 var res = openils.Util.readResponse(r);
1291 litUpdateCopiesProgress.update(res);
1293 oncomplete: function() {
1294 self.drawCopies(liId);
1295 openils.Util.hide("acq-lit-update-copies-progress");
1301 var dfa_list = this._virtDfaCountsAsList();
1302 if (dfa_list.length > 0) {
1303 fieldmapper.standardRequest(
1305 "open-ils.acq.distribution_formula.record_application"],
1308 "params": [openils.User.authtoken, dfa_list, liId],
1309 "onresponse": function(r) {
1310 var res = openils.Util.readResponse(r);
1311 if (res && res.length < dfa_list.length)
1312 alert(localeStrings.DFA_NOT_ALL);
1316 this.virtDfaCounts = {};
1320 this.applySelectedLiAction = function(action) {
1324 case 'delete_selected':
1325 this._deleteLiList(self.getSelected());
1328 case 'create_order':
1330 if(!this.createPoProviderSelector) {
1331 var widget = new openils.widget.AutoFieldWidget({
1332 fmField : 'provider',
1334 searchFilter: {"active": "t"},
1335 parentNode : dojo.byId('acq-lit-po-provider'),
1338 function(w) { self.createPoProviderSelector = w; }
1342 if(!this.createPoAgencySelector) {
1343 var widget = new openils.widget.AutoFieldWidget({
1344 fmField : 'ordering_agency',
1346 parentNode : dojo.byId('acq-lit-po-agency'),
1347 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
1350 function(w) { self.createPoAgencySelector = w; }
1355 acqLitPoCreateDialog.show();
1358 case 'save_picklist':
1359 this._loadPLSelect();
1360 acqLitSavePlDialog.show();
1363 case 'selector_ready':
1365 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
1366 acqLitChangeLiStateDialog.show();
1377 case 'rollback_receive_po':
1378 this.rollbackPoReceive();
1381 case 'create_assets':
1382 this.createAssets();
1385 case 'export_attr_list':
1386 this.chooseExportAttr();
1389 case 'add_brief_record':
1391 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
1393 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
1397 this.createAssets = function() {
1398 if(!this.isPO) return;
1399 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
1400 this.show('acq-lit-progress-numbers');
1402 fieldmapper.standardRequest(
1403 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
1405 params: [this.authtoken, this.isPO],
1406 onresponse: function(r) {
1407 var resp = openils.Util.readResponse(r);
1408 self._updateProgressNumbers(resp, true);
1414 this.chooseExportAttr = function() {
1415 if (!acqLitExportAttrSelector._li_setup) {
1417 acqLitExportAttrSelector.store = new dojo.data.ItemFileReadStore(
1419 "data": acqliad.toStoreData(
1421 "acqliad", {"code": li_exportable_attrs}
1426 acqLitExportAttrSelector.setValue();
1427 acqLitExportAttrButton.onClick = function(){self.exportAttrList();};
1428 acqLitExportAttrSelector._li_setup = true;
1430 openils.Util.show("acq-lit-export-attr-holder", "inline");
1433 this.exportAttrList = function() {
1434 var attr_def = acqLitExportAttrSelector.item;
1435 var li_list = this.getSelected();
1436 var value_list = li_list.map(
1438 return (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1439 attr_def.code, "lineitem_marc_attr_definition"
1442 ).filter(function(attr) { return Boolean(attr); });
1444 if (value_list.length > 0) {
1445 if (value_list.length < li_list.length) {
1447 dojo.string.substitute(
1448 localeStrings.EXPORT_SHORT_LIST, [attr_def.description]
1455 openils.XUL.contentToFileSaveDialog(
1456 value_list.join("\n"),
1457 localeStrings.EXPORT_SAVE_DIALOG_TITLE
1463 alert(dojo.string.substitute(
1464 localeStrings.EXPORT_EMPTY_LIST, [attr_def.description]
1468 openils.Util.hide("acq-lit-export-attr-holder");
1471 this.printPO = function() {
1472 if(!this.isPO) return;
1473 progressDialog.show(true);
1474 fieldmapper.standardRequest(
1475 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
1477 params: [this.authtoken, this.isPO, 'html'],
1478 oncomplete: function(r) {
1479 progressDialog.hide();
1480 var evt = openils.Util.readResponse(r);
1481 if(evt && evt.template_output()) {
1482 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
1483 win.document.body.innerHTML = evt.template_output().data();
1491 this.receivePO = function() {
1492 if (!this.isPO) return;
1494 for (var id in this.liCache) {
1495 /* assumption: liCache reflects exactly the
1496 * set of LIs that belong to our PO */
1497 if (this.liCache[id].state() != "received" &&
1498 !this.checkLiAlerts(id)) return;
1501 this.show('acq-lit-progress-numbers');
1503 fieldmapper.standardRequest(
1504 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
1506 params: [this.authtoken, this.isPO],
1507 onresponse : function(r) {
1508 var resp = openils.Util.readResponse(r);
1509 self._updateProgressNumbers(resp, true);
1515 this.issueReceive = function(obj, rollback) {
1516 /* (For now) there shall be no marking LI or LIDs (un)received
1517 * except from the actual "view PO" interface. */
1518 if (!this.isPO) return;
1521 {"jub": "lineitem", "acqlid": "lineitem_detail"}[obj.classname];
1523 "open-ils.acq." + part + ".receive" + (rollback ? ".rollback" : "");
1525 progressDialog.show(true);
1526 fieldmapper.standardRequest(
1527 ["open-ils.acq", method], {
1529 "params": [this.authtoken, obj.id()],
1530 "onresponse": function(r) {
1531 self.handleReceive(openils.Util.readResponse(r));
1533 "oncomplete": function() { progressDialog.hide(); }
1539 * Handles the responses from receive and rollback ML calls.
1541 this.handleReceive = function(resp) {
1544 for (var li_id in resp.li) {
1545 for (var key in resp.li[li_id])
1546 self.liCache[li_id][key](resp.li[li_id][key]);
1547 self.updateLiReceivedness(self.liCache[li_id]);
1551 if (typeof(self.poUpdateCallback) == "function")
1552 self.poUpdateCallback(resp.po);
1555 for (var lid_id in resp.lid) {
1556 for (var key in resp.lid[lid_id])
1557 self.copyCache[lid_id][key](resp.lid[lid_id][key]);
1558 self.updateLidReceivedness(self.copyCache[lid_id]);
1564 this.rollbackPoReceive = function() {
1565 if(!this.isPO) return;
1566 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
1567 this.show('acq-lit-progress-numbers');
1569 fieldmapper.standardRequest(
1570 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
1572 params: [this.authtoken, this.isPO],
1573 onresponse : function(r) {
1574 var resp = openils.Util.readResponse(r);
1575 self._updateProgressNumbers(resp, true);
1581 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1583 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1584 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1585 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1586 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1587 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1588 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1589 if(resp.complete && reloadOnComplete)
1590 location.href = location.href;
1594 this._createPO = function(fields) {
1595 this.show('acq-lit-progress-numbers');
1596 var po = new fieldmapper.acqpo();
1597 po.provider(this.createPoProviderSelector.attr('value'));
1598 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1600 var selected = this.getSelected( (fields.create_from == 'all') );
1601 if(selected.length == 0) return;
1603 var max = selected.length * 3;
1606 fieldmapper.standardRequest(
1607 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1610 openils.User.authtoken,
1613 lineitems : selected.map(function(li) { return li.id() }),
1614 create_assets : fields.create_assets[0],
1618 onresponse : function(r) {
1619 var resp = openils.Util.readResponse(r);
1620 self._updateProgressNumbers(resp);
1622 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1628 this._deleteLiList = function(list, idx) {
1629 if(idx == null) idx = 0;
1630 if(idx >= list.length) return;
1631 var liId = list[idx].id();
1632 fieldmapper.standardRequest(
1633 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1635 params: [openils.User.authtoken, liId],
1636 oncomplete: function(r) {
1637 self.removeLineitem(liId);
1638 self._deleteLiList(list, ++idx);
1644 this.editOrderMarc = function(li) {
1646 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1647 to true in about:config */
1649 if(!openils.XUL.enableXPConnect()) return;
1651 if(openils.XUL.isXUL()) {
1652 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1654 win = window.open('/xul/server/cat/marcedit.xul');
1658 record : {marc : li.marc()},
1660 label: 'Save Record', // XXX I18N
1661 func: function(xmlString) {
1663 fieldmapper.standardRequest(
1664 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1666 params: [openils.User.authtoken, li],
1667 oncomplete: function(r) {
1668 openils.Util.readResponse(r);
1670 self.drawInfo(li.id())
1679 this._savePl = function(values) {
1681 var selected = this.getSelected( (values.which == 'all') );
1682 openils.Util.show('acq-lit-generic-progress');
1684 if(values.new_name) {
1685 openils.acq.Picklist.create(
1686 {name: values.new_name},
1688 self._updateLiList(id, selected, 0,
1690 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1694 } else if(values.existing_pl) {
1695 // update lineitems to use an existing picklist
1696 self._updateLiList(values.existing_pl, selected, 0,
1698 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1703 this._updateLiState = function(values, state) {
1705 var selected = this.getSelected( (values.which == 'all') );
1706 if(!selected.length) return;
1707 dojo.forEach(selected, function(li) {li.state(state);});
1708 self._updateLiList(null, selected, 0,
1709 // TODO consider inline updates for efficiency
1710 function() { location.href = location.href }
1714 this._updateLiList = function(pl, list, idx, oncomplete) {
1715 if(idx >= list.length) return oncomplete();
1717 if(pl != null) li.picklist(pl);
1718 litGenericProgress.update({maximum: list.length, progress: idx});
1719 new openils.acq.Lineitem({lineitem:li}).update(
1721 self._updateLiList(pl, list, ++idx, oncomplete);
1726 this._loadPLSelect = function() {
1727 if(this._plSelectLoaded) return;
1729 function handleResponse(r) {
1730 plList.push(r.recv().content());
1732 var method = 'open-ils.acq.picklist.user.retrieve';
1733 fieldmapper.standardRequest(
1734 ['open-ils.acq', method],
1736 params: [this.authtoken],
1737 onresponse: handleResponse,
1738 oncomplete: function() {
1739 self._plSelectLoaded = true;
1740 acqLitAddExistingSelect.store =
1741 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1742 acqLitAddExistingSelect.setValue();
1748 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1749 this.showRealCopies = function(li) {
1750 while(this.realCopiesTbody.childNodes[0])
1751 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1752 this.show('real-copies');
1754 this.realCopyList = [];
1756 var tabIndex = 1000;
1759 acqLitSaveRealCopies.onClick = function() {
1760 self.saveRealCopies();
1763 this._fetchLineitem(li.id(),
1765 li = self.liCache[li.id()] = fullLi;
1769 id : li.lineitem_details().map(
1770 function(item) { return item.eg_copy_id() }
1775 onresponse : function(r) {
1776 var copy = openils.Util.readResponse(r);
1777 var volId = copy.call_number();
1778 var volume = self.volCache[volId];
1780 volume = self.volCache[volId] = self.pcrud.retrieve('acn', volId);
1782 self.addRealCopy(volume, copy, tabIndex++);
1790 this.addRealCopy = function(volume, copy, tabIndex) {
1791 var row = this.realCopiesRow.cloneNode(true);
1792 this.realCopyList.push(copy);
1796 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1799 var isvol = (field == 'owning_lib' || field == 'label');
1800 var widget = new openils.widget.AutoFieldWidget({
1802 fmObject : isvol ? volume : copy,
1803 parentNode : nodeByName(field, row),
1804 readOnly : (field != 'barcode'),
1807 var widgetDrawn = null;
1809 if(field == 'barcode') {
1811 widgetDrawn = function(w, ww) {
1812 var node = w.domNode;
1813 node.setAttribute('tabindex', ''+tabIndex);
1815 // on enter, select the next barcode input
1816 dojo.connect(w, 'onKeyDown',
1818 if(e.keyCode == dojo.keys.ENTER) {
1819 var ti = node.getAttribute('tabindex');
1820 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1821 if(nextNode) nextNode.select();
1826 dojo.connect(w, 'onChange',
1828 if(!val || val == copy.barcode()) return;
1829 copy.ischanged(true);
1835 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1840 widget.build(widgetDrawn);
1844 this.realCopiesTbody.appendChild(row);
1845 if(selectNode) selectNode.select();
1848 this.saveRealCopies = function() {
1849 progressDialog.show(true);
1850 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1851 this.pcrud.update(list, {oncomplete: function() {
1852 progressDialog.hide();