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'];
26 var fundSearchFormat = ['${0} (${1})', 'code', 'year'];
28 function nodeByName(name, context) {
29 return dojo.query('[name='+name+']', context)[0];
33 var liDetailBatchFields = ['fund', 'owning_lib', 'location', 'collection_code', 'circ_modifier', 'cn_label'];
34 var liDetailFields = liDetailBatchFields.concat(['barcode', 'note']);
36 function AcqLiTable() {
42 this.realDfaCache = {};
43 this.virtDfaCounts = {};
46 this.toggleState = false;
47 this.tbody = dojo.byId('acq-lit-tbody');
50 this.authtoken = openils.User.authtoken;
51 this.pcrud = new openils.PermaCrud();
52 this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
53 this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
54 this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
55 this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
56 this.copyBatchWidgets = {};
57 this.liNotesTbody = dojo.byId('acq-lit-notes-tbody');
58 this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row'));
59 this.realCopiesTbody = dojo.byId('acq-lit-real-copies-tbody');
60 this.realCopiesRow = this.realCopiesTbody.removeChild(dojo.byId('acq-lit-real-copies-row'));
61 this._copy_fields_for_acqdf = ['owning_lib', 'location'];
63 dojo.connect(acqLitLiActionsSelector, 'onChange',
65 self.applySelectedLiAction(this.attr('value'))
66 acqLitLiActionsSelector.attr('value', '_');
69 acqLitCreatePoSubmit.onClick = function() {
70 acqLitPoCreateDialog.hide();
71 self._createPO(acqLitPoCreateDialog.getValues());
74 acqLitSavePlButton.onClick = function() {
75 acqLitSavePlDialog.hide();
76 self._savePl(acqLitSavePlDialog.getValues());
79 acqLitCancelLiStateButton.onClick = function() {
80 acqLitChangeLiStateDialog.hide();
82 acqLitSaveLiStateButton.onClick = function() {
83 acqLitChangeLiStateDialog.hide();
84 self._updateLiState(acqLitChangeLiStateDialog.getValues(), acqLitChangeLiStateDialog.attr('state'));
88 //dojo.byId('acq-lit-notes-new-button').onclick = function(){acqLitCreateLiNoteDialog.show();}
90 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
91 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
92 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
93 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
94 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
96 this.reset = function() {
97 while(self.tbody.childNodes[0])
98 self.tbody.removeChild(self.tbody.childNodes[0]);
103 this.setNext = function(handler) {
104 var link = dojo.byId('acq-lit-next');
106 dojo.style(link, 'visibility', 'visible');
107 link.onclick = handler;
109 dojo.style(link, 'visibility', 'hidden');
113 this.setPrev = function(handler) {
114 var link = dojo.byId('acq-lit-prev');
116 dojo.style(link, 'visibility', 'visible');
117 link.onclick = handler;
119 dojo.style(link, 'visibility', 'hidden');
123 this.show = function(div) {
124 openils.Util.hide('acq-lit-table-div');
125 openils.Util.hide('acq-lit-info-div');
126 openils.Util.hide('acq-lit-li-details');
127 openils.Util.hide('acq-lit-notes-div');
128 openils.Util.hide('acq-lit-real-copies-div');
131 openils.Util.show('acq-lit-table-div');
134 openils.Util.show('acq-lit-info-div');
137 openils.Util.show('acq-lit-li-details');
140 openils.Util.show('acq-lit-real-copies-div');
143 openils.Util.show('acq-lit-notes-div');
147 openils.Util.show(div);
151 this.hide = function() {
155 this.toggleSelect = function() {
157 dojo.forEach(self.selectors, function(i){i.checked = false});
159 dojo.forEach(self.selectors, function(i){i.checked = true});
160 self.toggleState = !self.toggleState;
164 /** @param all If true, assume all are selected */
165 this.getSelected = function(all) {
167 dojo.forEach(self.selectors,
170 selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
176 this.setRowAttr = function(td, liWrapper, field, type) {
177 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
178 td.appendChild(document.createTextNode(val));
182 * Inserts a single lineitem into the growing table of lineitems
183 * @param {Object} li The lineitem object to insert
185 this.addLineitem = function(li, skip_final_placement) {
186 this.liCache[li.id()] = li;
188 // sort the lineitem notes on edit_time
189 if(!li.lineitem_notes()) li.lineitem_notes([]);
191 var liWrapper = new openils.acq.Lineitem({lineitem:li});
192 var row = self.rowTemplate.cloneNode(true);
193 row.setAttribute('li', li.id());
194 var tds = dojo.query('[attr]', row);
195 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
196 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
198 var isbn = liWrapper.findAttr('isbn', 'lineitem_marc_attr_definition');
200 // XXX media prefix for added content
201 dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
204 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
205 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
206 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
208 this.updateLiNotesCount(li, row);
210 // show which PO this lineitem is a member of
211 if(li.purchase_order() && !this.isPO) {
213 this.poCache[li.purchase_order()] =
214 this.poCache[li.purchase_order()] ||
215 fieldmapper.standardRequest(
216 ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
218 this.authtoken, li.purchase_order(), {
219 "flesh_price_summary": true,
220 "flesh_lineitem_count": true
223 if(po && !this.isMeta) {
224 openils.Util.show(nodeByName('po', row), 'inline');
225 var link = nodeByName('po_link', row);
226 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
227 link.innerHTML = 'PO: ' + po.name(); // TODO i18n
231 // show which picklist this lineitem is a member of
232 if(li.picklist() && (this.isPO || this.isMeta)) {
234 this.plCache[li.picklist()] =
235 this.plCache[li.picklist()] ||
236 fieldmapper.standardRequest(
237 ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
238 {params: [this.authtoken, li.picklist()]});
240 openils.Util.show(nodeByName('pl', row), 'inline');
241 var link = nodeByName('pl_link', row);
242 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
243 link.innerHTML = 'PL: '+pl.name(); // TODO i18n
247 var countNode = nodeByName('count', row);
248 var count = li.item_count() || 0;
249 if (typeof(this._copy_count_cb) == "function") {
250 this._copy_count_cb(li.id(), count);
252 countNode.innerHTML = count;
253 countNode.id = 'acq-lit-copy-count-label-' + li.id();
256 nodeByName('li_state', row).innerHTML = li.state(); // TODO i18n state labels
259 var priceInput = dojo.query('[name=price]', row)[0];
260 priceInput.value = li.estimated_unit_price() || '';
261 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
263 // show either "mark received" or "unreceive" as appropriate
264 this.updateLiReceivedness(li, row);
266 if (!skip_final_placement) {
267 self.tbody.appendChild(row);
268 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
274 this.updateLiNotesCount = function(li, row) {
275 if (typeof(row) == "undefined")
276 row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
278 var has_notes = (li.lineitem_notes().filter(
279 function(o) { return Boolean (o.alert_text()); }
282 /* U+2691 is the code point for a filled-in flag character */
283 nodeByName("notes_alert_flag", row).innerHTML =
284 has_notes ? "⚑" : "";
285 nodeByName("noteslink", row).style.fontStyle =
286 has_notes ? "italic" : "normal";
287 nodeByName("notes_count", row).innerHTML = li.lineitem_notes().length;
290 this.updateLiReceivedness = function(li, row) {
291 if (typeof(row) == "undefined")
292 row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
294 var recv_link = nodeByName("receive_link", row);
295 var unrecv_link = nodeByName("unreceive_link", row);
296 var real_copies_link = nodeByName("real_copies_link", row);
298 /* handle row coloring for based on LI state */
299 openils.Util.removeCSSClass(row, /^oils-acq-li-state-/);
300 openils.Util.addCSSClass(row, "oils-acq-li-state-" + li.state());
302 /* handle links that appear/disappear based on whether LI is received */
307 openils.Util.hide(real_copies_link);
308 openils.Util.hide(unrecv_link);
309 openils.Util.show(recv_link, "inline");
310 recv_link.onclick = function() {
311 if (self.checkLiAlerts(li.id()))
312 self.issueReceive(li);
316 openils.Util.hide(recv_link);
317 openils.Util.show(unrecv_link, "inline");
318 unrecv_link.onclick = function() {
319 if (confirm(localeStrings.UNRECEIVE_LI))
320 self.issueReceive(li, /* rollback */ true);
322 // TODO we should allow editing before receipt, in which case the
323 // test should be "if 1 or more real (acp) copies exist
324 openils.Util.show(real_copies_link);
325 real_copies_link.onclick = function() {
326 self.showRealCopyEditUI(li);
332 openils.Util.hide(recv_link);
333 openils.Util.hide(unrecv_link);
334 openils.Util.hide(real_copies_link);
338 this._setAlertStore = function() {
339 acqLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
341 "data": acqliat.toStoreData(
343 "acqliat", {"id": {"!=": null}}
348 acqLitAlertAlertText.setValue(); /* make the store "live" */
349 acqLitAlertAlertText._store_ready = true;
353 * Draws and shows the lineitem notes pane
355 this.drawLiNotes = function(li) {
358 if (!acqLitAlertAlertText._store_ready)
359 this._setAlertStore();
362 li.lineitem_notes().sort(
364 if(a.edit_time() < b.edit_time()) return 1;
370 while(this.liNotesTbody.childNodes[0])
371 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
374 acqLitCreateLiNoteSubmit.onClick = function() {
375 var value = acqLitCreateNoteText.attr('value');
377 var note = new fieldmapper.acqlin();
380 note.lineitem(li.id());
382 self.updateLiNotes(li, note);
385 acqLitCreateAlertSubmit.onClick = function() {
386 if (!acqLitAlertAlertText.item) {
387 alert(localeStrings.ALERT_UNSELECTED);
391 var alert_text = new fieldmapper.acqliat().fromStoreItem(
392 acqLitAlertAlertText.item
394 var value = acqLitAlertNoteValue.attr("value") || "";
396 var note = new fieldmapper.acqlin();
398 note.lineitem(li.id());
400 note.alert_text(alert_text);
402 self.updateLiNotes(li, note);
405 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
409 * Draws a single lineitem note in the notes pane
411 this.addLiNote = function(li, note) {
412 if(note.isdeleted()) return;
414 var row = self.liNotesRow.cloneNode(true);
415 nodeByName("value", row).innerHTML = note.value();
416 var alert_node = nodeByName("alert_code", row);
417 if (note.alert_text()) {
418 alert_node.innerHTML = note.alert_text().code();
419 if (note.alert_text().description()) {
422 "connectId": [alert_node],
423 "label": note.alert_text().description()
424 }, dojo.create("span", null, alert_node, "after")
429 nodeByName("delete", row).onclick = function() {
430 note.isdeleted(true);
431 self.liNotesTbody.removeChild(row);
432 self.updateLiNotes(li);
435 if(note.edit_time()) {
436 nodeByName("edit_time", row).innerHTML =
437 dojo.date.locale.format(
438 dojo.date.stamp.fromISOString(note.edit_time()),
439 {formatLength:'short'});
442 self.liNotesTbody.appendChild(row);
446 * Updates any new/changed/deleted notes on the server
448 this.updateLiNotes = function(li, newNote) {
454 notes = li.lineitem_notes().filter(
456 if(note.ischanged() || note.isnew() || note.isdeleted())
462 if(notes.length == 0) return;
463 progressDialog.show();
465 fieldmapper.standardRequest(
466 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
468 params : [this.authtoken, notes],
469 onresponse : function(r) {
470 var resp = openils.Util.readResponse(r);
475 // remove the old changed notes
477 dojo.forEach(li.lineitem_notes(),
479 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
483 li.lineitem_notes(list);
486 progressDialog.hide();
487 self.updateLiNotesCount(li);
488 self.drawLiNotes(li);
492 progressDialog.update(resp);
493 var newnote = resp.note;
495 if(!newnote.isdeleted()) {
496 newnote.isnew(false);
497 newnote.ischanged(false);
498 li.lineitem_notes().push(newnote);
505 this.updateLiPrice = function(input, li) {
507 var price = input.value;
508 if(Number(price) == Number(li.estimated_unit_price())) return;
510 fieldmapper.standardRequest(
511 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
513 params : [this.authtoken, li.id(), price],
514 oncomplete : function(r) {
515 openils.Util.readResponse(r);
521 this.removeLineitem = function(liId) {
522 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
523 delete this.liCache[liId];
524 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
527 this.drawInfo = function(liId) {
529 openils.acq.Lineitem.fetchAttrDefs(
531 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
536 this._fetchLineitem = function(liId, handler) {
538 var li = this.liCache[liId];
539 if(li && li.marc() && li.lineitem_details())
542 fieldmapper.standardRequest(
543 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
546 params: [self.authtoken, liId, {
548 flesh_li_details: true,
549 flesh_fund_debit: true }],
551 oncomplete: function(r) {
552 var li = openils.Util.readResponse(r);
559 this._drawInfo = function(li) {
561 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
564 openils.Util.hide('acq-lit-marc-order-record-label');
565 openils.Util.hide(acqLitEditOrderMarc.domNode);
566 openils.Util.show('acq-lit-marc-real-record-label');
568 openils.Util.show('acq-lit-marc-order-record-label');
569 openils.Util.show(acqLitEditOrderMarc.domNode);
570 openils.Util.hide('acq-lit-marc-real-record-label');
573 this.drawMarcHTML(li);
574 this.infoTbody = dojo.byId('acq-lit-info-tbody');
577 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
578 while(this.infoTbody.childNodes[0])
579 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
581 for(var i = 0; i < li.attributes().length; i++) {
582 var attr = li.attributes()[i];
583 var row = this.infoRow.cloneNode(true);
585 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
586 var name = openils.acq.Lineitem.attrDefs[type].filter(
588 return (a.code() == attr.attr_name());
590 ).pop().description();
592 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
593 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
594 this.infoTbody.appendChild(row);
598 openils.Util.show('acq-lit-info-cat-link');
599 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
601 if(openils.XUL.isXUL()) {
603 var makeRecTab = function() {
606 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
609 show_nav_buttons : true,
610 show_print_button : true,
611 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
615 link.setAttribute('href', 'javascript:void(0);');
616 link.onclick = makeRecTab;
619 var href = link.getAttribute('href');
621 link.setAttribute('href', href + li.eg_bib_id());
624 openils.Util.hide('acq-lit-info-cat-link');
628 this.drawMarcHTML = function(li) {
629 var params = [null, true, li.marc()];
631 params = [li.eg_bib_id(), true];
633 fieldmapper.standardRequest(
634 ['open-ils.search', 'open-ils.search.biblio.record.html'],
637 oncomplete: function(r) {
638 dojo.byId('acq-lit-marc-div').innerHTML =
639 openils.Util.readResponse(r);
645 this.drawCopies = function(liId) {
649 this.copyWidgetCache = {};
650 this.oldCopyWidgetCache = {};
651 this.virtDfaCounts = {};
652 this.realDfaCache = {};
655 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
656 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
657 acqLitCopyCountInput.attr('value', '0');
659 while(this.copyTbody.childNodes[0])
660 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
662 this._drawBatchCopyWidgets();
664 this._drawDistribApplied(liId);
666 this._fetchDistribFormulas(
668 openils.acq.Lineitem.fetchAttrDefs(
670 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
677 this._saveDistribAppliedTemplates = function() {
678 if (!this._appliedDistribTemplate) {
679 this._appliedDistribTemplate =
680 dojo.byId("acq-lit-distrib-applied-tbody").
681 removeChild(dojo.byId("acq-lit-distrib-applied-row"));
682 dojo.attr(this._appliedDistribTemplate, "id");
686 this._drawDistribApplied = function(liId) {
687 /* Build this table while hidden to prevent rendering artifacts */
688 openils.Util.hide("acq-lit-distrib-applied-tbody");
690 this._saveDistribAppliedTemplates();
692 /* Remove any rows in the table from previous populations */
693 dojo.query("tr[formula]", "acq-lit-distrib-applied-tbody").
694 forEach(dojo.destroy);
696 /* Unregister all dijits previously created (for some reason this isn't
697 * covered by the above destroy calls). */
698 dijit.registry.forEach(
699 function(w) { if (/^dfa-/.test(w.id)) w.destroyRecursive(); }
702 /* Populate the table with our liId */
704 fieldmapper.standardRequest(
706 "open-ils.acq.distribution_formula_application.ranged.retrieve"],
709 "params": [self.authtoken, liId],
710 "onresponse": function(r) {
711 var dfa = openils.Util.readResponse(r);
714 self.realDfaCache[dfa.id()] = dfa;
715 self._drawDistribAppliedUnit(dfa);
718 "oncomplete": function() {
719 /* Reveal built table */
722 "acq-lit-distrib-applied-tbody", "table-row-group"
730 this._drawDistribAppliedUnit = function(dfa) {
732 var row = dojo.query(
733 'tr[formula="' + dfa.formula().id() + '"]',
734 "acq-lit-distrib-applied-tbody"
739 row = dojo.clone(this._appliedDistribTemplate);
740 dojo.attr(row, "formula", dfa.formula().id());
741 dojo.query("th", row)[0].innerHTML = dfa.formula().name();
744 var td = dojo.query("td", row)[0];
746 dojo.create("span", {"id": "dfa-button-" + dfa.id()}, td, "last");
747 dojo.create("span", {"id": "dfa-tip-" + dfa.id()}, td, "last");
750 dojo.place(row, "acq-lit-distrib-applied-tbody", "last");
752 new dijit.form.Button(
754 "onClick": function() {
755 if (confirm(localeStrings.EXPLAIN_DFA_MGMT))
759 /* XXX I /cannot/ make the following work in as a CSS class
760 * for some reason. So frustrating... */
761 "style": function(id) {
763 "font-weight: bold; color: #c00;" :
765 }(dfa.id()) + "margin: 0 6px;display: inline;"
766 }, "dfa-button-" + dfa.id()
770 "connectId": ["dfa-button-" + dfa.id()],
771 "label": dojo.string.substitute(
772 localeStrings.DFA_TIP, dfa.id() > 0 ? [
773 openils.User.formalName(dfa.creator()),
774 dojo.date.locale.format(
775 dojo.date.stamp.fromISOString(dfa.create_time()),
776 {"formatLength":"short"}
778 ] : [localeStrings.ITS_YOU, localeStrings.JUST_NOW]
780 }, "dfa-tip-" + dfa.id()
784 this.deleteDfa = function(dfa) {
785 if (dfa.id() > 0) { /* real */
786 this.pcrud.eliminate(
789 "oncomplete": function() {
790 self._removeDistribApplied(dfa.id());
791 delete self.realDfaCache[dfa.id()];
795 } else { /* virtual */
796 if (--(this.virtDfaCounts[dfa.formula().id()]) < 0)
797 this.virtDfaCounts[dfa.formula().id()] = 0;
798 /* hasn't been saved yet, so no need to do anything server side */
799 this._removeDistribApplied(dfa.id());
804 this._removeDistribApplied = function(dfaId) {
805 var re = new RegExp("^dfa-\\w+-" + String(dfaId));
806 dijit.registry.forEach(
807 function(w) { if (re.test(w.id)) w.destroyRecursive(); }
809 this._removeDistribAppliedEmptyRows();
812 this._removeAllDistribAppliedVirtual = function() {
813 /* Unregister dijits */
814 dijit.registry.forEach(
815 function(w) { if (/^dfa-\w+--/.test(w.id)) w.destroyRecursive(); }
817 this._removeDistribAppliedEmptyRows();
820 this._removeDistribAppliedEmptyRows = function() {
821 /* Remove any rows with no DFA at all */
822 dojo.query("tr[formula] td", "acq-lit-distrib-applied-tbody").forEach(
824 if (o.childNodes.length < 1) dojo.destroy(o.parentNode);
830 * Insert a new row into the distribution formula selection form
832 this._addDistribFormulaRow = function() {
835 if (!self.distribForms) {
836 // no formulas, hide the form
837 openils.Util.hide('acq-lit-distrib-formula-tbody');
841 if(!this.distribFormulaTemplate)
842 this.distribFormulaTemplate =
843 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
845 var row = this.distribFormulaTemplate.cloneNode(true);
846 dojo.place(row, "acq-lit-distrib-formula-tbody", "only");
848 this.dfSelector = new dijit.form.FilteringSelect(
849 {"labelAttr": "dynLabel", "labelType": "html"},
850 nodeByName("selector", row)
852 this._updateFormulaStore();
853 this.dfSelector.fetchProperties =
854 {"sort": [{"attribute": "use_count", "descending": true}]};
856 var apply = new dijit.form.Button(
857 {"label": localeStrings.APPLY},
858 nodeByName('set_button', row)
861 var reset = new dijit.form.Button(
862 {"label": localeStrings.RESET_FORMULAE, "disabled": true},
863 nodeByName("reset_button", row)
866 dojo.connect(apply, 'onClick',
868 var form_id = self.dfSelector.attr("value");
870 self._applyDistribFormula(form_id);
871 reset.attr("disabled", false);
875 dojo.connect(reset, 'onClick',
877 self.restoreCopyFieldsBeforeDF();
878 self.virtDfaCounts = {};
881 self._updateFormulaStore();
882 self._removeAllDistribAppliedVirtual();
883 reset.attr("disabled", "true");
890 * Applies a distrib formula to the current set of copies
892 this._applyDistribFormula = function(formula) {
895 formula = this.distribForms.filter(
896 function(form) { return form.id() == formula; }
899 var copyRows = dojo.query('tr', self.copyTbody);
901 if (this.dfeOffset >= copyRows.length) {
902 alert(localeStrings.OUT_OF_COPIES);
906 var entries_applied = 0;
908 var rowIndex = this.dfeOffset;
909 rowIndex < copyRows.length;
913 var row = copyRows[rowIndex];
914 var copy_id = row.getAttribute('copy_id');
915 var copyWidgets = this.copyWidgetCache[copy_id];
916 var entryIndex = this.dfeOffset;
919 // find the correct entry for the current row
920 dojo.forEach(formula.entries(),
923 entryIndex += e.item_count();
924 if(entryIndex > rowIndex)
932 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
933 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
936 this.saveCopyFieldsBeforeDF(copy_id);
937 this._copy_fields_for_acqdf.forEach(
940 copyWidgets[field].attr('value', (entry[field]()));
947 if (entries_applied) {
948 this.virtDfaCounts[formula.id()] =
949 ++(this.virtDfaCounts[formula.id()]) || 1;
950 this._updateFormulaStore();
951 this._drawDistribAppliedUnit(
953 var dfa = new acqdfa();
954 dfa.formula(df); dfa.id(self.virtDfaId--); return dfa;
957 this.dfeOffset += entries_applied;
962 * This function updates the DF store for the dropdown so that use_counts
963 * can reflect DF applications from this session before they're saved
966 this._updateFormulaStore = function() {
967 this.dfSelector.store = new dojo.data.ItemFileReadStore(
969 "data": self._labelFormulasWithCounts(
970 acqdf.toStoreData(self.distribForms)
976 this.saveCopyFieldsBeforeDF = function(copy_id) {
978 if (!this.oldCopyWidgetCache[copy_id]) {
979 var copyWidgets = this.copyWidgetCache[copy_id];
981 this.oldCopyWidgetCache[copy_id] = {};
982 this._copy_fields_for_acqdf.forEach(
984 self.oldCopyWidgetCache[copy_id][f] =
985 copyWidgets[f].attr("value");
991 this.restoreCopyFieldsBeforeDF = function() {
993 for (var copy_id in this.oldCopyWidgetCache) {
994 this._copy_fields_for_acqdf.forEach(
996 self.copyWidgetCache[copy_id][f].attr(
997 "value", self.oldCopyWidgetCache[copy_id][f]
1004 this._labelFormulasWithCounts = function(store_data) {
1005 for (var key in store_data.items) {
1006 var obj = store_data.items[key];
1007 obj.use_count = Number(obj.use_count); /* needed for sorting */
1009 if (this.virtDfaCounts[obj.id])
1010 obj.use_count = obj.use_count + Number(this.virtDfaCounts[obj.id]);
1012 obj.dynLabel = "<span class='acq-lit-distrib-form-use-count'>[" +
1013 obj.use_count + "]</span> " + obj.name;
1019 * This method formerly would not refetch the DF formulas if they'd been
1020 * loaded already, but now it always re-fetches, since use_count changes.
1022 this._fetchDistribFormulas = function(onload) {
1023 fieldmapper.standardRequest(
1025 "open-ils.acq.distribution_formula.ranged.retrieve.atomic"],
1028 "params": [openils.User.authtoken],
1029 "oncomplete": function(r) {
1030 self.distribForms = openils.Util.readResponse(r);
1031 if(!self.distribForms || self.distribForms.length == 0) {
1032 self.distribForms = [];
1034 self._addDistribFormulaRow();
1041 this._drawBatchCopyWidgets = function() {
1042 var row = this.copyBatchRow;
1043 dojo.forEach(liDetailBatchFields,
1045 if(self.copyBatchRowDrawn) {
1046 self.copyBatchWidgets[field].attr('value', null);
1048 var widget = new openils.widget.AutoFieldWidget({
1051 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1052 searchFormat : (field == 'fund') ? fundSearchFormat : null,
1053 parentNode : dojo.query('[name='+field+']', row)[0],
1054 orgLimitPerms : ['CREATE_PICKLIST'],
1055 dijitArgs : {required:false},
1060 self.copyBatchWidgets[field] = w;
1066 this.copyBatchRowDrawn = true;
1069 this.batchCopyUpdate = function() {
1071 for(var k in this.copyWidgetCache) {
1072 var cache = this.copyWidgetCache[k];
1073 dojo.forEach(liDetailBatchFields, function(f) {
1074 var newval = self.copyBatchWidgets[f].attr('value');
1075 if(newval) cache[f].attr('value', newval);
1080 this._drawCopies = function(li) {
1083 // this button sets the total number of copies for a given lineitem
1084 acqLitAddCopyCount.onClick = function() {
1085 var count = acqLitCopyCountInput.attr('value');
1088 while(self.copyCount() < count)
1091 // delete rows if necessary
1092 var diff = self.copyCount() - count;
1094 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
1095 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
1096 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
1098 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1104 if(li.lineitem_details().length > 0) {
1105 dojo.forEach(li.lineitem_details(),
1107 self.addCopy(li, copy);
1115 this.copyCount = function() {
1117 for(var id in this.copyCache) {
1118 if(!this.copyCache[id].isdeleted())
1124 this.virtCopyId = -1;
1125 this.addCopy = function(li, copy) {
1126 var row = this.copyRow.cloneNode(true);
1127 this.copyTbody.appendChild(row);
1131 copy = new fieldmapper.acqlid();
1133 copy.id(this.virtCopyId--);
1134 copy.lineitem(li.id());
1137 this.copyCache[copy.id()] = copy;
1138 row.setAttribute('copy_id', copy.id());
1139 self.copyWidgetCache[copy.id()] = {};
1141 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1143 dojo.forEach(liDetailFields,
1145 var widget = new openils.widget.AutoFieldWidget({
1148 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1149 searchFormat : (field == 'fund') ? fundSearchFormat : null,
1151 parentNode : dojo.query('[name='+field+']', row)[0],
1152 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
1153 readOnly : Boolean(copy.eg_copy_id())
1156 // make sure we capture the value from any async widgets
1158 copy[field](ww.getFormattedValue())
1159 self.copyWidgetCache[copy.id()][field] = w;
1162 dojo.connect(widget.widget, 'onChange',
1164 if(copy.isnew() || val != copy[field]()) {
1165 // prevent setting ischanged() automatically on widget load for existing copies
1166 copy[field](widget.getFormattedValue())
1167 copy.ischanged(true);
1174 this.updateLidReceivedness(copy, row);
1177 this.updateLidReceivedness = function(copy, row) {
1178 if (typeof(row) == "undefined") {
1180 'tr[copy_id="' + copy.id() + '"]', this.copyTbody
1185 var recv_link = nodeByName("receive", row);
1186 var unrecv_link = nodeByName("unreceive", row);
1187 var del_link = nodeByName("delete", row);
1190 openils.Util.hide(del_link.parentNode);
1192 /* Avoid showing (un)receive links for virtual copies */
1193 if (copy.id() > 0) {
1194 if(copy.recv_time()) {
1195 openils.Util.hide(recv_link);
1196 openils.Util.show(unrecv_link);
1197 unrecv_link.onclick = function() {
1198 if (confirm(localeStrings.UNRECEIVE_LID))
1199 self.issueReceive(copy, /* rollback */ true);
1202 openils.Util.hide(unrecv_link);
1203 openils.Util.show(recv_link);
1204 recv_link.onclick = function() {
1205 if (self.checkLiAlerts(copy.lineitem()))
1206 self.issueReceive(copy);
1210 openils.Util.hide(unrecv_link);
1211 openils.Util.hide(recv_link);
1214 openils.Util.hide(unrecv_link);
1215 openils.Util.hide(recv_link);
1217 del_link.onclick = function() { self.deleteCopy(row) };
1218 openils.Util.show(del_link.parentNode);
1222 this._confirmAlert = function(li, lin) {
1224 dojo.string.substitute(
1225 localeStrings.CONFIRM_LI_ALERT, [
1226 (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1227 "title", "lineitem_marc_attr_definition"
1229 lin.alert_text().code(),
1230 lin.alert_text().description() || "",
1237 this.checkLiAlerts = function(li_id) {
1238 var li = this.liCache[li_id];
1240 var alert_notes = li.lineitem_notes().filter(
1241 function(o) { return Boolean(o.alert_text()); }
1244 /* this is _intentionally_ not done in a call to forEach() ... */
1245 for (var i = 0; i < alert_notes.length; i++) {
1246 if (this.noteAcks[alert_notes[i].id()])
1248 else if (!this._confirmAlert(li, alert_notes[i]))
1251 this.noteAcks[alert_notes[i].id()] = true;
1257 this.deleteCopy = function(row) {
1258 var copy = this.copyCache[row.getAttribute('copy_id')];
1259 copy.isdeleted(true);
1261 delete this.copyCache[copy.id()];
1262 this.copyTbody.removeChild(row);
1265 this._virtDfaCountsAsList = function() {
1267 for (var key in this.virtDfaCounts) {
1268 for (var i = 0; i < this.virtDfaCounts[key]; i++)
1274 this.saveCopyChanges = function(liId) {
1280 for(var id in this.copyCache) {
1281 var c = this.copyCache[id];
1282 if(!c.isdeleted()) total++;
1283 if(c.isnew() || c.ischanged() || c.isdeleted()) {
1284 if(c.id() < 0) c.id(null);
1289 if (typeof(this._copy_count_cb) == "function") {
1290 this._copy_count_cb(liId, total);
1293 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
1296 if (copies.length > 0) {
1297 openils.Util.show("acq-lit-update-copies-progress");
1298 fieldmapper.standardRequest(
1299 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
1301 params: [openils.User.authtoken, copies],
1302 onresponse: function(r) {
1303 var res = openils.Util.readResponse(r);
1304 litUpdateCopiesProgress.update(res);
1306 oncomplete: function() {
1307 self.drawCopies(liId);
1308 openils.Util.hide("acq-lit-update-copies-progress");
1314 var dfa_list = this._virtDfaCountsAsList();
1315 if (dfa_list.length > 0) {
1316 fieldmapper.standardRequest(
1318 "open-ils.acq.distribution_formula.record_application"],
1321 "params": [openils.User.authtoken, dfa_list, liId],
1322 "onresponse": function(r) {
1323 var res = openils.Util.readResponse(r);
1324 if (res && res.length < dfa_list.length)
1325 alert(localeStrings.DFA_NOT_ALL);
1329 this.virtDfaCounts = {};
1333 this.applySelectedLiAction = function(action) {
1337 case 'delete_selected':
1338 this._deleteLiList(self.getSelected());
1341 case 'create_order':
1343 if(!this.createPoProviderSelector) {
1344 var widget = new openils.widget.AutoFieldWidget({
1345 fmField : 'provider',
1347 searchFilter: {"active": "t"},
1348 parentNode : dojo.byId('acq-lit-po-provider'),
1351 function(w) { self.createPoProviderSelector = w; }
1355 if(!this.createPoAgencySelector) {
1356 var widget = new openils.widget.AutoFieldWidget({
1357 fmField : 'ordering_agency',
1359 parentNode : dojo.byId('acq-lit-po-agency'),
1360 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
1363 function(w) { self.createPoAgencySelector = w; }
1368 acqLitPoCreateDialog.show();
1371 case 'save_picklist':
1372 this._loadPLSelect();
1373 acqLitSavePlDialog.show();
1376 case 'selector_ready':
1378 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
1379 acqLitChangeLiStateDialog.show();
1390 case 'rollback_receive_po':
1391 this.rollbackPoReceive();
1394 case 'create_assets':
1395 this.createAssets();
1398 case 'export_attr_list':
1399 this.chooseExportAttr();
1402 case 'add_brief_record':
1404 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
1406 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
1410 this.createAssets = function() {
1411 if(!this.isPO) return;
1412 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
1413 this.show('acq-lit-progress-numbers');
1415 fieldmapper.standardRequest(
1416 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
1418 params: [this.authtoken, this.isPO],
1419 onresponse: function(r) {
1420 var resp = openils.Util.readResponse(r);
1421 self._updateProgressNumbers(resp, true);
1427 this.chooseExportAttr = function() {
1428 if (!acqLitExportAttrSelector._li_setup) {
1430 acqLitExportAttrSelector.store = new dojo.data.ItemFileReadStore(
1432 "data": acqliad.toStoreData(
1434 "acqliad", {"code": li_exportable_attrs}
1439 acqLitExportAttrSelector.setValue();
1440 acqLitExportAttrButton.onClick = function(){self.exportAttrList();};
1441 acqLitExportAttrSelector._li_setup = true;
1443 openils.Util.show("acq-lit-export-attr-holder", "inline");
1446 this.exportAttrList = function() {
1447 var attr_def = acqLitExportAttrSelector.item;
1448 var li_list = this.getSelected();
1449 var value_list = li_list.map(
1451 return (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1452 attr_def.code, "lineitem_marc_attr_definition"
1455 ).filter(function(attr) { return Boolean(attr); });
1457 if (value_list.length > 0) {
1458 if (value_list.length < li_list.length) {
1460 dojo.string.substitute(
1461 localeStrings.EXPORT_SHORT_LIST, [attr_def.description]
1468 openils.XUL.contentToFileSaveDialog(
1469 value_list.join("\n"),
1470 localeStrings.EXPORT_SAVE_DIALOG_TITLE
1476 alert(dojo.string.substitute(
1477 localeStrings.EXPORT_EMPTY_LIST, [attr_def.description]
1481 openils.Util.hide("acq-lit-export-attr-holder");
1484 this.printPO = function() {
1485 if(!this.isPO) return;
1486 progressDialog.show(true);
1487 fieldmapper.standardRequest(
1488 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
1490 params: [this.authtoken, this.isPO, 'html'],
1491 oncomplete: function(r) {
1492 progressDialog.hide();
1493 var evt = openils.Util.readResponse(r);
1494 if(evt && evt.template_output()) {
1495 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
1496 win.document.body.innerHTML = evt.template_output().data();
1504 this.receivePO = function() {
1505 if (!this.isPO) return;
1507 for (var id in this.liCache) {
1508 /* assumption: liCache reflects exactly the
1509 * set of LIs that belong to our PO */
1510 if (this.liCache[id].state() != "received" &&
1511 !this.checkLiAlerts(id)) return;
1514 this.show('acq-lit-progress-numbers');
1516 fieldmapper.standardRequest(
1517 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
1519 params: [this.authtoken, this.isPO],
1520 onresponse : function(r) {
1521 var resp = openils.Util.readResponse(r);
1522 self._updateProgressNumbers(resp, true);
1528 this.issueReceive = function(obj, rollback) {
1529 /* (For now) there shall be no marking LI or LIDs (un)received
1530 * except from the actual "view PO" interface. */
1531 if (!this.isPO) return;
1534 {"jub": "lineitem", "acqlid": "lineitem_detail"}[obj.classname];
1536 "open-ils.acq." + part + ".receive" + (rollback ? ".rollback" : "");
1538 progressDialog.show(true);
1539 fieldmapper.standardRequest(
1540 ["open-ils.acq", method], {
1542 "params": [this.authtoken, obj.id()],
1543 "onresponse": function(r) {
1544 self.handleReceive(openils.Util.readResponse(r));
1546 "oncomplete": function() { progressDialog.hide(); }
1552 * Handles the responses from receive and rollback ML calls.
1554 this.handleReceive = function(resp) {
1557 for (var li_id in resp.li) {
1558 for (var key in resp.li[li_id])
1559 self.liCache[li_id][key](resp.li[li_id][key]);
1560 self.updateLiReceivedness(self.liCache[li_id]);
1564 if (typeof(self.poUpdateCallback) == "function")
1565 self.poUpdateCallback(resp.po);
1568 for (var lid_id in resp.lid) {
1569 for (var key in resp.lid[lid_id])
1570 self.copyCache[lid_id][key](resp.lid[lid_id][key]);
1571 self.updateLidReceivedness(self.copyCache[lid_id]);
1577 this.rollbackPoReceive = function() {
1578 if(!this.isPO) return;
1579 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
1580 this.show('acq-lit-progress-numbers');
1582 fieldmapper.standardRequest(
1583 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
1585 params: [this.authtoken, this.isPO],
1586 onresponse : function(r) {
1587 var resp = openils.Util.readResponse(r);
1588 self._updateProgressNumbers(resp, true);
1594 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1596 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1597 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1598 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1599 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1600 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1601 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1602 if(resp.complete && reloadOnComplete)
1603 location.href = location.href;
1607 this._createPO = function(fields) {
1608 this.show('acq-lit-progress-numbers');
1609 var po = new fieldmapper.acqpo();
1610 po.provider(this.createPoProviderSelector.attr('value'));
1611 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1613 var selected = this.getSelected( (fields.create_from == 'all') );
1614 if(selected.length == 0) return;
1616 var max = selected.length * 3;
1619 fieldmapper.standardRequest(
1620 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1623 openils.User.authtoken,
1626 lineitems : selected.map(function(li) { return li.id() }),
1627 create_assets : fields.create_assets[0],
1631 onresponse : function(r) {
1632 var resp = openils.Util.readResponse(r);
1633 self._updateProgressNumbers(resp);
1635 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1641 this._deleteLiList = function(list, idx) {
1642 if(idx == null) idx = 0;
1643 if(idx >= list.length) return;
1644 var liId = list[idx].id();
1645 fieldmapper.standardRequest(
1646 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1648 params: [openils.User.authtoken, liId],
1649 oncomplete: function(r) {
1650 self.removeLineitem(liId);
1651 self._deleteLiList(list, ++idx);
1657 this.editOrderMarc = function(li) {
1659 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1660 to true in about:config */
1662 if(!openils.XUL.enableXPConnect()) return;
1664 if(openils.XUL.isXUL()) {
1665 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1667 win = window.open('/xul/server/cat/marcedit.xul');
1671 record : {marc : li.marc()},
1673 label: 'Save Record', // XXX I18N
1674 func: function(xmlString) {
1676 fieldmapper.standardRequest(
1677 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1679 params: [openils.User.authtoken, li],
1680 oncomplete: function(r) {
1681 openils.Util.readResponse(r);
1683 self.drawInfo(li.id())
1692 this._savePl = function(values) {
1694 var selected = this.getSelected( (values.which == 'all') );
1695 openils.Util.show('acq-lit-generic-progress');
1697 if(values.new_name) {
1698 openils.acq.Picklist.create(
1699 {name: values.new_name},
1701 self._updateLiList(id, selected, 0,
1703 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1707 } else if(values.existing_pl) {
1708 // update lineitems to use an existing picklist
1709 self._updateLiList(values.existing_pl, selected, 0,
1711 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1716 this._updateLiState = function(values, state) {
1718 var selected = this.getSelected( (values.which == 'all') );
1719 if(!selected.length) return;
1720 dojo.forEach(selected, function(li) {li.state(state);});
1721 self._updateLiList(null, selected, 0,
1722 // TODO consider inline updates for efficiency
1723 function() { location.href = location.href }
1727 this._updateLiList = function(pl, list, idx, oncomplete) {
1728 if(idx >= list.length) return oncomplete();
1730 if(pl != null) li.picklist(pl);
1731 litGenericProgress.update({maximum: list.length, progress: idx});
1732 new openils.acq.Lineitem({lineitem:li}).update(
1734 self._updateLiList(pl, list, ++idx, oncomplete);
1739 this._loadPLSelect = function() {
1740 if(this._plSelectLoaded) return;
1742 function handleResponse(r) {
1743 plList.push(r.recv().content());
1745 var method = 'open-ils.acq.picklist.user.retrieve';
1746 fieldmapper.standardRequest(
1747 ['open-ils.acq', method],
1749 params: [this.authtoken],
1750 onresponse: handleResponse,
1751 oncomplete: function() {
1752 self._plSelectLoaded = true;
1753 acqLitAddExistingSelect.store =
1754 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1755 acqLitAddExistingSelect.setValue();
1761 this.showRealCopyEditUI = function(li) {
1766 this._fetchLineitem(li.id(),
1768 li = self.liCache[li.id()] = fullLi;
1772 id : li.lineitem_details().map(
1773 function(item) { return item.eg_copy_id() }
1777 oncomplete : function(r) {
1779 var r_list = openils.Util.readResponse( r );
1780 for (var i = 0; i < r_list.length; i++) {
1781 var copy = r_list[i];
1782 var volId = copy.call_number();
1783 var volume = self.volCache[volId];
1785 volume = self.volCache[volId] = self.pcrud.retrieve('acn', volId);
1787 copy.call_number(volume);
1788 copyList.push(copy);
1791 // If we need to, we can pass in an update_copy function to handle the update instead of volume_item_creator
1792 xulG.volume_item_creator( { 'existing_copies' : copyList } );
1795 alert('error in oncomplete: ' + E);
1806 this.saveRealCopies = function() {
1807 progressDialog.show(true);
1808 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1809 this.pcrud.update(list, {oncomplete: function() {
1810 progressDialog.hide();
1815 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1816 this.showRealCopies = function(li) {
1817 while(this.realCopiesTbody.childNodes[0])
1818 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1819 this.show('real-copies');
1821 this.realCopyList = [];
1823 var tabIndex = 1000;
1826 acqLitSaveRealCopies.onClick = function() {
1827 self.saveRealCopies();
1830 this._fetchLineitem(li.id(),
1832 li = self.liCache[li.id()] = fullLi;
1836 id : li.lineitem_details().map(
1837 function(item) { return item.eg_copy_id() }
1842 onresponse : function(r) {
1843 var copy = openils.Util.readResponse(r);
1844 var volId = copy.call_number();
1845 var volume = self.volCache[volId];
1847 volume = self.volCache[volId] = self.pcrud.retrieve('acn', volId);
1849 self.addRealCopy(volume, copy, tabIndex++);
1857 this.addRealCopy = function(volume, copy, tabIndex) {
1858 var row = this.realCopiesRow.cloneNode(true);
1859 this.realCopyList.push(copy);
1863 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1866 var isvol = (field == 'owning_lib' || field == 'label');
1867 var widget = new openils.widget.AutoFieldWidget({
1869 fmObject : isvol ? volume : copy,
1870 parentNode : nodeByName(field, row),
1871 readOnly : (field != 'barcode'),
1874 var widgetDrawn = null;
1876 if(field == 'barcode') {
1878 widgetDrawn = function(w, ww) {
1879 var node = w.domNode;
1880 node.setAttribute('tabindex', ''+tabIndex);
1882 // on enter, select the next barcode input
1883 dojo.connect(w, 'onKeyDown',
1885 if(e.keyCode == dojo.keys.ENTER) {
1886 var ti = node.getAttribute('tabindex');
1887 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1888 if(nextNode) nextNode.select();
1893 dojo.connect(w, 'onChange',
1895 if(!val || val == copy.barcode()) return;
1896 copy.ischanged(true);
1902 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1907 widget.build(widgetDrawn);
1911 this.realCopiesTbody.appendChild(row);
1912 if(selectNode) selectNode.select();