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 var fundLabelFormat = ['${0} (${1})', 'code', 'year'];
27 function nodeByName(name, context) {
28 return dojo.query('[name='+name+']', context)[0];
32 var liDetailBatchFields = ['fund', 'owning_lib', 'location', 'collection_code', 'circ_modifier', 'cn_label'];
33 var liDetailFields = liDetailBatchFields.concat(['barcode', 'note']);
35 function AcqLiTable() {
41 this.realDfaCache = {};
42 this.virtDfaCounts = {};
45 this.toggleState = false;
46 this.tbody = dojo.byId('acq-lit-tbody');
49 this.authtoken = openils.User.authtoken;
50 this.pcrud = new openils.PermaCrud();
51 this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
52 this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
53 this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
54 this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
55 this.copyBatchWidgets = {};
56 this.liNotesTbody = dojo.byId('acq-lit-notes-tbody');
57 this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row'));
58 this.realCopiesTbody = dojo.byId('acq-lit-real-copies-tbody');
59 this.realCopiesRow = this.realCopiesTbody.removeChild(dojo.byId('acq-lit-real-copies-row'));
60 this._copy_fields_for_acqdf = ['owning_lib', 'location'];
62 dojo.connect(acqLitLiActionsSelector, 'onChange',
64 self.applySelectedLiAction(this.attr('value'))
65 acqLitLiActionsSelector.attr('value', '_');
68 acqLitCreatePoSubmit.onClick = function() {
69 acqLitPoCreateDialog.hide();
70 self._createPO(acqLitPoCreateDialog.getValues());
73 acqLitSavePlButton.onClick = function() {
74 acqLitSavePlDialog.hide();
75 self._savePl(acqLitSavePlDialog.getValues());
78 acqLitCancelLiStateButton.onClick = function() {
79 acqLitChangeLiStateDialog.hide();
81 acqLitSaveLiStateButton.onClick = function() {
82 acqLitChangeLiStateDialog.hide();
83 self._updateLiState(acqLitChangeLiStateDialog.getValues(), acqLitChangeLiStateDialog.attr('state'));
87 //dojo.byId('acq-lit-notes-new-button').onclick = function(){acqLitCreateLiNoteDialog.show();}
89 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
90 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
91 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
92 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
93 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
95 this.reset = function() {
96 while(self.tbody.childNodes[0])
97 self.tbody.removeChild(self.tbody.childNodes[0]);
102 this.setNext = function(handler) {
103 var link = dojo.byId('acq-lit-next');
105 dojo.style(link, 'visibility', 'visible');
106 link.onclick = handler;
108 dojo.style(link, 'visibility', 'hidden');
112 this.setPrev = function(handler) {
113 var link = dojo.byId('acq-lit-prev');
115 dojo.style(link, 'visibility', 'visible');
116 link.onclick = handler;
118 dojo.style(link, 'visibility', 'hidden');
122 this.show = function(div) {
123 openils.Util.hide('acq-lit-table-div');
124 openils.Util.hide('acq-lit-info-div');
125 openils.Util.hide('acq-lit-li-details');
126 openils.Util.hide('acq-lit-notes-div');
127 openils.Util.hide('acq-lit-real-copies-div');
130 openils.Util.show('acq-lit-table-div');
133 openils.Util.show('acq-lit-info-div');
136 openils.Util.show('acq-lit-li-details');
139 openils.Util.show('acq-lit-real-copies-div');
142 openils.Util.show('acq-lit-notes-div');
146 openils.Util.show(div);
150 this.hide = function() {
154 this.toggleSelect = function() {
156 dojo.forEach(self.selectors, function(i){i.checked = false});
158 dojo.forEach(self.selectors, function(i){i.checked = true});
159 self.toggleState = !self.toggleState;
163 /** @param all If true, assume all are selected */
164 this.getSelected = function(all) {
166 dojo.forEach(self.selectors,
169 selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
175 this.setRowAttr = function(td, liWrapper, field, type) {
176 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
177 td.appendChild(document.createTextNode(val));
181 * Inserts a single lineitem into the growing table of lineitems
182 * @param {Object} li The lineitem object to insert
184 this.addLineitem = function(li, skip_final_placement) {
185 this.liCache[li.id()] = li;
187 // sort the lineitem notes on edit_time
188 if(!li.lineitem_notes()) li.lineitem_notes([]);
190 var liWrapper = new openils.acq.Lineitem({lineitem:li});
191 var row = self.rowTemplate.cloneNode(true);
192 row.setAttribute('li', li.id());
193 var tds = dojo.query('[attr]', row);
194 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
195 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
197 var isbn = liWrapper.findAttr('isbn', 'lineitem_marc_attr_definition');
199 // XXX media prefix for added content
200 dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
203 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
204 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
205 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
207 this.updateLiNotesCount(li, row);
209 // show which PO this lineitem is a member of
210 if(li.purchase_order() && !this.isPO) {
212 this.poCache[li.purchase_order()] =
213 this.poCache[li.purchase_order()] ||
214 fieldmapper.standardRequest(
215 ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
217 this.authtoken, li.purchase_order(), {
218 "flesh_price_summary": true,
219 "flesh_lineitem_count": true
222 if(po && !this.isMeta) {
223 openils.Util.show(nodeByName('po', row), 'inline');
224 var link = nodeByName('po_link', row);
225 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
226 link.innerHTML = 'PO: ' + po.name(); // TODO i18n
230 // show which picklist this lineitem is a member of
231 if(li.picklist() && (this.isPO || this.isMeta)) {
233 this.plCache[li.picklist()] =
234 this.plCache[li.picklist()] ||
235 fieldmapper.standardRequest(
236 ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
237 {params: [this.authtoken, li.picklist()]});
239 openils.Util.show(nodeByName('pl', row), 'inline');
240 var link = nodeByName('pl_link', row);
241 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
242 link.innerHTML = 'PL: '+pl.name(); // TODO i18n
246 var countNode = nodeByName('count', row);
247 var count = li.item_count() || 0;
248 if (typeof(this._copy_count_cb) == "function") {
249 this._copy_count_cb(li.id(), count);
251 countNode.innerHTML = count;
252 countNode.id = 'acq-lit-copy-count-label-' + li.id();
255 nodeByName('li_state', row).innerHTML = li.state(); // TODO i18n state labels
257 var priceInput = dojo.query('[name=price]', row)[0];
258 var priceData = liWrapper.getPrice();
259 priceInput.value = (priceData) ? priceData.price : '';
260 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
262 // show either "mark received" or "unreceive" as appropriate
263 this.updateLiReceivedness(li, row);
265 if (!skip_final_placement) {
266 self.tbody.appendChild(row);
267 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
273 this.updateLiNotesCount = function(li, row) {
274 if (typeof(row) == "undefined")
275 row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
277 var has_notes = (li.lineitem_notes().filter(
278 function(o) { return Boolean (o.alert_text()); }
281 /* U+2691 is the code point for a filled-in flag character */
282 nodeByName("notes_alert_flag", row).innerHTML =
283 has_notes ? "⚑" : "";
284 nodeByName("noteslink", row).style.fontStyle =
285 has_notes ? "italic" : "normal";
286 nodeByName("notes_count", row).innerHTML = li.lineitem_notes().length;
289 this.updateLiReceivedness = function(li, row) {
290 if (typeof(row) == "undefined")
291 row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
293 var recv_link = nodeByName("receive_link", row);
294 var unrecv_link = nodeByName("unreceive_link", row);
295 var real_copies_link = nodeByName("real_copies_link", row);
297 /* handle row coloring for based on LI state */
298 openils.Util.removeCSSClass(row, /^oils-acq-li-state-/);
299 openils.Util.addCSSClass(row, "oils-acq-li-state-" + li.state());
301 /* handle links that appear/disappear based on whether LI is received */
306 openils.Util.hide(real_copies_link);
307 openils.Util.hide(unrecv_link);
308 openils.Util.show(recv_link, "inline");
309 recv_link.onclick = function() {
310 if (self.checkLiAlerts(li.id()))
311 self.issueReceive(li);
315 openils.Util.hide(recv_link);
316 openils.Util.show(unrecv_link, "inline");
317 unrecv_link.onclick = function() {
318 if (confirm(localeStrings.UNRECEIVE_LI))
319 self.issueReceive(li, /* rollback */ true);
321 // TODO we should allow editing before receipt, in which case the
322 // test should be "if 1 or more real (acp) copies exist
323 openils.Util.show(real_copies_link);
324 real_copies_link.onclick = function() {
325 self.showRealCopies(li);
331 openils.Util.hide(recv_link);
332 openils.Util.hide(unrecv_link);
333 openils.Util.hide(real_copies_link);
337 this._setAlertStore = function() {
338 acqLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
340 "data": acqliat.toStoreData(
342 "acqliat", {"id": {"!=": null}}
347 acqLitAlertAlertText.setValue(); /* make the store "live" */
348 acqLitAlertAlertText._store_ready = true;
352 * Draws and shows the lineitem notes pane
354 this.drawLiNotes = function(li) {
357 if (!acqLitAlertAlertText._store_ready)
358 this._setAlertStore();
361 li.lineitem_notes().sort(
363 if(a.edit_time() < b.edit_time()) return 1;
369 while(this.liNotesTbody.childNodes[0])
370 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
373 acqLitCreateLiNoteSubmit.onClick = function() {
374 var value = acqLitCreateNoteText.attr('value');
376 var note = new fieldmapper.acqlin();
379 note.lineitem(li.id());
381 self.updateLiNotes(li, note);
384 acqLitCreateAlertSubmit.onClick = function() {
385 if (!acqLitAlertAlertText.item) {
386 alert(localeStrings.ALERT_UNSELECTED);
390 var alert_text = new fieldmapper.acqliat().fromStoreItem(
391 acqLitAlertAlertText.item
393 var value = acqLitAlertNoteValue.attr("value") || "";
395 var note = new fieldmapper.acqlin();
397 note.lineitem(li.id());
399 note.alert_text(alert_text);
401 self.updateLiNotes(li, note);
404 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
408 * Draws a single lineitem note in the notes pane
410 this.addLiNote = function(li, note) {
411 if(note.isdeleted()) return;
413 var row = self.liNotesRow.cloneNode(true);
414 nodeByName("value", row).innerHTML = note.value();
415 var alert_node = nodeByName("alert_code", row);
416 if (note.alert_text()) {
417 alert_node.innerHTML = note.alert_text().code();
418 if (note.alert_text().description()) {
421 "connectId": [alert_node],
422 "label": note.alert_text().description()
423 }, dojo.create("span", null, alert_node, "after")
428 nodeByName("delete", row).onclick = function() {
429 note.isdeleted(true);
430 self.liNotesTbody.removeChild(row);
431 self.updateLiNotes(li);
434 if(note.edit_time()) {
435 nodeByName("edit_time", row).innerHTML =
436 dojo.date.locale.format(
437 dojo.date.stamp.fromISOString(note.edit_time()),
438 {formatLength:'short'});
441 self.liNotesTbody.appendChild(row);
445 * Updates any new/changed/deleted notes on the server
447 this.updateLiNotes = function(li, newNote) {
453 notes = li.lineitem_notes().filter(
455 if(note.ischanged() || note.isnew() || note.isdeleted())
461 if(notes.length == 0) return;
462 progressDialog.show();
464 fieldmapper.standardRequest(
465 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
467 params : [this.authtoken, notes],
468 onresponse : function(r) {
469 var resp = openils.Util.readResponse(r);
474 // remove the old changed notes
476 dojo.forEach(li.lineitem_notes(),
478 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
482 li.lineitem_notes(list);
485 progressDialog.hide();
486 self.updateLiNotesCount(li);
487 self.drawLiNotes(li);
491 progressDialog.update(resp);
492 var newnote = resp.note;
494 if(!newnote.isdeleted()) {
495 newnote.isnew(false);
496 newnote.ischanged(false);
497 li.lineitem_notes().push(newnote);
504 this.updateLiPrice = function(input, li) {
506 var price = input.value;
507 var liWrapper = new openils.acq.Lineitem({lineitem:li});
508 var oldPrice = liWrapper.getPrice() || null;
510 if(oldPrice) oldPrice = oldPrice.price;
511 if(price == oldPrice) return;
513 fieldmapper.standardRequest(
514 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
516 params : [this.authtoken, li.id(), price],
517 oncomplete : function(r) {
518 openils.Util.readResponse(r);
524 this.removeLineitem = function(liId) {
525 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
526 delete this.liCache[liId];
527 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
530 this.drawInfo = function(liId) {
532 openils.acq.Lineitem.fetchAttrDefs(
534 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
539 this._fetchLineitem = function(liId, handler) {
541 var li = this.liCache[liId];
542 if(li && li.marc() && li.lineitem_details())
545 fieldmapper.standardRequest(
546 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
549 params: [self.authtoken, liId, {
551 flesh_li_details: true,
552 flesh_fund_debit: true }],
554 oncomplete: function(r) {
555 var li = openils.Util.readResponse(r);
562 this._drawInfo = function(li) {
564 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
567 openils.Util.hide('acq-lit-marc-order-record-label');
568 openils.Util.hide(acqLitEditOrderMarc.domNode);
569 openils.Util.show('acq-lit-marc-real-record-label');
571 openils.Util.show('acq-lit-marc-order-record-label');
572 openils.Util.show(acqLitEditOrderMarc.domNode);
573 openils.Util.hide('acq-lit-marc-real-record-label');
576 this.drawMarcHTML(li);
577 this.infoTbody = dojo.byId('acq-lit-info-tbody');
580 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
581 while(this.infoTbody.childNodes[0])
582 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
584 for(var i = 0; i < li.attributes().length; i++) {
585 var attr = li.attributes()[i];
586 var row = this.infoRow.cloneNode(true);
588 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
589 var name = openils.acq.Lineitem.attrDefs[type].filter(
591 return (a.code() == attr.attr_name());
593 ).pop().description();
595 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
596 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
597 this.infoTbody.appendChild(row);
601 openils.Util.show('acq-lit-info-cat-link');
602 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
604 if(openils.XUL.isXUL()) {
606 var makeRecTab = function() {
609 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
612 show_nav_buttons : true,
613 show_print_button : true,
614 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
618 link.setAttribute('href', 'javascript:void(0);');
619 link.onclick = makeRecTab;
622 var href = link.getAttribute('href');
624 link.setAttribute('href', href + li.eg_bib_id());
627 openils.Util.hide('acq-lit-info-cat-link');
631 this.drawMarcHTML = function(li) {
632 var params = [null, true, li.marc()];
634 params = [li.eg_bib_id(), true];
636 fieldmapper.standardRequest(
637 ['open-ils.search', 'open-ils.search.biblio.record.html'],
640 oncomplete: function(r) {
641 dojo.byId('acq-lit-marc-div').innerHTML =
642 openils.Util.readResponse(r);
648 this.drawCopies = function(liId) {
652 this.copyWidgetCache = {};
653 this.oldCopyWidgetCache = {};
654 this.virtDfaCounts = {};
655 this.realDfaCache = {};
658 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
659 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
660 acqLitCopyCountInput.attr('value', '0');
662 while(this.copyTbody.childNodes[0])
663 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
665 this._drawBatchCopyWidgets();
667 this._drawDistribApplied(liId);
669 this._fetchDistribFormulas(
671 openils.acq.Lineitem.fetchAttrDefs(
673 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
680 this._saveDistribAppliedTemplates = function() {
681 if (!this._appliedDistribTemplate) {
682 this._appliedDistribTemplate =
683 dojo.byId("acq-lit-distrib-applied-tbody").
684 removeChild(dojo.byId("acq-lit-distrib-applied-row"));
685 dojo.attr(this._appliedDistribTemplate, "id");
689 this._drawDistribApplied = function(liId) {
690 /* Build this table while hidden to prevent rendering artifacts */
691 openils.Util.hide("acq-lit-distrib-applied-tbody");
693 this._saveDistribAppliedTemplates();
695 /* Remove any rows in the table from previous populations */
696 dojo.query("tr[formula]", "acq-lit-distrib-applied-tbody").
697 forEach(dojo.destroy);
699 /* Unregister all dijits previously created (for some reason this isn't
700 * covered by the above destroy calls). */
701 dijit.registry.forEach(
702 function(w) { if (/^dfa-/.test(w.id)) w.destroyRecursive(); }
705 /* Populate the table with our liId */
707 fieldmapper.standardRequest(
709 "open-ils.acq.distribution_formula_application.ranged.retrieve"],
712 "params": [self.authtoken, liId],
713 "onresponse": function(r) {
714 var dfa = openils.Util.readResponse(r);
717 self.realDfaCache[dfa.id()] = dfa;
718 self._drawDistribAppliedUnit(dfa);
721 "oncomplete": function() {
722 /* Reveal built table */
725 "acq-lit-distrib-applied-tbody", "table-row-group"
733 this._drawDistribAppliedUnit = function(dfa) {
735 var row = dojo.query(
736 'tr[formula="' + dfa.formula().id() + '"]',
737 "acq-lit-distrib-applied-tbody"
742 row = dojo.clone(this._appliedDistribTemplate);
743 dojo.attr(row, "formula", dfa.formula().id());
744 dojo.query("th", row)[0].innerHTML = dfa.formula().name();
747 var td = dojo.query("td", row)[0];
749 dojo.create("span", {"id": "dfa-button-" + dfa.id()}, td, "last");
750 dojo.create("span", {"id": "dfa-tip-" + dfa.id()}, td, "last");
753 dojo.place(row, "acq-lit-distrib-applied-tbody", "last");
755 new dijit.form.Button(
757 "onClick": function() {
758 if (confirm(localeStrings.EXPLAIN_DFA_MGMT))
762 /* XXX I /cannot/ make the following work in as a CSS class
763 * for some reason. So frustrating... */
764 "style": function(id) {
766 "font-weight: bold; color: #c00;" :
768 }(dfa.id()) + "margin: 0 6px;display: inline;"
769 }, "dfa-button-" + dfa.id()
773 "connectId": ["dfa-button-" + dfa.id()],
774 "label": dojo.string.substitute(
775 localeStrings.DFA_TIP, dfa.id() > 0 ? [
776 openils.User.formalName(dfa.creator()),
777 dojo.date.locale.format(
778 dojo.date.stamp.fromISOString(dfa.create_time()),
779 {"formatLength":"short"}
781 ] : [localeStrings.ITS_YOU, localeStrings.JUST_NOW]
783 }, "dfa-tip-" + dfa.id()
787 this.deleteDfa = function(dfa) {
788 if (dfa.id() > 0) { /* real */
792 "oncomplete": function() {
793 self._removeDistribApplied(dfa.id());
794 delete self.realDfaCache[dfa.id()];
798 } else { /* virtual */
799 if (--(this.virtDfaCounts[dfa.formula().id()]) < 0)
800 this.virtDfaCounts[dfa.formula().id()] = 0;
801 /* hasn't been saved yet, so no need to do anything server side */
802 this._removeDistribApplied(dfa.id());
807 this._removeDistribApplied = function(dfaId) {
808 var re = new RegExp("^dfa-\\w+-" + String(dfaId));
809 dijit.registry.forEach(
810 function(w) { if (re.test(w.id)) w.destroyRecursive(); }
812 this._removeDistribAppliedEmptyRows();
815 this._removeAllDistribAppliedVirtual = function() {
816 /* Unregister dijits */
817 dijit.registry.forEach(
818 function(w) { if (/^dfa-\w+--/.test(w.id)) w.destroyRecursive(); }
820 this._removeDistribAppliedEmptyRows();
823 this._removeDistribAppliedEmptyRows = function() {
824 /* Remove any rows with no DFA at all */
825 dojo.query("tr[formula] td", "acq-lit-distrib-applied-tbody").forEach(
827 if (o.childNodes.length < 1) dojo.destroy(o.parentNode);
833 * Insert a new row into the distribution formula selection form
835 this._addDistribFormulaRow = function() {
838 if (!self.distribForms) {
839 // no formulas, hide the form
840 openils.Util.hide('acq-lit-distrib-formula-tbody');
844 if(!this.distribFormulaTemplate)
845 this.distribFormulaTemplate =
846 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
848 var row = this.distribFormulaTemplate.cloneNode(true);
849 dojo.place(row, "acq-lit-distrib-formula-tbody", "only");
851 this.dfSelector = new dijit.form.FilteringSelect(
852 {"labelAttr": "dynLabel", "labelType": "html"},
853 nodeByName("selector", row)
855 this._updateFormulaStore();
856 this.dfSelector.fetchProperties =
857 {"sort": [{"attribute": "use_count", "descending": true}]};
859 var apply = new dijit.form.Button(
860 {"label": localeStrings.APPLY},
861 nodeByName('set_button', row)
864 var reset = new dijit.form.Button(
865 {"label": localeStrings.RESET_FORMULAE, "disabled": true},
866 nodeByName("reset_button", row)
869 dojo.connect(apply, 'onClick',
871 var form_id = self.dfSelector.attr("value");
873 self._applyDistribFormula(form_id);
874 reset.attr("disabled", false);
878 dojo.connect(reset, 'onClick',
880 self.restoreCopyFieldsBeforeDF();
881 self.virtDfaCounts = {};
884 self._updateFormulaStore();
885 self._removeAllDistribAppliedVirtual();
886 reset.attr("disabled", "true");
893 * Applies a distrib formula to the current set of copies
895 this._applyDistribFormula = function(formula) {
898 formula = this.distribForms.filter(
899 function(form) { return form.id() == formula; }
902 var copyRows = dojo.query('tr', self.copyTbody);
904 if (this.dfeOffset >= copyRows.length) {
905 alert(localeStrings.OUT_OF_COPIES);
909 var entries_applied = 0;
911 var rowIndex = this.dfeOffset;
912 rowIndex < copyRows.length;
916 var row = copyRows[rowIndex];
917 var copy_id = row.getAttribute('copy_id');
918 var copyWidgets = this.copyWidgetCache[copy_id];
919 var entryIndex = this.dfeOffset;
922 // find the correct entry for the current row
923 dojo.forEach(formula.entries(),
926 entryIndex += e.item_count();
927 if(entryIndex > rowIndex)
935 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
936 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
939 this.saveCopyFieldsBeforeDF(copy_id);
940 this._copy_fields_for_acqdf.forEach(
943 copyWidgets[field].attr('value', (entry[field]()));
950 if (entries_applied) {
951 this.virtDfaCounts[formula.id()] =
952 ++(this.virtDfaCounts[formula.id()]) || 1;
953 this._updateFormulaStore();
954 this._drawDistribAppliedUnit(
956 var dfa = new acqdfa();
957 dfa.formula(df); dfa.id(self.virtDfaId--); return dfa;
960 this.dfeOffset += entries_applied;
965 * This function updates the DF store for the dropdown so that use_counts
966 * can reflect DF applications from this session before they're saved
969 this._updateFormulaStore = function() {
970 this.dfSelector.store = new dojo.data.ItemFileReadStore(
972 "data": self._labelFormulasWithCounts(
973 acqdf.toStoreData(self.distribForms)
979 this.saveCopyFieldsBeforeDF = function(copy_id) {
981 if (!this.oldCopyWidgetCache[copy_id]) {
982 var copyWidgets = this.copyWidgetCache[copy_id];
984 this.oldCopyWidgetCache[copy_id] = {};
985 this._copy_fields_for_acqdf.forEach(
987 self.oldCopyWidgetCache[copy_id][f] =
988 copyWidgets[f].attr("value");
994 this.restoreCopyFieldsBeforeDF = function() {
996 for (var copy_id in this.oldCopyWidgetCache) {
997 this._copy_fields_for_acqdf.forEach(
999 self.copyWidgetCache[copy_id][f].attr(
1000 "value", self.oldCopyWidgetCache[copy_id][f]
1007 this._labelFormulasWithCounts = function(store_data) {
1008 for (var key in store_data.items) {
1009 var obj = store_data.items[key];
1010 obj.use_count = Number(obj.use_count); /* needed for sorting */
1012 if (this.virtDfaCounts[obj.id])
1013 obj.use_count = obj.use_count + Number(this.virtDfaCounts[obj.id]);
1015 obj.dynLabel = "<span class='acq-lit-distrib-form-use-count'>[" +
1016 obj.use_count + "]</span> " + obj.name;
1022 * This method formerly would not refetch the DF formulas if they'd been
1023 * loaded already, but now it always re-fetches, since use_count changes.
1025 this._fetchDistribFormulas = function(onload) {
1026 fieldmapper.standardRequest(
1028 "open-ils.acq.distribution_formula.ranged.retrieve.atomic"],
1031 "params": [openils.User.authtoken],
1032 "oncomplete": function(r) {
1033 self.distribForms = openils.Util.readResponse(r);
1034 if(!self.distribForms || self.distribForms.length == 0) {
1035 self.distribForms = [];
1037 self._addDistribFormulaRow();
1044 this._drawBatchCopyWidgets = function() {
1045 var row = this.copyBatchRow;
1046 dojo.forEach(liDetailBatchFields,
1048 if(self.copyBatchRowDrawn) {
1049 self.copyBatchWidgets[field].attr('value', null);
1051 var widget = new openils.widget.AutoFieldWidget({
1054 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1055 parentNode : dojo.query('[name='+field+']', row)[0],
1056 orgLimitPerms : ['CREATE_PICKLIST'],
1057 dijitArgs : {required:false},
1062 self.copyBatchWidgets[field] = w;
1068 this.copyBatchRowDrawn = true;
1071 this.batchCopyUpdate = function() {
1073 for(var k in this.copyWidgetCache) {
1074 var cache = this.copyWidgetCache[k];
1075 dojo.forEach(liDetailBatchFields, function(f) {
1076 var newval = self.copyBatchWidgets[f].attr('value');
1077 if(newval) cache[f].attr('value', newval);
1082 this._drawCopies = function(li) {
1085 // this button sets the total number of copies for a given lineitem
1086 acqLitAddCopyCount.onClick = function() {
1087 var count = acqLitCopyCountInput.attr('value');
1090 while(self.copyCount() < count)
1093 // delete rows if necessary
1094 var diff = self.copyCount() - count;
1096 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
1097 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
1098 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
1100 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1106 if(li.lineitem_details().length > 0) {
1107 dojo.forEach(li.lineitem_details(),
1109 self.addCopy(li, copy);
1117 this.copyCount = function() {
1119 for(var id in this.copyCache) {
1120 if(!this.copyCache[id].isdeleted())
1126 this.virtCopyId = -1;
1127 this.addCopy = function(li, copy) {
1128 var row = this.copyRow.cloneNode(true);
1129 this.copyTbody.appendChild(row);
1133 copy = new fieldmapper.acqlid();
1135 copy.id(this.virtCopyId--);
1136 copy.lineitem(li.id());
1139 this.copyCache[copy.id()] = copy;
1140 row.setAttribute('copy_id', copy.id());
1141 self.copyWidgetCache[copy.id()] = {};
1143 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1145 dojo.forEach(liDetailFields,
1147 var widget = new openils.widget.AutoFieldWidget({
1150 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1152 parentNode : dojo.query('[name='+field+']', row)[0],
1153 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
1154 readOnly : Boolean(copy.eg_copy_id())
1157 // make sure we capture the value from any async widgets
1159 copy[field](ww.getFormattedValue())
1160 self.copyWidgetCache[copy.id()][field] = w;
1163 dojo.connect(widget.widget, 'onChange',
1165 if(copy.isnew() || val != copy[field]()) {
1166 // prevent setting ischanged() automatically on widget load for existing copies
1167 copy[field](widget.getFormattedValue())
1168 copy.ischanged(true);
1175 this.updateLidReceivedness(copy, row);
1178 this.updateLidReceivedness = function(copy, row) {
1179 if (typeof(row) == "undefined") {
1181 'tr[copy_id="' + copy.id() + '"]', this.copyTbody
1186 var recv_link = nodeByName("receive", row);
1187 var unrecv_link = nodeByName("unreceive", row);
1188 var del_link = nodeByName("delete", row);
1191 openils.Util.hide(del_link.parentNode);
1193 /* Avoid showing (un)receive links for virtual copies */
1194 if (copy.id() > 0) {
1195 if(copy.recv_time()) {
1196 openils.Util.hide(recv_link);
1197 openils.Util.show(unrecv_link);
1198 unrecv_link.onclick = function() {
1199 if (confirm(localeStrings.UNRECEIVE_LID))
1200 self.issueReceive(copy, /* rollback */ true);
1203 openils.Util.hide(unrecv_link);
1204 openils.Util.show(recv_link);
1205 recv_link.onclick = function() {
1206 if (self.checkLiAlerts(copy.lineitem()))
1207 self.issueReceive(copy);
1211 openils.Util.hide(unrecv_link);
1212 openils.Util.hide(recv_link);
1215 openils.Util.hide(unrecv_link);
1216 openils.Util.hide(recv_link);
1218 del_link.onclick = function() { self.deleteCopy(row) };
1219 openils.Util.show(del_link.parentNode);
1223 this._confirmAlert = function(li, lin) {
1225 dojo.string.substitute(
1226 localeStrings.CONFIRM_LI_ALERT, [
1227 (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1228 "title", "lineitem_marc_attr_definition"
1230 lin.alert_text().code(),
1231 lin.alert_text().description() || "",
1238 this.checkLiAlerts = function(li_id) {
1239 var li = this.liCache[li_id];
1241 var alert_notes = li.lineitem_notes().filter(
1242 function(o) { return Boolean(o.alert_text()); }
1245 /* this is _intentionally_ not done in a call to forEach() ... */
1246 for (var i = 0; i < alert_notes.length; i++) {
1247 if (this.noteAcks[alert_notes[i].id()])
1249 else if (!this._confirmAlert(li, alert_notes[i]))
1252 this.noteAcks[alert_notes[i].id()] = true;
1258 this.deleteCopy = function(row) {
1259 var copy = this.copyCache[row.getAttribute('copy_id')];
1260 copy.isdeleted(true);
1262 delete this.copyCache[copy.id()];
1263 this.copyTbody.removeChild(row);
1266 this._virtDfaCountsAsList = function() {
1268 for (var key in this.virtDfaCounts) {
1269 for (var i = 0; i < this.virtDfaCounts[key]; i++)
1275 this.saveCopyChanges = function(liId) {
1281 for(var id in this.copyCache) {
1282 var c = this.copyCache[id];
1283 if(!c.isdeleted()) total++;
1284 if(c.isnew() || c.ischanged() || c.isdeleted()) {
1285 if(c.id() < 0) c.id(null);
1290 if (typeof(this._copy_count_cb) == "function") {
1291 this._copy_count_cb(liId, total);
1294 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
1297 if (copies.length > 0) {
1298 openils.Util.show("acq-lit-update-copies-progress");
1299 fieldmapper.standardRequest(
1300 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
1302 params: [openils.User.authtoken, copies],
1303 onresponse: function(r) {
1304 var res = openils.Util.readResponse(r);
1305 litUpdateCopiesProgress.update(res);
1307 oncomplete: function() {
1308 self.drawCopies(liId);
1309 openils.Util.hide("acq-lit-update-copies-progress");
1315 var dfa_list = this._virtDfaCountsAsList();
1316 if (dfa_list.length > 0) {
1317 fieldmapper.standardRequest(
1319 "open-ils.acq.distribution_formula.record_application"],
1322 "params": [openils.User.authtoken, dfa_list, liId],
1323 "onresponse": function(r) {
1324 var res = openils.Util.readResponse(r);
1325 if (res && res.length < dfa_list.length)
1326 alert(localeStrings.DFA_NOT_ALL);
1330 this.virtDfaCounts = {};
1334 this.applySelectedLiAction = function(action) {
1338 case 'delete_selected':
1339 this._deleteLiList(self.getSelected());
1342 case 'create_order':
1344 if(!this.createPoProviderSelector) {
1345 var widget = new openils.widget.AutoFieldWidget({
1346 fmField : 'provider',
1348 searchFilter: {"active": "t"},
1349 parentNode : dojo.byId('acq-lit-po-provider'),
1352 function(w) { self.createPoProviderSelector = w; }
1356 if(!this.createPoAgencySelector) {
1357 var widget = new openils.widget.AutoFieldWidget({
1358 fmField : 'ordering_agency',
1360 parentNode : dojo.byId('acq-lit-po-agency'),
1361 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
1364 function(w) { self.createPoAgencySelector = w; }
1369 acqLitPoCreateDialog.show();
1372 case 'save_picklist':
1373 this._loadPLSelect();
1374 acqLitSavePlDialog.show();
1377 case 'selector_ready':
1379 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
1380 acqLitChangeLiStateDialog.show();
1391 case 'rollback_receive_po':
1392 this.rollbackPoReceive();
1395 case 'create_assets':
1396 this.createAssets();
1399 case 'export_attr_list':
1400 this.chooseExportAttr();
1403 case 'add_brief_record':
1405 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
1407 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
1411 this.createAssets = function() {
1412 if(!this.isPO) return;
1413 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
1414 this.show('acq-lit-progress-numbers');
1416 fieldmapper.standardRequest(
1417 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
1419 params: [this.authtoken, this.isPO],
1420 onresponse: function(r) {
1421 var resp = openils.Util.readResponse(r);
1422 self._updateProgressNumbers(resp, true);
1428 this.chooseExportAttr = function() {
1429 if (!acqLitExportAttrSelector._li_setup) {
1431 acqLitExportAttrSelector.store = new dojo.data.ItemFileReadStore(
1433 "data": acqliad.toStoreData(
1435 "acqliad", {"code": li_exportable_attrs}
1440 acqLitExportAttrSelector.setValue();
1441 acqLitExportAttrButton.onClick = function(){self.exportAttrList();};
1442 acqLitExportAttrSelector._li_setup = true;
1444 openils.Util.show("acq-lit-export-attr-holder", "inline");
1447 this.exportAttrList = function() {
1448 var attr_def = acqLitExportAttrSelector.item;
1449 var li_list = this.getSelected();
1450 var value_list = li_list.map(
1452 return (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1453 attr_def.code, "lineitem_marc_attr_definition"
1456 ).filter(function(attr) { return Boolean(attr); });
1458 if (value_list.length > 0) {
1459 if (value_list.length < li_list.length) {
1461 dojo.string.substitute(
1462 localeStrings.EXPORT_SHORT_LIST, [attr_def.description]
1469 openils.XUL.contentToFileSaveDialog(
1470 value_list.join("\n"),
1471 localeStrings.EXPORT_SAVE_DIALOG_TITLE
1477 alert(dojo.string.substitute(
1478 localeStrings.EXPORT_EMPTY_LIST, [attr_def.description]
1482 openils.Util.hide("acq-lit-export-attr-holder");
1485 this.printPO = function() {
1486 if(!this.isPO) return;
1487 progressDialog.show(true);
1488 fieldmapper.standardRequest(
1489 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
1491 params: [this.authtoken, this.isPO, 'html'],
1492 oncomplete: function(r) {
1493 progressDialog.hide();
1494 var evt = openils.Util.readResponse(r);
1495 if(evt && evt.template_output()) {
1496 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
1497 win.document.body.innerHTML = evt.template_output().data();
1505 this.receivePO = function() {
1506 if (!this.isPO) return;
1508 for (var id in this.liCache) {
1509 /* assumption: liCache reflects exactly the
1510 * set of LIs that belong to our PO */
1511 if (this.liCache[id].state() != "received" &&
1512 !this.checkLiAlerts(id)) return;
1515 this.show('acq-lit-progress-numbers');
1517 fieldmapper.standardRequest(
1518 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
1520 params: [this.authtoken, this.isPO],
1521 onresponse : function(r) {
1522 var resp = openils.Util.readResponse(r);
1523 self._updateProgressNumbers(resp, true);
1529 this.issueReceive = function(obj, rollback) {
1530 /* (For now) there shall be no marking LI or LIDs (un)received
1531 * except from the actual "view PO" interface. */
1532 if (!this.isPO) return;
1535 {"jub": "lineitem", "acqlid": "lineitem_detail"}[obj.classname];
1537 "open-ils.acq." + part + ".receive" + (rollback ? ".rollback" : "");
1539 progressDialog.show(true);
1540 fieldmapper.standardRequest(
1541 ["open-ils.acq", method], {
1543 "params": [this.authtoken, obj.id()],
1544 "onresponse": function(r) {
1545 self.handleReceive(openils.Util.readResponse(r));
1547 "oncomplete": function() { progressDialog.hide(); }
1553 * Handles the responses from receive and rollback ML calls.
1555 this.handleReceive = function(resp) {
1558 for (var li_id in resp.li) {
1559 for (var key in resp.li[li_id])
1560 self.liCache[li_id][key](resp.li[li_id][key]);
1561 self.updateLiReceivedness(self.liCache[li_id]);
1565 if (typeof(self.poUpdateCallback) == "function")
1566 self.poUpdateCallback(resp.po);
1569 for (var lid_id in resp.lid) {
1570 for (var key in resp.lid[lid_id])
1571 self.copyCache[lid_id][key](resp.lid[lid_id][key]);
1572 self.updateLidReceivedness(self.copyCache[lid_id]);
1578 this.rollbackPoReceive = function() {
1579 if(!this.isPO) return;
1580 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
1581 this.show('acq-lit-progress-numbers');
1583 fieldmapper.standardRequest(
1584 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
1586 params: [this.authtoken, this.isPO],
1587 onresponse : function(r) {
1588 var resp = openils.Util.readResponse(r);
1589 self._updateProgressNumbers(resp, true);
1595 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1597 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1598 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1599 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1600 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1601 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1602 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1603 if(resp.complete && reloadOnComplete)
1604 location.href = location.href;
1608 this._createPO = function(fields) {
1609 this.show('acq-lit-progress-numbers');
1610 var po = new fieldmapper.acqpo();
1611 po.provider(this.createPoProviderSelector.attr('value'));
1612 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1614 var selected = this.getSelected( (fields.create_from == 'all') );
1615 if(selected.length == 0) return;
1617 var max = selected.length * 3;
1620 fieldmapper.standardRequest(
1621 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1624 openils.User.authtoken,
1627 lineitems : selected.map(function(li) { return li.id() }),
1628 create_assets : fields.create_assets[0],
1632 onresponse : function(r) {
1633 var resp = openils.Util.readResponse(r);
1634 self._updateProgressNumbers(resp);
1636 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1642 this._deleteLiList = function(list, idx) {
1643 if(idx == null) idx = 0;
1644 if(idx >= list.length) return;
1645 var liId = list[idx].id();
1646 fieldmapper.standardRequest(
1647 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1649 params: [openils.User.authtoken, liId],
1650 oncomplete: function(r) {
1651 self.removeLineitem(liId);
1652 self._deleteLiList(list, ++idx);
1658 this.editOrderMarc = function(li) {
1660 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1661 to true in about:config */
1663 if(!openils.XUL.enableXPConnect()) return;
1665 if(openils.XUL.isXUL()) {
1666 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1668 win = window.open('/xul/server/cat/marcedit.xul');
1672 record : {marc : li.marc()},
1674 label: 'Save Record', // XXX I18N
1675 func: function(xmlString) {
1677 fieldmapper.standardRequest(
1678 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1680 params: [openils.User.authtoken, li],
1681 oncomplete: function(r) {
1682 openils.Util.readResponse(r);
1684 self.drawInfo(li.id())
1693 this._savePl = function(values) {
1695 var selected = this.getSelected( (values.which == 'all') );
1696 openils.Util.show('acq-lit-generic-progress');
1698 if(values.new_name) {
1699 openils.acq.Picklist.create(
1700 {name: values.new_name},
1702 self._updateLiList(id, selected, 0,
1704 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1708 } else if(values.existing_pl) {
1709 // update lineitems to use an existing picklist
1710 self._updateLiList(values.existing_pl, selected, 0,
1712 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1717 this._updateLiState = function(values, state) {
1719 var selected = this.getSelected( (values.which == 'all') );
1720 if(!selected.length) return;
1721 dojo.forEach(selected, function(li) {li.state(state);});
1722 self._updateLiList(null, selected, 0,
1723 // TODO consider inline updates for efficiency
1724 function() { location.href = location.href }
1728 this._updateLiList = function(pl, list, idx, oncomplete) {
1729 if(idx >= list.length) return oncomplete();
1731 if(pl != null) li.picklist(pl);
1732 litGenericProgress.update({maximum: list.length, progress: idx});
1733 new openils.acq.Lineitem({lineitem:li}).update(
1735 self._updateLiList(pl, list, ++idx, oncomplete);
1740 this._loadPLSelect = function() {
1741 if(this._plSelectLoaded) return;
1743 function handleResponse(r) {
1744 plList.push(r.recv().content());
1746 var method = 'open-ils.acq.picklist.user.retrieve';
1747 fieldmapper.standardRequest(
1748 ['open-ils.acq', method],
1750 params: [this.authtoken],
1751 onresponse: handleResponse,
1752 oncomplete: function() {
1753 self._plSelectLoaded = true;
1754 acqLitAddExistingSelect.store =
1755 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1756 acqLitAddExistingSelect.setValue();
1762 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1763 this.showRealCopies = function(li) {
1764 while(this.realCopiesTbody.childNodes[0])
1765 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1766 this.show('real-copies');
1768 this.realCopyList = [];
1770 var tabIndex = 1000;
1773 acqLitSaveRealCopies.onClick = function() {
1774 self.saveRealCopies();
1777 this._fetchLineitem(li.id(),
1779 li = self.liCache[li.id()] = fullLi;
1783 id : li.lineitem_details().map(
1784 function(item) { return item.eg_copy_id() }
1789 onresponse : function(r) {
1790 var copy = openils.Util.readResponse(r);
1791 var volId = copy.call_number();
1792 var volume = self.volCache[volId];
1794 volume = self.volCache[volId] = self.pcrud.retrieve('acn', volId);
1796 self.addRealCopy(volume, copy, tabIndex++);
1804 this.addRealCopy = function(volume, copy, tabIndex) {
1805 var row = this.realCopiesRow.cloneNode(true);
1806 this.realCopyList.push(copy);
1810 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1813 var isvol = (field == 'owning_lib' || field == 'label');
1814 var widget = new openils.widget.AutoFieldWidget({
1816 fmObject : isvol ? volume : copy,
1817 parentNode : nodeByName(field, row),
1818 readOnly : (field != 'barcode'),
1821 var widgetDrawn = null;
1823 if(field == 'barcode') {
1825 widgetDrawn = function(w, ww) {
1826 var node = w.domNode;
1827 node.setAttribute('tabindex', ''+tabIndex);
1829 // on enter, select the next barcode input
1830 dojo.connect(w, 'onKeyDown',
1832 if(e.keyCode == dojo.keys.ENTER) {
1833 var ti = node.getAttribute('tabindex');
1834 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1835 if(nextNode) nextNode.select();
1840 dojo.connect(w, 'onChange',
1842 if(!val || val == copy.barcode()) return;
1843 copy.ischanged(true);
1849 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1854 widget.build(widgetDrawn);
1858 this.realCopiesTbody.appendChild(row);
1859 if(selectNode) selectNode.select();
1862 this.saveRealCopies = function() {
1863 progressDialog.show(true);
1864 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1865 this.pcrud.update(list, {oncomplete: function() {
1866 progressDialog.hide();