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];
274 nodeByName("notes_count", row).innerHTML = li.lineitem_notes().length;
277 this.updateLiReceivedness = function(li, row) {
278 if (typeof(row) == "undefined")
279 row = dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
281 var recv_link = nodeByName("receive_link", row);
282 var unrecv_link = nodeByName("unreceive_link", row);
283 var real_copies_link = nodeByName("real_copies_link", row);
285 /* handle row coloring for based on LI state */
286 openils.Util.removeCSSClass(row, /^oils-acq-li-state-/);
287 openils.Util.addCSSClass(row, "oils-acq-li-state-" + li.state());
289 /* handle links that appear/disappear based on whether LI is received */
294 openils.Util.hide(real_copies_link);
295 openils.Util.hide(unrecv_link);
296 openils.Util.show(recv_link, "inline");
297 recv_link.onclick = function() {
298 if (self.checkLiAlerts(li.id()))
299 self.issueReceive(li);
303 openils.Util.hide(recv_link);
304 openils.Util.show(unrecv_link, "inline");
305 unrecv_link.onclick = function() {
306 if (confirm(localeStrings.UNRECEIVE_LI))
307 self.issueReceive(li, /* rollback */ true);
309 // TODO we should allow editing before receipt, in which case the
310 // test should be "if 1 or more real (acp) copies exist
311 openils.Util.show(real_copies_link);
312 real_copies_link.onclick = function() {
313 self.showRealCopies(li);
319 openils.Util.hide(recv_link);
320 openils.Util.hide(unrecv_link);
321 openils.Util.hide(real_copies_link);
325 this._setAlertStore = function() {
326 acqLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
328 "data": acqliat.toStoreData(
330 "acqliat", {"id": {"!=": null}}
335 acqLitAlertAlertText.setValue(); /* make the store "live" */
336 acqLitAlertAlertText._store_ready = true;
340 * Draws and shows the lineitem notes pane
342 this.drawLiNotes = function(li) {
345 if (!acqLitAlertAlertText._store_ready)
346 this._setAlertStore();
349 li.lineitem_notes().sort(
351 if(a.edit_time() < b.edit_time()) return 1;
357 while(this.liNotesTbody.childNodes[0])
358 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
361 acqLitCreateLiNoteSubmit.onClick = function() {
362 var value = acqLitCreateNoteText.attr('value');
364 var note = new fieldmapper.acqlin();
367 note.lineitem(li.id());
369 self.updateLiNotes(li, note);
372 acqLitCreateAlertSubmit.onClick = function() {
373 if (!acqLitAlertAlertText.item) {
374 alert(localeStrings.ALERT_UNSELECTED);
378 var alert_text = new fieldmapper.acqliat().fromStoreItem(
379 acqLitAlertAlertText.item
381 var value = acqLitAlertNoteValue.attr("value") || "";
383 var note = new fieldmapper.acqlin();
385 note.lineitem(li.id());
387 note.alert_text(alert_text);
389 self.updateLiNotes(li, note);
392 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
396 * Draws a single lineitem note in the notes pane
398 this.addLiNote = function(li, note) {
399 if(note.isdeleted()) return;
401 var row = self.liNotesRow.cloneNode(true);
402 nodeByName("value", row).innerHTML = note.value();
403 if (note.alert_text())
404 nodeByName("alert_code", row).innerHTML = note.alert_text().code();
406 nodeByName("delete", row).onclick = function() {
407 note.isdeleted(true);
408 self.liNotesTbody.removeChild(row);
409 self.updateLiNotes(li);
412 if(note.edit_time()) {
413 nodeByName("edit_time", row).innerHTML =
414 dojo.date.locale.format(
415 dojo.date.stamp.fromISOString(note.edit_time()),
416 {formatLength:'short'});
419 self.liNotesTbody.appendChild(row);
423 * Updates any new/changed/deleted notes on the server
425 this.updateLiNotes = function(li, newNote) {
431 notes = li.lineitem_notes().filter(
433 if(note.ischanged() || note.isnew() || note.isdeleted())
439 if(notes.length == 0) return;
440 progressDialog.show();
442 fieldmapper.standardRequest(
443 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
445 params : [this.authtoken, notes],
446 onresponse : function(r) {
447 var resp = openils.Util.readResponse(r);
452 // remove the old changed notes
454 dojo.forEach(li.lineitem_notes(),
456 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
460 li.lineitem_notes(list);
463 progressDialog.hide();
464 self.updateLiNotesCount(li);
465 self.drawLiNotes(li);
469 progressDialog.update(resp);
470 var newnote = resp.note;
472 if(!newnote.isdeleted()) {
473 newnote.isnew(false);
474 newnote.ischanged(false);
475 li.lineitem_notes().push(newnote);
482 this.updateLiPrice = function(input, li) {
484 var price = input.value;
485 var liWrapper = new openils.acq.Lineitem({lineitem:li});
486 var oldPrice = liWrapper.getPrice() || null;
488 if(oldPrice) oldPrice = oldPrice.price;
489 if(price == oldPrice) return;
491 fieldmapper.standardRequest(
492 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
494 params : [this.authtoken, li.id(), price],
495 oncomplete : function(r) {
496 openils.Util.readResponse(r);
502 this.removeLineitem = function(liId) {
503 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
504 delete this.liCache[liId];
505 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
508 this.drawInfo = function(liId) {
510 openils.acq.Lineitem.fetchAttrDefs(
512 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
517 this._fetchLineitem = function(liId, handler) {
519 var li = this.liCache[liId];
520 if(li && li.marc() && li.lineitem_details())
523 fieldmapper.standardRequest(
524 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
527 params: [self.authtoken, liId, {
529 flesh_li_details: true,
530 flesh_fund_debit: true }],
532 oncomplete: function(r) {
533 var li = openils.Util.readResponse(r);
540 this._drawInfo = function(li) {
542 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
545 openils.Util.hide('acq-lit-marc-order-record-label');
546 openils.Util.hide(acqLitEditOrderMarc.domNode);
547 openils.Util.show('acq-lit-marc-real-record-label');
549 openils.Util.show('acq-lit-marc-order-record-label');
550 openils.Util.show(acqLitEditOrderMarc.domNode);
551 openils.Util.hide('acq-lit-marc-real-record-label');
554 this.drawMarcHTML(li);
555 this.infoTbody = dojo.byId('acq-lit-info-tbody');
558 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
559 while(this.infoTbody.childNodes[0])
560 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
562 for(var i = 0; i < li.attributes().length; i++) {
563 var attr = li.attributes()[i];
564 var row = this.infoRow.cloneNode(true);
566 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
567 var name = openils.acq.Lineitem.attrDefs[type].filter(
569 return (a.code() == attr.attr_name());
571 ).pop().description();
573 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
574 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
575 this.infoTbody.appendChild(row);
579 openils.Util.show('acq-lit-info-cat-link');
580 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
582 if(openils.XUL.isXUL()) {
584 var makeRecTab = function() {
587 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
590 show_nav_buttons : true,
591 show_print_button : true,
592 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
596 link.setAttribute('href', 'javascript:void(0);');
597 link.onclick = makeRecTab;
600 var href = link.getAttribute('href');
602 link.setAttribute('href', href + li.eg_bib_id());
605 openils.Util.hide('acq-lit-info-cat-link');
609 this.drawMarcHTML = function(li) {
610 var params = [null, true, li.marc()];
612 params = [li.eg_bib_id(), true];
614 fieldmapper.standardRequest(
615 ['open-ils.search', 'open-ils.search.biblio.record.html'],
618 oncomplete: function(r) {
619 dojo.byId('acq-lit-marc-div').innerHTML =
620 openils.Util.readResponse(r);
626 this.drawCopies = function(liId) {
630 this.copyWidgetCache = {};
631 this.oldCopyWidgetCache = {};
632 this.virtDfaCounts = {};
633 this.realDfaCache = {};
636 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
637 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
638 acqLitCopyCountInput.attr('value', '0');
640 while(this.copyTbody.childNodes[0])
641 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
643 this._drawBatchCopyWidgets();
645 this._drawDistribApplied(liId);
647 this._fetchDistribFormulas(
649 openils.acq.Lineitem.fetchAttrDefs(
651 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
658 this._saveDistribAppliedTemplates = function() {
659 if (!this._appliedDistribTemplate) {
660 this._appliedDistribTemplate =
661 dojo.byId("acq-lit-distrib-applied-tbody").
662 removeChild(dojo.byId("acq-lit-distrib-applied-row"));
663 dojo.attr(this._appliedDistribTemplate, "id");
667 this._drawDistribApplied = function(liId) {
668 /* Build this table while hidden to prevent rendering artifacts */
669 openils.Util.hide("acq-lit-distrib-applied-tbody");
671 this._saveDistribAppliedTemplates();
673 /* Remove any rows in the table from previous populations */
674 dojo.query("tr[formula]", "acq-lit-distrib-applied-tbody").
675 forEach(dojo.destroy);
677 /* Unregister all dijits previously created (for some reason this isn't
678 * covered by the above destroy calls). */
679 dijit.registry.forEach(
680 function(w) { if (/^dfa-/.test(w.id)) w.destroyRecursive(); }
683 /* Populate the table with our liId */
685 fieldmapper.standardRequest(
687 "open-ils.acq.distribution_formula_application.ranged.retrieve"],
690 "params": [self.authtoken, liId],
691 "onresponse": function(r) {
692 var dfa = openils.Util.readResponse(r);
695 self.realDfaCache[dfa.id()] = dfa;
696 self._drawDistribAppliedUnit(dfa);
699 "oncomplete": function() {
700 /* Reveal built table */
703 "acq-lit-distrib-applied-tbody", "table-row-group"
711 this._drawDistribAppliedUnit = function(dfa) {
713 var row = dojo.query(
714 'tr[formula="' + dfa.formula().id() + '"]',
715 "acq-lit-distrib-applied-tbody"
720 row = dojo.clone(this._appliedDistribTemplate);
721 dojo.attr(row, "formula", dfa.formula().id());
722 dojo.query("th", row)[0].innerHTML = dfa.formula().name();
725 var td = dojo.query("td", row)[0];
727 dojo.create("span", {"id": "dfa-button-" + dfa.id()}, td, "last");
728 dojo.create("span", {"id": "dfa-tip-" + dfa.id()}, td, "last");
731 dojo.place(row, "acq-lit-distrib-applied-tbody", "last");
733 new dijit.form.Button(
735 "onClick": function() {
736 if (confirm(localeStrings.EXPLAIN_DFA_MGMT))
740 /* XXX I /cannot/ make the following work in as a CSS class
741 * for some reason. So frustrating... */
742 "style": function(id) {
744 "font-weight: bold; color: #c00;" :
746 }(dfa.id()) + "margin: 0 6px;display: inline;"
747 }, "dfa-button-" + dfa.id()
751 "connectId": ["dfa-button-" + dfa.id()],
752 "label": dojo.string.substitute(
753 localeStrings.DFA_TIP, dfa.id() > 0 ? [
754 openils.User.formalName(dfa.creator()),
755 dojo.date.locale.format(
756 dojo.date.stamp.fromISOString(dfa.create_time()),
757 {"formatLength":"short"}
759 ] : [localeStrings.ITS_YOU, localeStrings.JUST_NOW]
761 }, "dfa-tip-" + dfa.id()
765 this.deleteDfa = function(dfa) {
766 if (dfa.id() > 0) { /* real */
770 "oncomplete": function() {
771 self._removeDistribApplied(dfa.id());
772 delete self.realDfaCache[dfa.id()];
776 } else { /* virtual */
777 if (--(this.virtDfaCounts[dfa.formula().id()]) < 0)
778 this.virtDfaCounts[dfa.formula().id()] = 0;
779 /* hasn't been saved yet, so no need to do anything server side */
780 this._removeDistribApplied(dfa.id());
785 this._removeDistribApplied = function(dfaId) {
786 var re = new RegExp("^dfa-\\w+-" + String(dfaId));
787 dijit.registry.forEach(
788 function(w) { if (re.test(w.id)) w.destroyRecursive(); }
790 this._removeDistribAppliedEmptyRows();
793 this._removeAllDistribAppliedVirtual = function() {
794 /* Unregister dijits */
795 dijit.registry.forEach(
796 function(w) { if (/^dfa-\w+--/.test(w.id)) w.destroyRecursive(); }
798 this._removeDistribAppliedEmptyRows();
801 this._removeDistribAppliedEmptyRows = function() {
802 /* Remove any rows with no DFA at all */
803 dojo.query("tr[formula] td", "acq-lit-distrib-applied-tbody").forEach(
805 if (o.childNodes.length < 1) dojo.destroy(o.parentNode);
811 * Insert a new row into the distribution formula selection form
813 this._addDistribFormulaRow = function() {
816 if (!self.distribForms) {
817 // no formulas, hide the form
818 openils.Util.hide('acq-lit-distrib-formula-tbody');
822 if(!this.distribFormulaTemplate)
823 this.distribFormulaTemplate =
824 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
826 var row = this.distribFormulaTemplate.cloneNode(true);
827 dojo.place(row, "acq-lit-distrib-formula-tbody", "only");
829 this.dfSelector = new dijit.form.FilteringSelect(
830 {"labelAttr": "dynLabel", "labelType": "html"},
831 nodeByName("selector", row)
833 this._updateFormulaStore();
834 this.dfSelector.fetchProperties =
835 {"sort": [{"attribute": "use_count", "descending": true}]};
837 var apply = new dijit.form.Button(
838 {"label": localeStrings.APPLY},
839 nodeByName('set_button', row)
842 var reset = new dijit.form.Button(
843 {"label": localeStrings.RESET_FORMULAE, "disabled": true},
844 nodeByName("reset_button", row)
847 dojo.connect(apply, 'onClick',
849 var form_id = self.dfSelector.attr("value");
851 self._applyDistribFormula(form_id);
852 reset.attr("disabled", false);
856 dojo.connect(reset, 'onClick',
858 self.restoreCopyFieldsBeforeDF();
859 self.virtDfaCounts = {};
862 self._updateFormulaStore();
863 self._removeAllDistribAppliedVirtual();
864 reset.attr("disabled", "true");
871 * Applies a distrib formula to the current set of copies
873 this._applyDistribFormula = function(formula) {
876 formula = this.distribForms.filter(
877 function(form) { return form.id() == formula; }
880 var copyRows = dojo.query('tr', self.copyTbody);
882 if (this.dfeOffset >= copyRows.length) {
883 alert(localeStrings.OUT_OF_COPIES);
887 var entries_applied = 0;
889 var rowIndex = this.dfeOffset;
890 rowIndex < copyRows.length;
894 var row = copyRows[rowIndex];
895 var copy_id = row.getAttribute('copy_id');
896 var copyWidgets = this.copyWidgetCache[copy_id];
897 var entryIndex = this.dfeOffset;
900 // find the correct entry for the current row
901 dojo.forEach(formula.entries(),
904 entryIndex += e.item_count();
905 if(entryIndex > rowIndex)
913 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
914 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
917 this.saveCopyFieldsBeforeDF(copy_id);
918 this._copy_fields_for_acqdf.forEach(
921 copyWidgets[field].attr('value', (entry[field]()));
928 if (entries_applied) {
929 this.virtDfaCounts[formula.id()] =
930 ++(this.virtDfaCounts[formula.id()]) || 1;
931 this._updateFormulaStore();
932 this._drawDistribAppliedUnit(
934 var dfa = new acqdfa();
935 dfa.formula(df); dfa.id(self.virtDfaId--); return dfa;
938 this.dfeOffset += entries_applied;
943 * This function updates the DF store for the dropdown so that use_counts
944 * can reflect DF applications from this session before they're saved
947 this._updateFormulaStore = function() {
948 this.dfSelector.store = new dojo.data.ItemFileReadStore(
950 "data": self._labelFormulasWithCounts(
951 acqdf.toStoreData(self.distribForms)
957 this.saveCopyFieldsBeforeDF = function(copy_id) {
959 if (!this.oldCopyWidgetCache[copy_id]) {
960 var copyWidgets = this.copyWidgetCache[copy_id];
962 this.oldCopyWidgetCache[copy_id] = {};
963 this._copy_fields_for_acqdf.forEach(
965 self.oldCopyWidgetCache[copy_id][f] =
966 copyWidgets[f].attr("value");
972 this.restoreCopyFieldsBeforeDF = function() {
974 for (var copy_id in this.oldCopyWidgetCache) {
975 this._copy_fields_for_acqdf.forEach(
977 self.copyWidgetCache[copy_id][f].attr(
978 "value", self.oldCopyWidgetCache[copy_id][f]
985 this._labelFormulasWithCounts = function(store_data) {
986 for (var key in store_data.items) {
987 var obj = store_data.items[key];
988 obj.use_count = Number(obj.use_count); /* needed for sorting */
990 if (this.virtDfaCounts[obj.id])
991 obj.use_count = obj.use_count + Number(this.virtDfaCounts[obj.id]);
993 obj.dynLabel = "<span class='acq-lit-distrib-form-use-count'>[" +
994 obj.use_count + "]</span> " + obj.name;
1000 * This method formerly would not refetch the DF formulas if they'd been
1001 * loaded already, but now it always re-fetches, since use_count changes.
1003 this._fetchDistribFormulas = function(onload) {
1004 fieldmapper.standardRequest(
1006 "open-ils.acq.distribution_formula.ranged.retrieve.atomic"],
1009 "params": [openils.User.authtoken],
1010 "oncomplete": function(r) {
1011 self.distribForms = openils.Util.readResponse(r);
1012 if(!self.distribForms || self.distribForms.length == 0) {
1013 self.distribForms = [];
1015 self._addDistribFormulaRow();
1022 this._drawBatchCopyWidgets = function() {
1023 var row = this.copyBatchRow;
1024 dojo.forEach(liDetailBatchFields,
1026 if(self.copyBatchRowDrawn) {
1027 self.copyBatchWidgets[field].attr('value', null);
1029 var widget = new openils.widget.AutoFieldWidget({
1032 parentNode : dojo.query('[name='+field+']', row)[0],
1033 orgLimitPerms : ['CREATE_PICKLIST'],
1034 dijitArgs : {required:false},
1039 self.copyBatchWidgets[field] = w;
1045 this.copyBatchRowDrawn = true;
1048 this.batchCopyUpdate = function() {
1050 for(var k in this.copyWidgetCache) {
1051 var cache = this.copyWidgetCache[k];
1052 dojo.forEach(liDetailBatchFields, function(f) {
1053 var newval = self.copyBatchWidgets[f].attr('value');
1054 if(newval) cache[f].attr('value', newval);
1059 this._drawCopies = function(li) {
1062 // this button sets the total number of copies for a given lineitem
1063 acqLitAddCopyCount.onClick = function() {
1064 var count = acqLitCopyCountInput.attr('value');
1067 while(self.copyCount() < count)
1070 // delete rows if necessary
1071 var diff = self.copyCount() - count;
1073 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
1074 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
1075 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
1077 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1083 if(li.lineitem_details().length > 0) {
1084 dojo.forEach(li.lineitem_details(),
1086 self.addCopy(li, copy);
1094 this.copyCount = function() {
1096 for(var id in this.copyCache) {
1097 if(!this.copyCache[id].isdeleted())
1103 this.virtCopyId = -1;
1104 this.addCopy = function(li, copy) {
1105 var row = this.copyRow.cloneNode(true);
1106 this.copyTbody.appendChild(row);
1110 copy = new fieldmapper.acqlid();
1112 copy.id(this.virtCopyId--);
1113 copy.lineitem(li.id());
1116 this.copyCache[copy.id()] = copy;
1117 row.setAttribute('copy_id', copy.id());
1118 self.copyWidgetCache[copy.id()] = {};
1120 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1122 dojo.forEach(liDetailFields,
1124 var widget = new openils.widget.AutoFieldWidget({
1128 parentNode : dojo.query('[name='+field+']', row)[0],
1129 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
1130 readOnly : Boolean(copy.eg_copy_id())
1133 // make sure we capture the value from any async widgets
1135 copy[field](ww.getFormattedValue())
1136 self.copyWidgetCache[copy.id()][field] = w;
1139 dojo.connect(widget.widget, 'onChange',
1141 if(copy.isnew() || val != copy[field]()) {
1142 // prevent setting ischanged() automatically on widget load for existing copies
1143 copy[field](widget.getFormattedValue())
1144 copy.ischanged(true);
1151 this.updateLidReceivedness(copy, row);
1154 this.updateLidReceivedness = function(copy, row) {
1155 if (typeof(row) == "undefined") {
1157 'tr[copy_id="' + copy.id() + '"]', this.copyTbody
1162 var recv_link = nodeByName("receive", row);
1163 var unrecv_link = nodeByName("unreceive", row);
1164 var del_link = nodeByName("delete", row);
1167 openils.Util.hide(del_link.parentNode);
1169 /* Avoid showing (un)receive links for virtual copies */
1170 if (copy.id() > 0) {
1171 if(copy.recv_time()) {
1172 openils.Util.hide(recv_link);
1173 openils.Util.show(unrecv_link);
1174 unrecv_link.onclick = function() {
1175 if (confirm(localeStrings.UNRECEIVE_LID))
1176 self.issueReceive(copy, /* rollback */ true);
1179 openils.Util.hide(unrecv_link);
1180 openils.Util.show(recv_link);
1181 recv_link.onclick = function() {
1182 if (self.checkLiAlerts(copy.lineitem()))
1183 self.issueReceive(copy);
1187 openils.Util.hide(unrecv_link);
1188 openils.Util.hide(recv_link);
1191 openils.Util.hide(unrecv_link);
1192 openils.Util.hide(recv_link);
1194 del_link.onclick = function() { self.deleteCopy(row) };
1195 openils.Util.show(del_link.parentNode);
1199 this._confirmAlert = function(li, lin) {
1201 dojo.string.substitute(
1202 localeStrings.CONFIRM_LI_ALERT, [
1203 (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1204 "title", "lineitem_marc_attr_definition"
1206 lin.alert_text().code(),
1207 lin.alert_text().description() || "",
1214 this.checkLiAlerts = function(li_id) {
1215 var li = this.liCache[li_id];
1217 var alert_notes = li.lineitem_notes().filter(
1218 function(o) { return Boolean(o.alert_text()); }
1221 /* this is _intentionally_ not done in a call to forEach() ... */
1222 for (var i = 0; i < alert_notes.length; i++) {
1223 if (this.noteAcks[alert_notes[i].id()])
1225 else if (!this._confirmAlert(li, alert_notes[i]))
1228 this.noteAcks[alert_notes[i].id()] = true;
1234 this.deleteCopy = function(row) {
1235 var copy = this.copyCache[row.getAttribute('copy_id')];
1236 copy.isdeleted(true);
1238 delete this.copyCache[copy.id()];
1239 this.copyTbody.removeChild(row);
1242 this._virtDfaCountsAsList = function() {
1244 for (var key in this.virtDfaCounts) {
1245 for (var i = 0; i < this.virtDfaCounts[key]; i++)
1251 this.saveCopyChanges = function(liId) {
1257 for(var id in this.copyCache) {
1258 var c = this.copyCache[id];
1259 if(!c.isdeleted()) total++;
1260 if(c.isnew() || c.ischanged() || c.isdeleted()) {
1261 if(c.id() < 0) c.id(null);
1266 if (typeof(this._copy_count_cb) == "function") {
1267 this._copy_count_cb(liId, total);
1270 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
1273 if (copies.length > 0) {
1274 openils.Util.show("acq-lit-update-copies-progress");
1275 fieldmapper.standardRequest(
1276 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
1278 params: [openils.User.authtoken, copies],
1279 onresponse: function(r) {
1280 var res = openils.Util.readResponse(r);
1281 litUpdateCopiesProgress.update(res);
1283 oncomplete: function() {
1284 self.drawCopies(liId);
1285 openils.Util.hide("acq-lit-update-copies-progress");
1291 var dfa_list = this._virtDfaCountsAsList();
1292 if (dfa_list.length > 0) {
1293 fieldmapper.standardRequest(
1295 "open-ils.acq.distribution_formula.record_application"],
1298 "params": [openils.User.authtoken, dfa_list, liId],
1299 "onresponse": function(r) {
1300 var res = openils.Util.readResponse(r);
1301 if (res && res.length < dfa_list.length)
1302 alert(localeStrings.DFA_NOT_ALL);
1306 this.virtDfaCounts = {};
1310 this.applySelectedLiAction = function(action) {
1314 case 'delete_selected':
1315 this._deleteLiList(self.getSelected());
1318 case 'create_order':
1320 if(!this.createPoProviderSelector) {
1321 var widget = new openils.widget.AutoFieldWidget({
1322 fmField : 'provider',
1324 searchFilter: {"active": "t"},
1325 parentNode : dojo.byId('acq-lit-po-provider'),
1328 function(w) { self.createPoProviderSelector = w; }
1332 if(!this.createPoAgencySelector) {
1333 var widget = new openils.widget.AutoFieldWidget({
1334 fmField : 'ordering_agency',
1336 parentNode : dojo.byId('acq-lit-po-agency'),
1337 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
1340 function(w) { self.createPoAgencySelector = w; }
1345 acqLitPoCreateDialog.show();
1348 case 'save_picklist':
1349 this._loadPLSelect();
1350 acqLitSavePlDialog.show();
1353 case 'selector_ready':
1355 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
1356 acqLitChangeLiStateDialog.show();
1367 case 'rollback_receive_po':
1368 this.rollbackPoReceive();
1371 case 'create_assets':
1372 this.createAssets();
1375 case 'export_attr_list':
1376 this.chooseExportAttr();
1379 case 'add_brief_record':
1381 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
1383 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
1387 this.createAssets = function() {
1388 if(!this.isPO) return;
1389 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
1390 this.show('acq-lit-progress-numbers');
1392 fieldmapper.standardRequest(
1393 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
1395 params: [this.authtoken, this.isPO],
1396 onresponse: function(r) {
1397 var resp = openils.Util.readResponse(r);
1398 self._updateProgressNumbers(resp, true);
1404 this.chooseExportAttr = function() {
1405 if (!acqLitExportAttrSelector._li_setup) {
1407 acqLitExportAttrSelector.store = new dojo.data.ItemFileReadStore(
1409 "data": acqliad.toStoreData(
1411 "acqliad", {"code": li_exportable_attrs}
1416 acqLitExportAttrSelector.setValue();
1417 acqLitExportAttrButton.onClick = function(){self.exportAttrList();};
1418 acqLitExportAttrSelector._li_setup = true;
1420 openils.Util.show("acq-lit-export-attr-holder", "inline");
1423 this.exportAttrList = function() {
1424 var attr_def = acqLitExportAttrSelector.item;
1425 var li_list = this.getSelected();
1426 var value_list = li_list.map(
1428 return (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1429 attr_def.code, "lineitem_marc_attr_definition"
1432 ).filter(function(attr) { return Boolean(attr); });
1434 if (value_list.length > 0) {
1435 if (value_list.length < li_list.length) {
1437 dojo.string.substitute(
1438 localeStrings.EXPORT_SHORT_LIST, [attr_def.description]
1445 openils.XUL.contentToFileSaveDialog(
1446 value_list.join("\n"),
1447 localeStrings.EXPORT_SAVE_DIALOG_TITLE
1453 alert(dojo.string.substitute(
1454 localeStrings.EXPORT_EMPTY_LIST, [attr_def.description]
1458 openils.Util.hide("acq-lit-export-attr-holder");
1461 this.printPO = function() {
1462 if(!this.isPO) return;
1463 progressDialog.show(true);
1464 fieldmapper.standardRequest(
1465 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
1467 params: [this.authtoken, this.isPO, 'html'],
1468 oncomplete: function(r) {
1469 progressDialog.hide();
1470 var evt = openils.Util.readResponse(r);
1471 if(evt && evt.template_output()) {
1472 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
1473 win.document.body.innerHTML = evt.template_output().data();
1481 this.receivePO = function() {
1482 if (!this.isPO) return;
1484 for (var id in this.liCache) {
1485 /* assumption: liCache reflects exactly the
1486 * set of LIs that belong to our PO */
1487 if (this.liCache[id].state() != "received" &&
1488 !this.checkLiAlerts(id)) return;
1491 this.show('acq-lit-progress-numbers');
1493 fieldmapper.standardRequest(
1494 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
1496 params: [this.authtoken, this.isPO],
1497 onresponse : function(r) {
1498 var resp = openils.Util.readResponse(r);
1499 self._updateProgressNumbers(resp, true);
1505 this.issueReceive = function(obj, rollback) {
1506 /* (For now) there shall be no marking LI or LIDs (un)received
1507 * except from the actual "view PO" interface. */
1508 if (!this.isPO) return;
1511 {"jub": "lineitem", "acqlid": "lineitem_detail"}[obj.classname];
1513 "open-ils.acq." + part + ".receive" + (rollback ? ".rollback" : "");
1515 progressDialog.show(true);
1516 fieldmapper.standardRequest(
1517 ["open-ils.acq", method], {
1519 "params": [this.authtoken, obj.id()],
1520 "onresponse": function(r) {
1521 self.handleReceive(openils.Util.readResponse(r));
1523 "oncomplete": function() { progressDialog.hide(); }
1529 * Handles the responses from receive and rollback ML calls.
1531 this.handleReceive = function(resp) {
1534 for (var li_id in resp.li) {
1535 for (var key in resp.li[li_id])
1536 self.liCache[li_id][key](resp.li[li_id][key]);
1537 self.updateLiReceivedness(self.liCache[li_id]);
1541 if (typeof(self.poUpdateCallback) == "function")
1542 self.poUpdateCallback(resp.po);
1545 for (var lid_id in resp.lid) {
1546 for (var key in resp.lid[lid_id])
1547 self.copyCache[lid_id][key](resp.lid[lid_id][key]);
1548 self.updateLidReceivedness(self.copyCache[lid_id]);
1554 this.rollbackPoReceive = function() {
1555 if(!this.isPO) return;
1556 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
1557 this.show('acq-lit-progress-numbers');
1559 fieldmapper.standardRequest(
1560 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
1562 params: [this.authtoken, this.isPO],
1563 onresponse : function(r) {
1564 var resp = openils.Util.readResponse(r);
1565 self._updateProgressNumbers(resp, true);
1571 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1573 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1574 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1575 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1576 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1577 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1578 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1579 if(resp.complete && reloadOnComplete)
1580 location.href = location.href;
1584 this._createPO = function(fields) {
1585 this.show('acq-lit-progress-numbers');
1586 var po = new fieldmapper.acqpo();
1587 po.provider(this.createPoProviderSelector.attr('value'));
1588 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1590 var selected = this.getSelected( (fields.create_from == 'all') );
1591 if(selected.length == 0) return;
1593 var max = selected.length * 3;
1596 fieldmapper.standardRequest(
1597 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1600 openils.User.authtoken,
1603 lineitems : selected.map(function(li) { return li.id() }),
1604 create_assets : fields.create_assets[0],
1608 onresponse : function(r) {
1609 var resp = openils.Util.readResponse(r);
1610 self._updateProgressNumbers(resp);
1612 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1618 this._deleteLiList = function(list, idx) {
1619 if(idx == null) idx = 0;
1620 if(idx >= list.length) return;
1621 var liId = list[idx].id();
1622 fieldmapper.standardRequest(
1623 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1625 params: [openils.User.authtoken, liId],
1626 oncomplete: function(r) {
1627 self.removeLineitem(liId);
1628 self._deleteLiList(list, ++idx);
1634 this.editOrderMarc = function(li) {
1636 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1637 to true in about:config */
1639 if(!openils.XUL.enableXPConnect()) return;
1641 if(openils.XUL.isXUL()) {
1642 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1644 win = window.open('/xul/server/cat/marcedit.xul');
1648 record : {marc : li.marc()},
1650 label: 'Save Record', // XXX I18N
1651 func: function(xmlString) {
1653 fieldmapper.standardRequest(
1654 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1656 params: [openils.User.authtoken, li],
1657 oncomplete: function(r) {
1658 openils.Util.readResponse(r);
1660 self.drawInfo(li.id())
1669 this._savePl = function(values) {
1671 var selected = this.getSelected( (values.which == 'all') );
1672 openils.Util.show('acq-lit-generic-progress');
1674 if(values.new_name) {
1675 openils.acq.Picklist.create(
1676 {name: values.new_name},
1678 self._updateLiList(id, selected, 0,
1680 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1684 } else if(values.existing_pl) {
1685 // update lineitems to use an existing picklist
1686 self._updateLiList(values.existing_pl, selected, 0,
1688 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1693 this._updateLiState = function(values, state) {
1695 var selected = this.getSelected( (values.which == 'all') );
1696 if(!selected.length) return;
1697 dojo.forEach(selected, function(li) {li.state(state);});
1698 self._updateLiList(null, selected, 0,
1699 // TODO consider inline updates for efficiency
1700 function() { location.href = location.href }
1704 this._updateLiList = function(pl, list, idx, oncomplete) {
1705 if(idx >= list.length) return oncomplete();
1707 if(pl != null) li.picklist(pl);
1708 litGenericProgress.update({maximum: list.length, progress: idx});
1709 new openils.acq.Lineitem({lineitem:li}).update(
1711 self._updateLiList(pl, list, ++idx, oncomplete);
1716 this._loadPLSelect = function() {
1717 if(this._plSelectLoaded) return;
1719 function handleResponse(r) {
1720 plList.push(r.recv().content());
1722 var method = 'open-ils.acq.picklist.user.retrieve';
1723 fieldmapper.standardRequest(
1724 ['open-ils.acq', method],
1726 params: [this.authtoken],
1727 onresponse: handleResponse,
1728 oncomplete: function() {
1729 self._plSelectLoaded = true;
1730 acqLitAddExistingSelect.store =
1731 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1732 acqLitAddExistingSelect.setValue();
1738 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1739 this.showRealCopies = function(li) {
1740 while(this.realCopiesTbody.childNodes[0])
1741 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1742 this.show('real-copies');
1744 this.realCopyList = [];
1746 var tabIndex = 1000;
1749 acqLitSaveRealCopies.onClick = function() {
1750 self.saveRealCopies();
1753 this._fetchLineitem(li.id(),
1755 li = self.liCache[li.id()] = fullLi;
1759 id : li.lineitem_details().map(
1760 function(item) { return item.eg_copy_id() }
1765 onresponse : function(r) {
1766 var copy = openils.Util.readResponse(r);
1767 var volId = copy.call_number();
1768 var volume = self.volCache[volId];
1770 volume = self.volCache[volId] = self.pcrud.retrieve('acn', volId);
1772 self.addRealCopy(volume, copy, tabIndex++);
1780 this.addRealCopy = function(volume, copy, tabIndex) {
1781 var row = this.realCopiesRow.cloneNode(true);
1782 this.realCopyList.push(copy);
1786 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1789 var isvol = (field == 'owning_lib' || field == 'label');
1790 var widget = new openils.widget.AutoFieldWidget({
1792 fmObject : isvol ? volume : copy,
1793 parentNode : nodeByName(field, row),
1794 readOnly : (field != 'barcode'),
1797 var widgetDrawn = null;
1799 if(field == 'barcode') {
1801 widgetDrawn = function(w, ww) {
1802 var node = w.domNode;
1803 node.setAttribute('tabindex', ''+tabIndex);
1805 // on enter, select the next barcode input
1806 dojo.connect(w, 'onKeyDown',
1808 if(e.keyCode == dojo.keys.ENTER) {
1809 var ti = node.getAttribute('tabindex');
1810 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1811 if(nextNode) nextNode.select();
1816 dojo.connect(w, 'onChange',
1818 if(!val || val == copy.barcode()) return;
1819 copy.ischanged(true);
1825 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1830 widget.build(widgetDrawn);
1834 this.realCopiesTbody.appendChild(row);
1835 if(selectNode) selectNode.select();
1838 this.saveRealCopies = function() {
1839 progressDialog.show(true);
1840 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1841 this.pcrud.update(list, {oncomplete: function() {
1842 progressDialog.hide();