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.acq.Lineitem');
10 dojo.require('openils.acq.PO');
11 dojo.require('openils.acq.Picklist');
12 dojo.require('openils.widget.AutoFieldWidget');
13 dojo.require('dojo.data.ItemFileReadStore');
14 dojo.require('openils.widget.ProgressDialog');
15 dojo.require('openils.PermaCrud');
16 dojo.require("openils.widget.PCrudAutocompleteBox");
18 if (!localeStrings) { /* we can do this because javascript doesn't have block scope */
19 dojo.requireLocalization('openils.acq', 'acq');
20 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 = [
26 '<span class="fund_${0}">${1} (${2})</span>', 'id', 'code', 'year'
28 var fundSearchFormat = ['${0} (${1})', 'code', 'year'];
30 function nodeByName(name, context) {
31 return dojo.query('[name='+name+']', context)[0];
34 // for caching linked users. e.g. lineitem_detail.receiver
37 var liDetailBatchFields = ['fund', 'owning_lib', 'location', 'collection_code', 'circ_modifier', 'cn_label'];
38 var liDetailFields = liDetailBatchFields.concat(['barcode', 'note']);
40 "stop": "color: #c00; font-weight: bold;",
41 "warning": "color: #c93;"
44 function AcqLiTable() {
51 this.haveFundClass = {}
52 this.fundBalanceState = {};
53 this.realDfaCache = {};
54 this.virtDfaCounts = {};
57 this.claimEligibleLidByLi = {};
58 this.claimEligibleLid = {};
59 this.toggleState = false;
60 this.tbody = dojo.byId('acq-lit-tbody');
63 this.authtoken = openils.User.authtoken;
64 this.pcrud = new openils.PermaCrud();
65 this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
66 this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
67 this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
68 this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
69 this.copyBatchWidgets = {};
70 this.liNotesTbody = dojo.byId('acq-lit-notes-tbody');
71 this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row'));
72 this.realCopiesTbody = dojo.byId('acq-lit-real-copies-tbody');
73 this.realCopiesRow = this.realCopiesTbody.removeChild(dojo.byId('acq-lit-real-copies-row'));
74 this._copy_fields_for_acqdf = ['owning_lib', 'location'];
75 this.skipInitialEligibilityCheck = false;
76 this.claimDialog = new ClaimDialogManager(
77 liClaimDialog, finalClaimDialog, this.claimEligibleLidByLi,
78 function(li) { /* callback that fires when claims are made */
79 self.fetchClaimInfo(li.id(), /* force update */ true);
83 dojo.byId("acq-lit-li-actions-selector").onchange = function() {
84 self.applySelectedLiAction(this.options[this.selectedIndex].value);
85 this.selectedIndex = 0;
88 acqLitCreatePoSubmit.onClick = function() {
89 if (self._confirmPoPrepaySituation()) {
90 acqLitPoCreateDialog.hide();
91 self._createPO(acqLitPoCreateDialog.getValues());
97 acqLitSavePlButton.onClick = function() {
98 acqLitSavePlDialog.hide();
99 self._savePl(acqLitSavePlDialog.getValues());
102 acqLitCancelLiStateButton.onClick = function() {
103 acqLitChangeLiStateDialog.hide();
105 acqLitSaveLiStateButton.onClick = function() {
106 acqLitChangeLiStateDialog.hide();
107 self._updateLiState(acqLitChangeLiStateDialog.getValues(), acqLitChangeLiStateDialog.attr('state'));
111 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
112 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
113 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
114 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
115 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
117 this.reset = function(keep_selectors) {
118 while(self.tbody.childNodes[0])
119 self.tbody.removeChild(self.tbody.childNodes[0]);
127 this.setNext = function(handler) {
128 var link = dojo.byId('acq-lit-next');
130 dojo.style(link, 'visibility', 'visible');
131 link.onclick = handler;
133 dojo.style(link, 'visibility', 'hidden');
137 this.setPrev = function(handler) {
138 var link = dojo.byId('acq-lit-prev');
140 dojo.style(link, 'visibility', 'visible');
141 link.onclick = handler;
143 dojo.style(link, 'visibility', 'hidden');
147 this.show = function(div) {
148 openils.Util.hide('acq-lit-table-div');
149 openils.Util.hide('acq-lit-info-div');
150 openils.Util.hide('acq-lit-li-details');
151 openils.Util.hide('acq-lit-notes-div');
152 openils.Util.hide('acq-lit-real-copies-div');
155 openils.Util.show('acq-lit-table-div');
158 openils.Util.show('acq-lit-info-div');
161 openils.Util.show('acq-lit-li-details');
164 openils.Util.show('acq-lit-real-copies-div');
167 openils.Util.show('acq-lit-notes-div');
171 openils.Util.show(div);
175 this.hide = function() {
179 this.toggleSelect = function() {
181 dojo.forEach(self.selectors, function(i){i.checked = false});
183 dojo.forEach(self.selectors, function(i){i.checked = true});
184 self.toggleState = !self.toggleState;
188 this.getAll = function(callback, id_only) {
189 /* For some uses of the li table, we may not really know about "all"
190 * the lineitems that the user thinks we know about. If we're a paged
191 * picklist, for example, we only know about the lineitems we've
192 * displayed, but not necessarily all the lineitems on the picklist.
193 * So we reach out to pcrud to inform us.
196 var oncomplete = function(r) {
197 var id_list = openils.Util.readResponse(r);
201 self.fetchLineitemsById(id_list, callback);
206 "jub", {"picklist": this.isPL}, {
207 "id_list": true, /* sic, even if id_only */
209 "oncomplete": oncomplete
213 } else if (this.isPO) {
215 "jub", {"purchase_order": this.isPO}, {
218 "oncomplete": oncomplete
222 } else if (this.isUni && this.pager) {
223 this.pager.getAllLineitemIDs(oncomplete);
227 /* If execution reaches this point, we don't need or can't perform
228 * any special tricks to find out the "real" list of "all" lineitems
229 * in this context, so we fall back to the old method.
231 callback(this.getSelected(true, null, id_only));
234 /** @param all If true, assume all are selected */
235 this.getSelected = function(
237 callback /* If you want a "good" idea of "all" lineitems, you must
238 provide a callback that accepts an array parameter, rather than
239 relying on the return value of this method itself. */,
243 return this.getAll(callback, id_only);
245 var indices = {}; /* use to uniqify. needed in paging situations. */
246 dojo.forEach(this.selectors,
249 indices[i.parentNode.parentNode.getAttribute('li')] = true;
253 var result = openils.Util.objectProperties(indices);
256 result = result.map(function(liId) { return self.liCache[liId]; });
264 this.setRowAttr = function(td, liWrapper, field, type) {
265 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
266 td.appendChild(document.createTextNode(val));
269 this.setClaimPolicyControl = function(li, row) {
270 if (!self.claimPolicyPicker) {
271 self.claimPolicyPicker = true; /* prevents a race condition */
272 new openils.widget.AutoFieldWidget({
273 "parentNode": "acq-lit-li-claim-policy",
275 "selfReference": true,
276 "dijitArgs": {"required": true}
277 }).build(function(w) { self.claimPolicyPicker = w; });
280 if (!row) row = this._findLiRow(li);
282 var actViewPolicy = nodeByName("action_view_claim_policy", row);
283 if (li.claim_policy())
284 actViewPolicy.innerHTML = localeStrings.CHANGE_CLAIM_POLICY;
286 if (!actViewPolicy.onclick) {
287 actViewPolicy.onclick = function() {
288 if (li.claim_policy())
289 self.claimPolicyPicker.attr("value", li.claim_policy());
290 liClaimPolicyDialog.show();
291 liClaimPolicySave.onClick = function() {
292 self.changeClaimPolicy(
293 [li], self.claimPolicyPicker.attr("value"),
295 self.setClaimPolicyControl(li, row);
296 self.reconsiderClaimControl(li, row);
297 liClaimPolicyDialog.hide();
305 this.fetchClaimInfo = function(liId, force, callback, row) {
307 liId, function(full) {
308 self.liCache[full.id()] = full;
309 self.checkClaimEligibility(full, callback, row);
315 * Inserts a single lineitem into the growing table of lineitems
316 * @param {Object} li The lineitem object to insert
318 this.addLineitem = function(li, skip_final_placement) {
319 this.liCache[li.id()] = li;
321 // insert the row right away so that final order isn't
322 // dependent on how long subsequent async request take
323 // for a given line item
324 var row = self.rowTemplate.cloneNode(true);
325 if (!skip_final_placement) {
326 self.tbody.appendChild(row);
328 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
330 // sort the lineitem notes on edit_time
331 if(!li.lineitem_notes()) li.lineitem_notes([]);
333 var liWrapper = new openils.acq.Lineitem({lineitem:li});
334 row.setAttribute('li', li.id());
335 var tds = dojo.query('[attr]', row);
336 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
337 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
340 liWrapper.findAttr("isbn", "lineitem_marc_attr_definition") ||
341 liWrapper.findAttr("upc", "lineitem_marc_attr_definition");
343 // XXX media prefix for added content
345 nodeByName("jacket", row).setAttribute(
346 "src", "/opac/extras/ac/jacket/small/" + identifier
350 nodeByName("liid", row).innerHTML += li.id();
353 openils.Util.show(nodeByName('catalog', row), 'inline');
354 nodeByName("catalog_link", row).onclick = this.generateMakeRecTab(li.eg_bib_id());
356 openils.Util.show(nodeByName('link_to_catalog', row), 'inline');
357 nodeByName("link_to_catalog_link", row).onclick = function() { self.drawBibFinder(li) };
360 nodeByName("worksheet_link", row).href =
361 oilsBasePath + "/acq/lineitem/worksheet/" + li.id();
363 nodeByName("show_requests_link", row).href =
364 oilsBasePath + "/acq/picklist/user_request?lineitem=" + li.id();
366 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
367 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
368 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
370 if (!this.skipInitialEligibilityCheck)
374 function(full) { self.setClaimPolicyControl(full, row) },
378 this.updateLiNotesCount(li, row);
380 // show which PO this lineitem is a member of
381 if(li.purchase_order() && !this.isPO) {
383 this.poCache[li.purchase_order()] =
384 this.poCache[li.purchase_order()] ||
385 fieldmapper.standardRequest(
386 ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
388 this.authtoken, li.purchase_order(), {
389 "flesh_price_summary": true,
390 "flesh_lineitem_count": true
393 if(po && !this.isMeta) {
394 openils.Util.show(nodeByName('po', row), 'inline');
395 var link = nodeByName('po_link', row);
396 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
397 link.innerHTML += po.name();
401 // show which picklist this lineitem is a member of
402 if(li.picklist() && (this.isPO || this.isMeta || this.isUni)) {
404 this.plCache[li.picklist()] =
405 this.plCache[li.picklist()] ||
406 fieldmapper.standardRequest(
407 ['open-ils.acq', 'open-ils.acq.picklist.retrieve.authoritative'],
408 {params: [this.authtoken, li.picklist()]});
410 if (pl.name() == "") {
411 openils.Util.show(nodeByName("bib_origin", row), "inline");
415 openils.Util.show(nodeByName('pl', row), 'inline');
416 var link = nodeByName('pl_link', row);
417 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
418 link.innerHTML += pl.name();
423 var countNode = nodeByName('count', row);
424 var count = li.item_count() || 0;
425 if (typeof(this._copy_count_cb) == "function") {
426 this._copy_count_cb(li.id(), count);
428 countNode.innerHTML = count;
429 countNode.id = 'acq-lit-copy-count-label-' + li.id();
432 var priceInput = dojo.query('[name=price]', row)[0];
433 priceInput.value = li.estimated_unit_price() || '';
434 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
436 // show either "mark received" or "unreceive" as appropriate
437 this.updateLiState(li, row);
439 if (skip_final_placement) {
444 this._liCountClaims = function(li) {
446 for (var i = 0; i < li.lineitem_details().length; i++)
447 total += li.lineitem_details()[i].claims().length;
451 this._findLiRow = function(li) {
452 return dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
455 this.reconsiderClaimControl = function(li, row) {
456 if (!row) row = this._findLiRow(li);
457 var option = nodeByName("action_manage_claims", row);
458 var eligible = this.claimEligibleLidByLi[li.id()].length;
459 var count = this._liCountClaims(li);
461 option.disabled = !(count || eligible);
463 dojo.string.substitute(localeStrings.NUM_CLAIMS_EXISTING, [count]);
464 option.onclick = function() { self.claimDialog.show(li); };
467 this.clearEligibility = function(li) {
468 this.claimEligibleLidByLi[li.id()] = [];
470 if (li.lineitem_details()) {
471 li.lineitem_details().forEach(
472 function(lid) { delete self.claimEligibleLid[lid.id()]; }
476 if (this.copyCache) {
478 for (var k in this.copyCache) {
479 if (this.copyCache[k].lineitem() == li.id())
483 function(k) { delete self.claimEligibleLid[k]; }
488 this.checkClaimEligibility = function(li, callback, row) {
489 /* Assume always eligible, i.e. from this interface we don't care about
490 * claim eligibility any more. this is where the user would force a
492 this.clearEligibility(li);
493 this.claimEligibleLidByLi[li.id()] = li.lineitem_details().map(
494 function(lid) { return lid.id(); }
496 li.lineitem_details().forEach(
497 function(lid) { self.claimEligibleLid[lid.id()] = true; }
499 this.reconsiderClaimControl(li, row);
500 if (callback) callback(li);
502 this.clearEligibility(li);
503 fieldmapper.standardRequest(
504 ["open-ils.acq", "open-ils.acq.claim.eligible.lineitem_detail"], {
505 "params": [openils.User.authtoken, {"lineitem": li.id()}],
507 "onresponse": function(r) {
508 if (r = openils.Util.readResponse(r)) {
509 self.claimEligibleLidByLi[li.id()].push(
512 self.claimEligibleLid[r.lineitem_detail()] = true;
515 "oncomplete": function() {
516 self.reconsiderClaimControl(li, row);
517 if (typeof(callback) == "function")
525 this.updateLiNotesCount = function(li, row) {
526 if (!row) row = this._findLiRow(li);
528 var has_notes = (li.lineitem_notes().filter(
529 function(o) { return Boolean (o.alert_text()); }
532 /* U+2691 is the code point for a filled-in flag character */
533 nodeByName("notes_alert_flag", row).innerHTML =
534 has_notes ? "⚑" : "";
535 nodeByName("noteslink", row).style.fontStyle =
536 has_notes ? "italic" : "normal";
537 nodeByName("notes_count", row).innerHTML = li.lineitem_notes().length;
540 /* XXX NOT related to _updateLiState(). rethink */
541 this.updateLiState = function(li, row) {
542 if (!row) row = this._findLiRow(li);
544 var actReceive = nodeByName("action_mark_recv", row);
545 var actUnRecv = nodeByName("action_mark_unrecv", row);
546 var actUpdateBarcodes = nodeByName("action_update_barcodes", row);
547 var actHoldingsMaint = nodeByName("action_holdings_maint", row);
549 var actNewInvoice = nodeByName('action_new_invoice', row);
550 var actLinkInvoice = nodeByName('action_link_invoice', row);
551 var actViewInvoice = nodeByName('action_view_invoice', row);
553 nodeByName('action_view_history', row).onclick =
554 function() { location.href = oilsBasePath + '/acq/lineitem/history/' + li.id(); };
556 var state_cell = nodeByName("li_state", row);
558 if (li.state() == "cancelled") {
559 if (typeof li.cancel_reason() == "object") {
560 var holds_state = dojo.create(
562 "style": "border-bottom: 1px dashed #000;",
563 "innerHTML": li.state()
564 }, state_cell, "only"
568 "label": "<em>" + li.cancel_reason().label() +
569 "</em><br />" + li.cancel_reason().description(),
570 "connectId": [holds_state]
571 }, dojo.create("span", null, state_cell, "last")
574 state_cell.innerHTML = li.state(); // TODO i18n state labels
577 state_cell.innerHTML = li.state(); // TODO i18n state labels
581 /* handle row coloring for based on LI state */
582 openils.Util.removeCSSClass(row, /^oils-acq-li-state-/);
583 openils.Util.addCSSClass(row, "oils-acq-li-state-" + li.state());
585 /* handle links that appear/disappear based on whether LI is received */
589 actNewInvoice.onclick = function() {
590 location.href = oilsBasePath + '/acq/invoice/view?create=1&attach_li=' + li.id();
591 nodeByName("action_none", row).selected = true;
593 actLinkInvoice.onclick = function() {
594 if (!self.invoiceLinkDialogManager) {
595 self.invoiceLinkDialogManager =
596 new InvoiceLinkDialogManager("li");
598 self.invoiceLinkDialogManager.target = li;
599 acqLitLinkInvoiceDialog.show();
600 nodeByName("action_none", row).selected = true;
602 actViewInvoice.onclick = function() {
603 location.href = oilsBasePath +
604 "/acq/search/unified?so=" +
605 base64Encode({"jub":[{"id": li.id()}]}) +
607 nodeByName("action_none", row).selected = true;
610 actNewInvoice.disabled = false;
611 actLinkInvoice.disabled = false;
612 actViewInvoice.disabled = false;
616 actReceive.disabled = false;
617 actReceive.onclick = function() {
618 if (self.checkLiAlerts(li.id()))
619 self.issueReceive(li);
620 nodeByName("action_none", row).selected = true;
625 actUnRecv.disabled = false;
626 actUnRecv.onclick = function() {
627 if (confirm(localeStrings.UNRECEIVE_LI))
628 self.issueReceive(li, /* rollback */ true);
629 nodeByName("action_none", row).selected = true;
631 // TODO we should allow editing before receipt, in which case the
632 // test should be "if 1 or more real (acp) copies exist
633 actUpdateBarcodes.disabled = false;
634 actUpdateBarcodes.onclick = function() {
635 self.showRealCopyEditUI(li);
636 nodeByName("action_none", row).selected = true;
638 actHoldingsMaint.disabled = false;
639 actHoldingsMaint.onclick = self.generateMakeRecTab( li.eg_bib_id(), 'copy_browser', row );
647 this._setAlertStore = function() {
648 acqLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
650 "data": acqliat.toStoreData(
652 "acqliat", {"id": {"!=": null}}
657 acqLitAlertAlertText.setValue(); /* make the store "live" */
658 acqLitAlertAlertText._store_ready = true;
662 * Draws and shows the lineitem notes pane
664 this.drawLiNotes = function(li) {
667 if (!acqLitAlertAlertText._store_ready)
668 this._setAlertStore();
671 li.lineitem_notes().sort(
673 if(a.edit_time() < b.edit_time()) return 1;
679 while(this.liNotesTbody.childNodes[0])
680 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
683 acqLitCreateNoteSubmit.onClick = function() {
684 var value = acqLitCreateNoteText.attr('value');
686 var note = new fieldmapper.acqlin();
689 Boolean(acqLitCreateNoteVendorPublic.attr('checked'))
692 note.lineitem(li.id());
694 self.updateLiNotes(li, note);
695 acqLitCreateNoteVendorPublic.attr("checked", false);
696 acqLitCreateNoteText.attr("value", "");
699 acqLitCreateAlertSubmit.onClick = function() {
700 if (!acqLitAlertAlertText.item) {
701 alert(localeStrings.ALERT_UNSELECTED);
705 var alert_text = new fieldmapper.acqliat().fromStoreItem(
706 acqLitAlertAlertText.item
708 var value = acqLitAlertNoteValue.attr("value") || "";
710 var note = new fieldmapper.acqlin();
712 note.lineitem(li.id());
714 note.alert_text(alert_text);
716 self.updateLiNotes(li, note);
719 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
723 * Draws a single lineitem note in the notes pane
725 this.addLiNote = function(li, note) {
726 if(note.isdeleted()) return;
728 var row = self.liNotesRow.cloneNode(true);
729 nodeByName("value", row).innerHTML = note.value();
730 var alert_node = nodeByName("alert_code", row);
731 if (note.alert_text()) {
732 alert_node.innerHTML = note.alert_text().code();
733 if (note.alert_text().description()) {
736 "connectId": [alert_node],
737 "label": note.alert_text().description()
738 }, dojo.create("span", null, alert_node, "after")
743 if (openils.Util.isTrue(note.vendor_public()))
744 nodeByName("vendor_public", row).innerHTML =
745 localeStrings.VENDOR_PUBLIC;
747 nodeByName("delete", row).onclick = function() {
748 note.isdeleted(true);
749 self.liNotesTbody.removeChild(row);
750 self.updateLiNotes(li);
753 if(note.edit_time()) {
754 nodeByName("edit_time", row).innerHTML =
755 dojo.date.locale.format(
756 dojo.date.stamp.fromISOString(note.edit_time()),
757 {formatLength:'short'});
760 self.liNotesTbody.appendChild(row);
764 * Updates any new/changed/deleted notes on the server
766 this.updateLiNotes = function(li, newNote) {
772 notes = li.lineitem_notes().filter(
774 if(note.ischanged() || note.isnew() || note.isdeleted())
780 if(notes.length == 0) return;
781 progressDialog.show();
783 fieldmapper.standardRequest(
784 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
786 params : [this.authtoken, notes],
787 onresponse : function(r) {
788 var resp = openils.Util.readResponse(r);
793 // remove the old changed notes
795 dojo.forEach(li.lineitem_notes(),
797 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
801 li.lineitem_notes(list);
804 progressDialog.hide();
805 self.updateLiNotesCount(li);
806 self.drawLiNotes(li);
810 progressDialog.update(resp);
811 var newnote = resp.note;
813 if(!newnote.isdeleted()) {
814 newnote.isnew(false);
815 newnote.ischanged(false);
816 li.lineitem_notes().push(newnote);
823 this.updateLiPrice = function(input, li) {
825 var price = input.value;
826 if(Number(price) == Number(li.estimated_unit_price())) return;
828 fieldmapper.standardRequest(
829 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
830 { async : false, // redundant w/ timeout
832 params : [this.authtoken, li.id(), price],
833 oncomplete : function(r) {
834 openils.Util.readResponse(r);
835 li.estimated_unit_price(price); // update local copy
841 this.removeLineitem = function(liId) {
842 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
843 delete this.liCache[liId];
844 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
847 this.drawInfo = function(liId) {
848 if (!this._isRelatedViewer) {
849 var d = dojo.byId("acq-lit-info-related");
850 if (!this.relCache[liId]) {
851 fieldmapper.standardRequest(
854 "open-ils.acq.lineitems_for_bib.by_lineitem_id.count"
857 "params": [openils.User.authtoken, liId],
858 "onresponse": function(r) {
859 self.relCache[liId] = openils.Util.readResponse(r);
860 nodeByName("related_number", d).innerHTML =
863 self.relCache[liId] >1 ? "show" : "hide"
869 nodeByName("related_number", d).innerHTML = this.relCache[liId];
870 openils.Util[this.relCache[liId] > 1 ? "show" : "hide"](d);
875 openils.acq.Lineitem.fetchAttrDefs(
877 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
882 /* For a given list of lineitem ids, build a list of full lineitems
883 * re-using the fetching logic that is otherwise typical to use in this
886 * If we've already got a lineitem in the cache, just use that.
888 * Once we've built a list of lineitems, call callback(thatlist).
890 this.fetchLineitemsById = function(id_list, callback) {
891 var total = id_list.length;
892 var result_list = [];
894 var inner = function(li) {
897 callback(result_list);
900 id_list.forEach(function(id) { self._fetchLineitem(id, inner); });
903 this._fetchLineitem = function(liId, handler, force) {
905 var li = this.liCache[liId];
906 if(li && li.marc() && li.lineitem_details() && !force)
909 fieldmapper.standardRequest(
910 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve.authoritative'],
913 params: [self.authtoken, liId, {
915 flesh_cancel_reason: true,
916 flesh_li_details: true,
918 flesh_fund_debit: true }],
920 oncomplete: function(r) {
921 var li = openils.Util.readResponse(r);
922 self.liCache[liId] = li;
929 this._drawInfo = function(li) {
931 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
934 openils.Util.hide('acq-lit-marc-order-record-label');
935 openils.Util.hide(acqLitEditOrderMarc.domNode);
936 openils.Util.show('acq-lit-marc-real-record-label');
938 openils.Util.show('acq-lit-marc-order-record-label');
939 openils.Util.show(acqLitEditOrderMarc.domNode);
940 openils.Util.hide('acq-lit-marc-real-record-label');
943 this.drawMarcHTML(li);
944 this.infoTbody = dojo.byId('acq-lit-info-tbody');
947 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
948 while(this.infoTbody.childNodes[0])
949 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
951 for(var i = 0; i < li.attributes().length; i++) {
952 var attr = li.attributes()[i];
953 var row = this.infoRow.cloneNode(true);
955 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
956 var name = openils.acq.Lineitem.attrDefs[type].filter(
958 return (a.code() == attr.attr_name());
960 ).pop().description();
962 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
963 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
964 this.infoTbody.appendChild(row);
967 if (!this._isRelatedViewer) {
968 nodeByName("rel_link", dojo.byId("acq-lit-info-related")).href =
969 oilsBasePath + "/acq/lineitem/related/" + li.id();
974 this.generateMakeRecTab = function(bib_id,default_view, row) {
978 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
981 show_nav_buttons : true,
982 show_print_button : true,
983 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + bib_id),
984 default_view : default_view
988 if(row) nodeByName("action_none", row).selected = true;
992 this.drawMarcHTML = function(li) {
993 var params = [null, true, li.marc()];
995 params = [li.eg_bib_id(), true];
997 fieldmapper.standardRequest(
998 ['open-ils.search', 'open-ils.search.biblio.record.html'],
1001 oncomplete: function(r) {
1002 dojo.byId('acq-lit-marc-div').innerHTML =
1003 openils.Util.readResponse(r);
1009 this.drawCopies = function(liId, force_fetch) {
1010 if (typeof force_fetch == "undefined")
1011 force_fetch = false;
1013 openils.acq.Lineitem.fetchAndRender(liId, {},
1014 function(li, html) {
1015 dojo.byId('acq-lit-copies-li-summary').innerHTML = html;
1019 this.show('copies');
1021 this.copyCache = {};
1022 this.copyWidgetCache = {};
1023 this.oldCopyWidgetCache = {};
1024 this.virtDfaCounts = {};
1025 this.realDfaCache = {};
1028 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
1029 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
1030 acqLitCopyCountInput.attr('value', '0');
1032 while(this.copyTbody.childNodes[0])
1033 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
1035 this._drawBatchCopyWidgets();
1037 this._drawDistribApplied(liId);
1039 this._fetchDistribFormulas(
1041 openils.acq.Lineitem.fetchAttrDefs(
1043 self._fetchLineitem(liId, function(li){self._drawCopies(li);}, force_fetch);
1050 this._saveDistribAppliedTemplates = function() {
1051 if (!this._appliedDistribTemplate) {
1052 this._appliedDistribTemplate =
1053 dojo.byId("acq-lit-distrib-applied-tbody").
1054 removeChild(dojo.byId("acq-lit-distrib-applied-row"));
1055 dojo.attr(this._appliedDistribTemplate, "id");
1059 this._drawDistribApplied = function(liId) {
1060 /* Build this table while hidden to prevent rendering artifacts */
1061 openils.Util.hide("acq-lit-distrib-applied-tbody");
1063 this._saveDistribAppliedTemplates();
1065 /* Remove any rows in the table from previous populations */
1066 dojo.query("tr[formula]", "acq-lit-distrib-applied-tbody").
1067 forEach(dojo.destroy);
1069 /* Unregister all dijits previously created (for some reason this isn't
1070 * covered by the above destroy calls). */
1071 dijit.registry.forEach(
1072 function(w) { if (/^dfa-/.test(w.id)) w.destroyRecursive(); }
1075 /* Populate the table with our liId */
1077 fieldmapper.standardRequest(
1079 "open-ils.acq.distribution_formula_application.ranged.retrieve"],
1082 "params": [self.authtoken, liId],
1083 "onresponse": function(r) {
1084 var dfa = openils.Util.readResponse(r);
1087 self.realDfaCache[dfa.id()] = dfa;
1088 self._drawDistribAppliedUnit(dfa);
1091 "oncomplete": function() {
1092 /* Reveal built table */
1095 "acq-lit-distrib-applied-tbody", "table-row-group"
1103 this._drawDistribAppliedUnit = function(dfa) {
1104 var new_row = false;
1105 var row = dojo.query(
1106 'tr[formula="' + dfa.formula().id() + '"]',
1107 "acq-lit-distrib-applied-tbody"
1112 row = dojo.clone(this._appliedDistribTemplate);
1113 dojo.attr(row, "formula", dfa.formula().id());
1114 dojo.query("th", row)[0].innerHTML = dfa.formula().name();
1117 var td = dojo.query("td", row)[0];
1119 dojo.create("span", {"id": "dfa-button-" + dfa.id()}, td, "last");
1120 dojo.create("span", {"id": "dfa-tip-" + dfa.id()}, td, "last");
1123 dojo.place(row, "acq-lit-distrib-applied-tbody", "last");
1125 new dijit.form.Button(
1127 "onClick": function() {
1128 if (confirm(localeStrings.EXPLAIN_DFA_MGMT))
1129 self.deleteDfa(dfa);
1132 /* XXX I /cannot/ make the following work in as a CSS class
1133 * for some reason. So frustrating... */
1134 "style": function(id) {
1136 "font-weight: bold; color: #c00;" :
1138 }(dfa.id()) + "margin: 0 6px;display: inline;"
1139 }, "dfa-button-" + dfa.id()
1143 "connectId": ["dfa-button-" + dfa.id()],
1144 "label": dojo.string.substitute(
1145 localeStrings.DFA_TIP, dfa.id() > 0 ? [
1146 openils.User.formalName(dfa.creator()),
1147 dojo.date.locale.format(
1148 dojo.date.stamp.fromISOString(dfa.create_time()),
1149 {"formatLength":"short"}
1151 ] : [localeStrings.ITS_YOU, localeStrings.JUST_NOW]
1153 }, "dfa-tip-" + dfa.id()
1157 this.deleteDfa = function(dfa) {
1158 if (dfa.id() > 0) { /* real */
1159 this.pcrud.eliminate(
1162 "oncomplete": function() {
1163 self._removeDistribApplied(dfa.id());
1164 delete self.realDfaCache[dfa.id()];
1168 } else { /* virtual */
1169 if (--(this.virtDfaCounts[dfa.formula().id()]) < 0)
1170 this.virtDfaCounts[dfa.formula().id()] = 0;
1171 /* hasn't been saved yet, so no need to do anything server side */
1172 this._removeDistribApplied(dfa.id());
1177 this._removeDistribApplied = function(dfaId) {
1178 var re = new RegExp("^dfa-\\w+-" + String(dfaId));
1179 dijit.registry.forEach(
1180 function(w) { if (re.test(w.id)) w.destroyRecursive(); }
1182 this._removeDistribAppliedEmptyRows();
1185 this._removeAllDistribAppliedVirtual = function() {
1186 /* Unregister dijits */
1187 dijit.registry.forEach(
1188 function(w) { if (/^dfa-\w+--/.test(w.id)) w.destroyRecursive(); }
1190 this._removeDistribAppliedEmptyRows();
1193 this._removeDistribAppliedEmptyRows = function() {
1194 /* Remove any rows with no DFA at all */
1195 dojo.query("tr[formula] td", "acq-lit-distrib-applied-tbody").forEach(
1197 if (o.childNodes.length < 1) dojo.destroy(o.parentNode);
1203 * Insert a new row into the distribution formula selection form
1205 this._addDistribFormulaRow = function() {
1208 if (!self.distribForms) {
1209 // no formulas, hide the form
1210 openils.Util.hide('acq-lit-distrib-formula-table');
1214 if(!this.distribFormulaTemplate)
1215 this.distribFormulaTemplate =
1216 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
1218 var row = this.distribFormulaTemplate.cloneNode(true);
1219 dojo.place(row, "acq-lit-distrib-formula-tbody", "only");
1221 this.dfSelector = new dijit.form.FilteringSelect(
1222 {"labelAttr": "dynLabel", "labelType": "html"},
1223 nodeByName("selector", row)
1225 this._updateFormulaStore();
1226 this.dfSelector.fetchProperties =
1227 {"sort": [{"attribute": "use_count", "descending": true}]};
1229 var apply = new dijit.form.Button(
1230 {"label": localeStrings.APPLY},
1231 nodeByName('set_button', row)
1234 var reset = new dijit.form.Button(
1235 {"label": localeStrings.RESET_FORMULAE, "disabled": true},
1236 nodeByName("reset_button", row)
1239 dojo.connect(apply, 'onClick',
1241 var form_id = self.dfSelector.attr("value");
1242 if(!form_id) return;
1243 self._applyDistribFormula(form_id);
1244 reset.attr("disabled", false);
1248 dojo.connect(reset, 'onClick',
1250 self.restoreCopyFieldsBeforeDF();
1251 self.virtDfaCounts = {};
1252 self.virtDfaId = -1;
1254 self._updateFormulaStore();
1255 self._removeAllDistribAppliedVirtual();
1256 reset.attr("disabled", "true");
1263 * Applies a distrib formula to the current set of copies
1265 this._applyDistribFormula = function(formula) {
1266 if(!formula) return;
1268 formula = this.distribForms.filter(
1269 function(form) { return form.id() == formula; }
1272 var copyRows = dojo.query('tr', self.copyTbody);
1274 if (this.dfeOffset >= copyRows.length) {
1275 alert(localeStrings.OUT_OF_COPIES);
1279 var entries_applied = 0;
1281 var rowIndex = this.dfeOffset;
1282 rowIndex < copyRows.length;
1286 var row = copyRows[rowIndex];
1287 var copy_id = row.getAttribute('copy_id');
1288 var copyWidgets = this.copyWidgetCache[copy_id];
1289 var entryIndex = this.dfeOffset;
1292 // find the correct entry for the current row
1293 dojo.forEach(formula.entries(),
1296 entryIndex += e.item_count();
1297 if(entryIndex > rowIndex)
1305 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
1306 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
1309 this.saveCopyFieldsBeforeDF(copy_id);
1310 this._copy_fields_for_acqdf.forEach(
1312 if(entry[field]()) {
1313 copyWidgets[field].attr('value', (entry[field]()));
1320 if (entries_applied) {
1321 this.virtDfaCounts[formula.id()] =
1322 ++(this.virtDfaCounts[formula.id()]) || 1;
1323 this._updateFormulaStore();
1324 this._drawDistribAppliedUnit(
1326 var dfa = new acqdfa();
1327 dfa.formula(df); dfa.id(self.virtDfaId--); return dfa;
1330 this.dfeOffset += entries_applied;
1335 * This function updates the DF store for the dropdown so that use_counts
1336 * can reflect DF applications from this session before they're saved
1339 this._updateFormulaStore = function() {
1340 this.dfSelector.store = new dojo.data.ItemFileReadStore(
1342 "data": self._labelFormulasWithCounts(
1343 acqdf.toStoreData(self.distribForms)
1349 this.saveCopyFieldsBeforeDF = function(copy_id) {
1351 if (!this.oldCopyWidgetCache[copy_id]) {
1352 var copyWidgets = this.copyWidgetCache[copy_id];
1354 this.oldCopyWidgetCache[copy_id] = {};
1355 this._copy_fields_for_acqdf.forEach(
1357 self.oldCopyWidgetCache[copy_id][f] =
1358 copyWidgets[f].attr("value");
1364 this.restoreCopyFieldsBeforeDF = function() {
1366 for (var copy_id in this.oldCopyWidgetCache) {
1367 this._copy_fields_for_acqdf.forEach(
1369 self.copyWidgetCache[copy_id][f].attr(
1370 "value", self.oldCopyWidgetCache[copy_id][f]
1377 this._labelFormulasWithCounts = function(store_data) {
1378 for (var key in store_data.items) {
1379 var obj = store_data.items[key];
1380 obj.use_count = Number(obj.use_count); /* needed for sorting */
1382 if (this.virtDfaCounts[obj.id])
1383 obj.use_count = obj.use_count + Number(this.virtDfaCounts[obj.id]);
1385 obj.dynLabel = "<span class='acq-lit-distrib-form-use-count'>[" +
1386 obj.use_count + "]</span> " + obj.name;
1392 * This method formerly would not refetch the DF formulas if they'd been
1393 * loaded already, but now it always re-fetches, since use_count changes.
1395 /** TODO: port distrib-formula selector to autofieldwidget+pcrud/dojo store */
1396 this._fetchDistribFormulas = function(onload) {
1397 fieldmapper.standardRequest(
1399 "open-ils.acq.distribution_formula.ranged.retrieve.atomic"],
1402 "params": [openils.User.authtoken, 0, 500],
1403 "oncomplete": function(r) {
1404 self.distribForms = openils.Util.readResponse(r);
1405 if(!self.distribForms || self.distribForms.length == 0) {
1406 self.distribForms = [];
1408 self._addDistribFormulaRow();
1415 this._drawBatchCopyWidgets = function() {
1416 var row = this.copyBatchRow;
1417 dojo.forEach(liDetailBatchFields,
1419 if(self.copyBatchRowDrawn) {
1420 self.copyBatchWidgets[field].attr('value', null);
1422 var widget = new openils.widget.AutoFieldWidget({
1425 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1426 searchFormat : (field == 'fund') ? fundSearchFormat : null,
1427 searchFilter : (field == 'fund') ? {"active": "t"} : null,
1428 parentNode : dojo.query('[name='+field+']', row)[0],
1429 orgLimitPerms : ['CREATE_PICKLIST'],
1432 "labelType": (field == "fund") ? "html" : null
1434 noCache: (field == "fund"),
1439 if (field == "fund" && w.store)
1440 self._ensureCSSFundClasses(w.store);
1441 self.copyBatchWidgets[field] = w;
1444 if (field == "fund") {
1446 widget.widget, "onChange", function(val) {
1447 self._updateFundSelectorStyle(widget, val);
1454 this.copyBatchRowDrawn = true;
1457 this.batchCopyUpdate = function() {
1459 for(var k in this.copyWidgetCache) {
1460 var cache = this.copyWidgetCache[k];
1461 dojo.forEach(liDetailBatchFields, function(f) {
1462 var newval = self.copyBatchWidgets[f].attr('value');
1463 if(newval) cache[f].attr('value', newval);
1468 this._drawCopies = function(li) {
1471 // this button sets the total number of copies for a given lineitem
1472 acqLitAddCopyCount.onClick = function() {
1473 var count = acqLitCopyCountInput.attr('value');
1476 while(self.copyCount() < count)
1479 // delete rows if necessary
1480 var diff = self.copyCount() - count;
1482 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
1483 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
1484 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
1486 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1492 if(li.lineitem_details().length > 0) {
1493 dojo.forEach(li.lineitem_details(),
1495 self.addCopy(li, copy);
1503 this.copyCount = function() {
1505 for(var id in this.copyCache) {
1506 if(!this.copyCache[id].isdeleted())
1512 this.virtCopyId = -1;
1513 this.addCopy = function(li, copy) {
1514 var row = this.copyRow.cloneNode(true);
1515 this.copyTbody.appendChild(row);
1519 copy = new fieldmapper.acqlid();
1521 copy.id(this.virtCopyId--);
1522 copy.lineitem(li.id());
1525 this.copyCache[copy.id()] = copy;
1526 row.setAttribute('copy_id', copy.id());
1527 self.copyWidgetCache[copy.id()] = {};
1529 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1531 var rcvr = copy.receiver();
1533 if (!userCache[rcvr]) {
1534 if(rcvr == openils.User.user.id()) {
1535 userCache[rcvr] = openils.User.user;
1537 userCache[rcvr] = fieldmapper.standardRequest(
1538 ['open-ils.actor', 'open-ils.actor.user.retrieve'],
1539 {params: [openils.User.authtoken, rcvr]}
1543 dojo.query('[name=receiver]', row)[0].innerHTML = userCache[rcvr].usrname();
1546 dojo.forEach(liDetailFields,
1549 if (field == "fund") {
1550 searchFilter = (copy.fund() ?
1551 {"-or": {"active": "t", "id": copy.fund()}} :
1554 searchFilter = null;
1557 var readOnly = false;
1559 // TODO: Add support for changing the owning_lib after real copies have been made.
1560 // owning_lib is order data as much as its item data
1561 if(copy.eg_copy_id() && ['owning_lib', 'location', 'circ_modifier', 'cn_label', 'barcode'].indexOf(field) >= 0) {
1565 // TODO: add support for changing the fund after debits have been created
1566 // Note: invoicing allows the change
1567 if(copy.fund_debit() && field == 'fund') {
1572 var widget = new openils.widget.AutoFieldWidget({
1575 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1576 searchFormat : (field == 'fund') ? fundSearchFormat : null,
1577 dijitArgs: {"labelType": (field == 'fund') ? "html" : null},
1578 searchFilter : searchFilter,
1579 noCache: (field == "fund"),
1581 parentNode : dojo.query('[name='+field+']', row)[0],
1582 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
1583 readOnly : readOnly,
1584 orgDefaultsToWs : true
1588 // make sure we capture the value from any async widgets
1591 if (field == "fund" && w.store)
1592 self._ensureCSSFundClasses(w.store);
1595 copy[field](ww.getFormattedValue())
1597 self.copyWidgetCache[copy.id()][field] = w;
1599 dojo.connect(w, 'onChange',
1601 if (field == "fund")
1602 self._updateFundSelectorStyle(widget, val);
1604 if (!readOnly && (copy.isnew() || val != copy[field]())) {
1605 // prevent setting ischanged() automatically on widget load for existing copies
1606 copy[field](widget.getFormattedValue())
1607 copy.ischanged(true);
1616 this.updateLidState(copy, row);
1619 this._ensureCSSFundClass = function(id) {
1620 if (!this.fundStyleSheet) {
1622 "style", {"type": "text/css"},
1623 document.getElementsByTagName("head")[0], "last"
1625 this.fundStyleSheet = document.styleSheets[
1626 document.styleSheets.length - 1
1630 var cn = "fund_" + id;
1631 if (!this.haveFundClass[cn]) {
1632 fieldmapper.standardRequest(
1633 ["open-ils.acq", "open-ils.acq.fund.check_balance_percentages"],
1635 "params": [openils.User.authtoken, id],
1637 "oncomplete": function(r) {
1638 r = openils.Util.readResponse(r);
1639 self.fundBalanceState[id] = r;
1641 if (r[0] /* stop */)
1642 style = fundStyles.stop;
1643 else if (r[1] /* warning */)
1644 style = fundStyles.warning;
1645 self.fundStyleSheet.insertRule(
1646 "." + cn + " { " + style + " }",
1647 self.fundStyleSheet.cssRules.length
1649 self.haveFundClass[cn] = true;
1656 this._ensureCSSFundClasses = function(store) {
1658 "query": {"id": "*"},
1659 "onItem": function(o) { self._ensureCSSFundClass(o.id[0]); }
1663 this._updateFundSelectorStyle = function(widget, fund_id) {
1664 openils.Util.removeCSSClass(widget.widget.domNode, /fund_\d+/);
1665 openils.Util.addCSSClass(widget.widget.domNode, "fund_" + fund_id);
1668 this.updateLidState = function(copy, row) {
1669 if (typeof(row) == "undefined") {
1671 'tr[copy_id="' + copy.id() + '"]', this.copyTbody
1676 var recv_link = nodeByName("receive", row);
1677 var unrecv_link = nodeByName("unreceive", row);
1678 var del_link = nodeByName("delete", row);
1679 var cxl_link = nodeByName("cancel", row);
1680 var claim_link = nodeByName("claim", row);
1681 var cxl_reason_link = nodeByName("cancel_reason", row);
1683 if (copy.cancel_reason()) {
1684 openils.Util.hide(del_link.parentNode);
1685 openils.Util.hide(recv_link);
1686 openils.Util.hide(unrecv_link);
1687 openils.Util.hide(cxl_link);
1688 openils.Util.hide(claim_link);
1690 /* XXX the following may leak memory in a long lived table: dijits may not get destroyed... not positive. revisit. */
1691 var holds_reason = dojo.create(
1693 "style": "border-bottom: 1px dashed #000;",
1694 "innerHTML": "Cancelled" /* XXX [sic] and i18n */
1695 }, cxl_reason_link, "only"
1699 "label": "<em>" + copy.cancel_reason().label() +
1700 "</em><br />" + copy.cancel_reason().description(),
1701 "connectId": [holds_reason]
1702 }, dojo.create("span", null, cxl_reason_link, "last")
1704 openils.Util.show(cxl_reason_link, "inline");
1705 } else if (this.isPO) {
1706 /* Only using this in one place so far, but may want it for better
1707 * decisions on when to display certain controls. */
1708 var li_state = this.liCache[copy.lineitem()].state();
1710 openils.Util.hide(del_link.parentNode);
1711 openils.Util.hide(cxl_reason_link);
1713 /* Avoid showing (un)receive links, cancel links, for virt copies */
1714 if (copy.id() > 0) {
1715 if (copy.recv_time()) {
1716 openils.Util.hide(cxl_link);
1717 openils.Util.hide(recv_link);
1718 openils.Util.hide(claim_link);
1720 openils.Util.show(unrecv_link, "inline");
1721 unrecv_link.onclick = function() {
1722 if (confirm(localeStrings.UNRECEIVE_LID))
1723 self.issueReceive(copy, /* rollback */ true);
1726 openils.Util.hide(unrecv_link);
1728 if (this.claimEligibleLid[copy.id()]) {
1729 openils.Util.show(claim_link, "inline");
1730 claim_link.onclick = function() {
1731 self.claimDialog.show(
1732 self.liCache[copy.lineitem()], copy.id()
1736 openils.Util.hide(claim_link);
1739 openils.Util[li_state == "on-order" ? "show" : "hide"](
1742 openils.Util.show(cxl_link, "inline");
1743 recv_link.onclick = function() {
1744 if (self.checkLiAlerts(copy.lineitem()))
1745 self.issueReceive(copy);
1747 cxl_link.onclick = function() {
1748 self.cancelLid(copy.id());
1752 openils.Util.hide(cxl_link);
1753 openils.Util.hide(unrecv_link);
1754 openils.Util.hide(recv_link);
1755 openils.Util.hide(claim_link);
1758 openils.Util.hide(unrecv_link);
1759 openils.Util.hide(recv_link);
1760 openils.Util.hide(cxl_reason_link);
1761 openils.Util.hide(claim_link);
1763 del_link.onclick = function() { self.deleteCopy(row) };
1764 openils.Util.show(del_link.parentNode);
1768 this.cancelLid = function(lid_id) {
1769 lidCancelDialog._lid_id = lid_id;
1770 openils.Util.show(lidCancelDialog.domNode.parentNode);
1771 lidCancelDialog.show();
1772 if (!lidCancelDialog._prepared) {
1773 var widget = new openils.widget.AutoFieldWidget({
1774 "fmField": "cancel_reason",
1775 "fmClass": "acqlid",
1776 "parentNode": dojo.byId("acq-lit-lid-cancel-reason"),
1777 "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
1782 acqLidCancelButton.onClick = function() {
1783 if (w.attr("value")) {
1784 if (confirm(localeStrings.LID_CANCEL_CONFIRM)) {
1786 lidCancelDialog._lid_id,
1790 lidCancelDialog.hide();
1793 lidCancelDialog._prepared = true;
1799 this._cancelLid = function(lid_id, reason) {
1800 fieldmapper.standardRequest(
1801 ["open-ils.acq", "open-ils.acq.lineitem_detail.cancel"], {
1802 "params": [openils.User.authtoken, lid_id, reason],
1804 "onresponse": function(r) {
1805 if (r = openils.Util.readResponse(r)) {
1807 for (var id in r.lid) {
1808 /* actually this should only iterate once */
1809 self.copyCache[id].cancel_reason(
1810 r.lid[id].cancel_reason
1812 self.updateLidState(self.copyCache[id]);
1821 this._confirmAlert = function(li, lin) {
1823 dojo.string.substitute(
1824 localeStrings.CONFIRM_LI_ALERT, [
1825 (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1826 "title", "lineitem_marc_attr_definition"
1828 lin.alert_text().code(),
1829 lin.alert_text().description() || "",
1836 this.checkLiAlerts = function(li_id) {
1837 var li = this.liCache[li_id];
1839 var alert_notes = li.lineitem_notes().filter(
1840 function(o) { return Boolean(o.alert_text()); }
1843 /* this is _intentionally_ not done in a call to forEach() ... */
1844 for (var i = 0; i < alert_notes.length; i++) {
1845 if (this.noteAcks[alert_notes[i].id()])
1847 else if (!this._confirmAlert(li, alert_notes[i]))
1850 this.noteAcks[alert_notes[i].id()] = true;
1856 this.deleteCopy = function(row) {
1857 var copy = this.copyCache[row.getAttribute('copy_id')];
1858 copy.isdeleted(true);
1860 delete this.copyCache[copy.id()];
1861 this.copyTbody.removeChild(row);
1864 this._virtDfaCountsAsList = function() {
1866 for (var key in this.virtDfaCounts) {
1867 for (var i = 0; i < this.virtDfaCounts[key]; i++)
1873 this.confirmBreachedCopyFunds = function(copies) {
1874 var stop = 0, warning = 0;
1878 var state = self.fundBalanceState[o.fund()];
1879 if (state[0] /* stop */)
1881 else if (state[1] /* warning */)
1888 return confirm(localeStrings.CONFIRM_FUNDS_AT_STOP);
1889 } else if (warning) {
1890 return confirm(localeStrings.CONFIRM_FUNDS_AT_WARNING);
1895 this.saveCopyChanges = function(liId) {
1901 for(var id in this.copyCache) {
1902 var c = this.copyCache[id];
1903 if(!c.isdeleted()) total++;
1904 if(c.isnew() || c.ischanged() || c.isdeleted()) {
1905 if(c.id() < 0) c.id(null);
1911 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
1914 if (copies.length > 0) {
1915 if (!this.confirmBreachedCopyFunds(copies))
1918 if (typeof(this._copy_count_cb) == "function")
1919 this._copy_count_cb(liId, total);
1921 openils.Util.show("acq-lit-update-copies-progress");
1922 fieldmapper.standardRequest(
1923 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
1925 params: [openils.User.authtoken, copies],
1926 onresponse: function(r) {
1927 var res = openils.Util.readResponse(r);
1928 litUpdateCopiesProgress.update(res);
1930 oncomplete: function() {
1931 self.drawCopies(liId, true /* force_fetch */);
1932 openils.Util.hide("acq-lit-update-copies-progress");
1938 var dfa_list = this._virtDfaCountsAsList();
1939 if (dfa_list.length > 0) {
1940 fieldmapper.standardRequest(
1942 "open-ils.acq.distribution_formula.record_application"],
1945 "params": [openils.User.authtoken, dfa_list, liId],
1946 "onresponse": function(r) {
1947 var res = openils.Util.readResponse(r);
1948 if (res && res.length < dfa_list.length)
1949 alert(localeStrings.DFA_NOT_ALL);
1953 this.virtDfaCounts = {};
1957 this._updateCreatePoPrepayCheckbox = function(prepay) {
1958 var prepay = openils.Util.isTrue(prepay);
1959 this._prepayRequiredByVendor = prepay;
1960 dijit.byId("acq-lit-po-prepay").attr("checked", prepay);
1963 this._confirmPoPrepaySituation = function() {
1964 var want_prepay = dijit.byId("acq-lit-po-prepay").attr("checked");
1965 if (want_prepay != this._prepayRequiredByVendor) {
1968 localeStrings.VENDOR_SAYS_PREPAY_NOT_NEEDED :
1969 localeStrings.VENDOR_SAYS_PREPAY_NEEDED
1976 this.applySelectedLiAction = function(action) {
1980 case 'delete_selected':
1981 this._deleteLiList(self.getSelected());
1984 case 'create_order':
1985 this._loadPOSelect();
1986 acqLitPoCreateDialog.show();
1989 case 'save_picklist':
1990 acqLitSavePlDialog.show();
1993 case 'selector_ready':
1995 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
1996 acqLitChangeLiStateDialog.show();
2004 location.href = oilsBasePath + '/acq/po/history/' + this.isPO;
2011 case 'rollback_receive_po':
2012 this.rollbackPoReceive();
2015 case 'create_assets':
2016 this.createAssets();
2019 case 'export_attr_list':
2020 this.chooseExportAttr();
2023 case 'batch_apply_funds':
2024 this.applyBatchLiFunds();
2027 case 'add_brief_record':
2029 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
2031 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
2035 case "cancel_lineitems":
2036 this.maybeCancelLineitems();
2039 case "change_claim_policy":
2040 var li_list = this.getSelected();
2041 this.claimPolicyPicker.attr("value", null);
2042 liClaimPolicyDialog.show();
2043 liClaimPolicySave.onClick = function() {
2044 self.changeClaimPolicy(
2046 self.claimPolicyPicker.attr("value"),
2050 self.setClaimPolicyControl(li);
2051 self.reconsiderClaimControl(li);
2054 liClaimPolicyDialog.hide();
2062 this.changeClaimPolicy = function(li_list, value, callback) {
2064 function(li) { li.claim_policy(value); }
2066 fieldmapper.standardRequest(
2067 ["open-ils.acq", "open-ils.acq.lineitem.update"], {
2068 "params": [openils.User.authtoken, li_list],
2070 "oncomplete": function(r) {
2071 r = openils.Util.readResponse(r);
2072 if (callback) callback(r);
2078 this.createAssets = function() {
2079 if(!this.isPO) return;
2080 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
2081 this.show('acq-lit-progress-numbers');
2083 fieldmapper.standardRequest(
2084 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
2086 params: [this.authtoken, this.isPO],
2087 onresponse: function(r) {
2088 var resp = openils.Util.readResponse(r);
2089 self._updateProgressNumbers(resp, true);
2095 this.maybeCancelLineitems = function() {
2096 openils.Util.show("acq-lit-cancel-reason", "inline");
2097 if (!acqLitCancelLineitemsButton._prepared) {
2098 var widget = new openils.widget.AutoFieldWidget({
2099 "fmField": "cancel_reason",
2101 "parentNode": dojo.byId("acq-lit-cancel-reason-selector"),
2102 "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
2107 acqLitCancelLineitemsButton.onClick = function() {
2108 if (w.attr("value")) {
2109 if (confirm(localeStrings.LI_CANCEL_CONFIRM)) {
2110 self._cancelLineitems(w.attr("value"));
2112 openils.Util.hide("acq-lit-cancel-reason");
2115 acqLitCancelLineitemsButton._prepared = true;
2121 this._cancelLineitems = function(reason) {
2122 var id_list = this.getSelected().map(function(o) { return o.id(); });
2123 fieldmapper.standardRequest(
2124 ["open-ils.acq", "open-ils.acq.lineitem.cancel.batch"], {
2125 "params": [openils.User.authtoken, id_list, reason],
2127 "onresponse": function(r) {
2128 if (r = openils.Util.readResponse(r)) {
2130 for (var id in r.li) {
2131 self.liCache[id].state(r.li[id].state);
2132 self.liCache[id].cancel_reason(
2133 r.li[id].cancel_reason
2135 self.updateLiState(self.liCache[id]);
2138 if (r.lid && self.copyCache) {
2139 for (var id in r.lid) {
2140 if (self.copyCache[id]) {
2141 self.copyCache[id].cancel_reason(
2142 r.lid[id].cancel_reason
2144 self.updateLidState(self.copyCache[id]);
2154 this.chooseExportAttr = function() {
2155 if (!acqLitExportAttrSelector._li_setup) {
2157 acqLitExportAttrSelector.store = new dojo.data.ItemFileReadStore(
2159 "data": acqlimad.toStoreData(
2161 "acqlimad", {"code": li_exportable_attrs}
2166 acqLitExportAttrSelector.setValue();
2167 acqLitExportAttrButton.onClick = function(){self.exportAttrList();};
2168 acqLitExportAttrSelector._li_setup = true;
2170 openils.Util.show("acq-lit-export-attr-holder", "inline");
2173 this.exportAttrList = function() {
2174 var attr_def = acqLitExportAttrSelector.item;
2175 var li_list = this.getSelected();
2176 var value_list = li_list.map(
2178 return (new openils.acq.Lineitem({"lineitem": li})).findAttr(
2179 attr_def.code, "lineitem_marc_attr_definition"
2182 ).filter(function(attr) { return Boolean(attr); });
2184 if (value_list.length > 0) {
2185 if (value_list.length < li_list.length) {
2187 dojo.string.substitute(
2188 localeStrings.EXPORT_SHORT_LIST, [attr_def.description]
2195 openils.XUL.contentToFileSaveDialog(
2196 value_list.join("\n"),
2197 localeStrings.EXPORT_SAVE_DIALOG_TITLE
2203 alert(dojo.string.substitute(
2204 localeStrings.EXPORT_EMPTY_LIST, [attr_def.description]
2208 openils.Util.hide("acq-lit-export-attr-holder");
2211 this.printPO = function() {
2212 if(!this.isPO) return;
2213 progressDialog.show(true);
2214 fieldmapper.standardRequest(
2215 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
2217 params: [this.authtoken, this.isPO, 'html'],
2218 oncomplete: function(r) {
2219 progressDialog.hide();
2220 var evt = openils.Util.readResponse(r);
2221 if(evt && evt.template_output()) {
2222 openils.Util.printHtmlString(evt.template_output().data());
2230 this.receivePO = function() {
2231 if (!this.isPO) return;
2233 for (var id in this.liCache) {
2234 /* assumption: liCache reflects exactly the
2235 * set of LIs that belong to our PO */
2236 if (this.liCache[id].state() != "received" &&
2237 !this.checkLiAlerts(id)) return;
2240 this.show('acq-lit-progress-numbers');
2242 fieldmapper.standardRequest(
2243 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
2245 params: [this.authtoken, this.isPO],
2246 onresponse : function(r) {
2247 var resp = openils.Util.readResponse(r);
2248 self._updateProgressNumbers(resp, true);
2254 this.issueReceive = function(obj, rollback) {
2255 /* (For now) there shall be no marking LI or LIDs (un)received
2256 * except from the actual "view PO" interface. */
2257 if (!this.isPO) return;
2260 {"jub": "lineitem", "acqlid": "lineitem_detail"}[obj.classname];
2262 "open-ils.acq." + part + ".receive" + (rollback ? ".rollback" : "");
2264 progressDialog.show(true);
2265 fieldmapper.standardRequest(
2266 ["open-ils.acq", method], {
2268 "params": [this.authtoken, obj.id()],
2269 "onresponse": function(r) {
2270 if (r = openils.Util.readResponse(r)) {
2271 self.fetchClaimInfo(
2272 part == "lineitem" ? obj.id() : obj.lineitem(),
2274 function() { self.handleReceive(r); }
2276 progressDialog.hide();
2284 * Handles the responses from receive and rollback ML calls.
2286 this.handleReceive = function(resp) {
2289 for (var li_id in resp.li) {
2290 for (var key in resp.li[li_id])
2291 self.liCache[li_id][key](resp.li[li_id][key]);
2292 self.updateLiState(self.liCache[li_id]);
2296 if (typeof(self.poUpdateCallback) == "function")
2297 self.poUpdateCallback(resp.po);
2300 for (var lid_id in resp.lid) {
2301 for (var key in resp.lid[lid_id])
2302 self.copyCache[lid_id][key](resp.lid[lid_id][key]);
2303 self.updateLidState(self.copyCache[lid_id]);
2309 this.rollbackPoReceive = function() {
2310 if(!this.isPO) return;
2311 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
2312 this.show('acq-lit-progress-numbers');
2314 fieldmapper.standardRequest(
2315 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
2317 params: [this.authtoken, this.isPO],
2318 onresponse : function(r) {
2319 var resp = openils.Util.readResponse(r);
2320 self._updateProgressNumbers(resp, true);
2326 this._updateProgressNumbers = function(resp, reloadOnComplete) {
2328 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
2329 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
2330 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
2331 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
2332 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
2333 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
2334 if(resp.complete && reloadOnComplete)
2335 location.href = location.href;
2339 this._createPO = function(fields) {
2340 var wantall = (fields.create_from == "all");
2342 /* If we're a picklist or purchase order already and the user wants
2343 * all lineitems, we might have pages' worth of lineitems haven't all
2344 * been loaded yet, so getSelected() won't find them. The server,
2345 * however, should know about all our lineitems, so let's ask the
2346 * server for a complete list.
2351 true, function(list) {
2352 self._createPOFromLineitems(fields, list);
2353 }, /* id_list */ true
2356 this._createPOFromLineitems(fields, this.getSelected(false, null, true /* id_list */));
2360 this._createPOFromLineitems = function(fields, selected) {
2361 if (selected.length == 0) return;
2363 this.show("acq-lit-progress-numbers");
2364 var po = new fieldmapper.acqpo();
2365 po.provider(this.createPoProviderSelector.attr("value"));
2366 po.ordering_agency(this.createPoAgencySelector.attr("value"));
2367 po.prepayment_required(fields.prepayment_required[0] ? true : false);
2369 fieldmapper.standardRequest(
2370 ["open-ils.acq", "open-ils.acq.purchase_order.create"],
2373 openils.User.authtoken,
2375 lineitems : selected,
2376 create_assets : fields.create_assets[0],
2380 onresponse : function(r) {
2381 var resp = openils.Util.readResponse(r);
2382 self._updateProgressNumbers(resp);
2383 if (resp.complete) {
2384 location.href = oilsBasePath + "/acq/po/view/" +
2385 resp.purchase_order.id();
2393 this.batchFundWidget = null;
2395 this.applyBatchLiFunds = function() {
2397 var liIds = this.getSelected().map(function(li) { return li.id(); });
2398 if(liIds.length == 0) return; // warn?
2401 batchFundUpdateDialog.show();
2403 if(!this.batchFundWidget) {
2404 this.batchFundWidget = new openils.widget.AutoFieldWidget({
2406 selfReference : true,
2407 labelFormat : fundLabelFormat,
2408 searchFormat : fundSearchFormat,
2409 searchFilter : {"active": "t"},
2410 parentNode : dojo.byId('acq-lit-batch-fund-selector'),
2411 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
2412 dijitArgs : { "required": true, "labelType": "html" },
2415 this.batchFundWidget.build();
2418 dojo.connect(batchFundUpdateCancel, 'onClick', function() { batchFundUpdateDialog.hide(); });
2419 dojo.connect(batchFundUpdateSubmit, 'onClick',
2422 // TODO: call .dry_run first to test thresholds
2423 fieldmapper.standardRequest(
2424 ['open-ils.acq', 'open-ils.acq.lineitem.fund.update.batch'],
2427 openils.User.authtoken,
2429 self.batchFundWidget.widget.attr('value')
2431 oncomplete : function(r) {
2432 var resp = openils.Util.readResponse(r);
2434 location.href = location.href;
2443 this._deleteLiList = function(list, idx) {
2444 if(idx == null) idx = 0;
2445 if(idx >= list.length) return;
2450 if (this.isPO && (li.state() == "on-order" || li.state() == "received")) {
2451 /* It makes little sense to delete a lineitem from a PO that has
2452 * already been marked 'on-order'. Especially if EDI is in use,
2453 * such a purchase order will probably have already been shipped
2454 * off to a vendor, and mucking with it at this point could leave
2455 * your data in a bad state that doesn't jive with reality.
2457 * I could see making this restriction even firmer.
2459 * I could also see adjusting the li state comparisons, extending
2460 * the comparison to the PO's state, and/or providing functions
2461 * that house the logic for comparing states in a single location.
2463 * Yes, this will be really annoying if you have selected a lot
2464 * of lineitems to cancel that have been ordered. You'll get a
2465 * confirm dialog for each one.
2468 if (!confirm(localeStrings.DEL_LI_FROM_PO)) {
2469 self._deleteLiList(list, ++idx); /* move on to next in list */
2474 fieldmapper.standardRequest(
2476 this.isPO ? 'open-ils.acq.purchase_order.lineitem.delete' : 'open-ils.acq.picklist.lineitem.delete'],
2478 params: [openils.User.authtoken, liId],
2479 oncomplete: function(r) {
2480 self.removeLineitem(liId);
2481 self._deleteLiList(list, ++idx);
2487 this.editOrderMarc = function(li) {
2489 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
2490 to true in about:config */
2492 if(!openils.XUL.enableXPConnect()) return;
2494 if(openils.XUL.isXUL()) {
2495 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
2497 win = window.open('/xul/server/cat/marcedit.xul');
2501 record : {marc : li.marc(), "rtype": "bre"},
2503 label: 'Save Record', // XXX I18N
2504 func: function(xmlString) {
2506 fieldmapper.standardRequest(
2507 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
2509 params: [openils.User.authtoken, li],
2510 oncomplete: function(r) {
2511 openils.Util.readResponse(r);
2513 self.drawInfo(li.id())
2519 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
2520 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
2524 this._savePl = function(values) {
2526 (values.which == 'all'),
2527 function(list) { self._savePlFromLineitems(values, list); }
2531 this._savePlFromLineitems = function(values, selected) {
2532 openils.Util.show("acq-lit-generic-progress");
2534 if(values.new_name) {
2535 openils.acq.Picklist.create(
2536 {name: values.new_name},
2542 oilsBasePath + "/acq/picklist/view/" + id;
2547 } else if(values.existing_pl) {
2548 // update lineitems to use an existing picklist
2550 values.existing_pl, selected, 0,
2553 oilsBasePath + "/acq/picklist/view/" +
2560 this._updateLiState = function(values, state) {
2561 progressDialog.show(true);
2563 (values.which == 'all'),
2565 self._updateLiStateFromLineitems(values, state, list);
2570 this._updateLiStateFromLineitems = function(values, state, selected) {
2571 if(!selected.length) return;
2572 dojo.forEach(selected, function(li) {li.state(state);});
2573 self._updateLiList(null, selected, 0,
2574 // TODO consider inline updates for efficiency
2575 function() { location.href = location.href }
2579 this._updateLiList = function(pl, list, idx, oncomplete) {
2580 if(idx >= list.length) return oncomplete();
2582 if(pl != null) li.picklist(pl);
2583 litGenericProgress.update({maximum: list.length, progress: idx});
2584 new openils.acq.Lineitem({lineitem:li}).update(
2586 self._updateLiList(pl, list, ++idx, oncomplete);
2591 this._loadPOSelect = function() {
2592 if (!this.createPoProviderSelector) {
2593 var widget = new openils.widget.AutoFieldWidget({
2594 "fmField": "provider",
2596 "searchFilter": {"active": "t"},
2597 "parentNode": dojo.byId("acq-lit-po-provider"),
2599 "onChange": function() {
2601 self._updateCreatePoPrepayCheckbox(
2602 this.item.prepayment_required()
2608 widget.build(function(w) { self.createPoProviderSelector = w; });
2611 if (!this.createPoAgencySelector) {
2612 var widget = new openils.widget.AutoFieldWidget({
2613 "fmField": "ordering_agency",
2615 "parentNode": dojo.byId("acq-lit-po-agency"),
2616 "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
2618 widget.build(function(w) { self.createPoAgencySelector = w; });
2622 this.showRealCopyEditUI = function(li) {
2627 this._fetchLineitem(li.id(),
2629 li = self.liCache[li.id()] = fullLi;
2633 id : li.lineitem_details().map(
2634 function(item) { return item.eg_copy_id() }
2638 oncomplete : function(r) {
2640 var r_list = openils.Util.readResponse( r );
2641 for (var i = 0; i < r_list.length; i++) {
2642 var copy = r_list[i];
2643 var volId = copy.call_number();
2644 var volume = self.volCache[volId];
2646 volume = self.volCache[volId] = self.pcrud.retrieve('acn', volId);
2648 copy.call_number(volume);
2649 copyList.push(copy);
2652 xulG.volume_item_creator( { 'existing_copies' : copyList } );
2655 alert('error in oncomplete: ' + E);
2664 this.drawBibFinder = function(li) {
2667 var liWrapper = new openils.acq.Lineitem({lineitem:li});
2670 ['isbn', 'upc', 'issn', 'title', 'author'],
2672 var val = liWrapper.findAttr(field, 'lineitem_marc_attr_definition');
2674 if(field == 'title' || field == 'author') {
2675 query += field +':' + val + ' ';
2677 query += 'identifier|' + field + ':' + val + ' ';
2684 oilsBasePath + '/acq/lineitem/findbib?query=' + escape(query),
2685 '', 'resizable,scrollbars=1');
2687 win.window.recordFound = function(bibId) {
2690 var attrs = li.attributes();
2691 li.attributes(null);
2692 li.eg_bib_id(bibId);
2694 fieldmapper.standardRequest(
2695 ["open-ils.acq", "open-ils.acq.lineitem.update"],
2697 "params": [openils.User.authtoken, li],
2699 "oncomplete": function(r) {
2700 if(openils.Util.readResponse(r)) {
2701 location.href = location.href;