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.createPoProviderSelector.attr("value") ||
90 !self.createPoAgencySelector.attr("value")) {
91 alert(localeStrings.CREATE_PO_INVALID);
93 } else if (self._confirmPoPrepaySituation()) {
94 acqLitPoCreateDialog.hide();
95 self._createPO(acqLitPoCreateDialog.getValues());
101 acqLitSavePlButton.onClick = function() {
102 acqLitSavePlDialog.hide();
103 self._savePl(acqLitSavePlDialog.getValues());
106 acqLitCancelLiStateButton.onClick = function() {
107 acqLitChangeLiStateDialog.hide();
109 acqLitSaveLiStateButton.onClick = function() {
110 acqLitChangeLiStateDialog.hide();
111 self._updateLiState(acqLitChangeLiStateDialog.getValues(), acqLitChangeLiStateDialog.attr('state'));
115 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
116 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
117 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
118 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
119 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
121 this.reset = function(keep_selectors) {
122 while(self.tbody.childNodes[0])
123 self.tbody.removeChild(self.tbody.childNodes[0]);
131 this.setNext = function(handler) {
132 var link = dojo.byId('acq-lit-next');
134 dojo.style(link, 'visibility', 'visible');
135 link.onclick = handler;
137 dojo.style(link, 'visibility', 'hidden');
141 this.setPrev = function(handler) {
142 var link = dojo.byId('acq-lit-prev');
144 dojo.style(link, 'visibility', 'visible');
145 link.onclick = handler;
147 dojo.style(link, 'visibility', 'hidden');
151 this.show = function(div) {
152 openils.Util.hide('acq-lit-table-div');
153 openils.Util.hide('acq-lit-info-div');
154 openils.Util.hide('acq-lit-li-details');
155 openils.Util.hide('acq-lit-notes-div');
156 openils.Util.hide('acq-lit-real-copies-div');
159 openils.Util.show('acq-lit-table-div');
162 openils.Util.show('acq-lit-info-div');
165 openils.Util.show('acq-lit-li-details');
168 openils.Util.show('acq-lit-real-copies-div');
171 openils.Util.show('acq-lit-notes-div');
175 openils.Util.show(div);
179 this.hide = function() {
183 this.toggleSelect = function() {
185 dojo.forEach(self.selectors, function(i){i.checked = false});
187 dojo.forEach(self.selectors, function(i){i.checked = true});
188 self.toggleState = !self.toggleState;
192 this.getAll = function(callback, id_only) {
193 /* For some uses of the li table, we may not really know about "all"
194 * the lineitems that the user thinks we know about. If we're a paged
195 * picklist, for example, we only know about the lineitems we've
196 * displayed, but not necessarily all the lineitems on the picklist.
197 * So we reach out to pcrud to inform us.
200 var oncomplete = function(r) {
201 var id_list = openils.Util.readResponse(r);
205 self.fetchLineitemsById(id_list, callback);
210 "jub", {"picklist": this.isPL}, {
211 "id_list": true, /* sic, even if id_only */
213 "oncomplete": oncomplete
217 } else if (this.isPO) {
219 "jub", {"purchase_order": this.isPO}, {
222 "oncomplete": oncomplete
226 } else if (this.isUni && this.pager) {
227 this.pager.getAllLineitemIDs(oncomplete);
231 /* If execution reaches this point, we don't need or can't perform
232 * any special tricks to find out the "real" list of "all" lineitems
233 * in this context, so we fall back to the old method.
235 callback(this.getSelected(true, null, id_only));
238 /** @param all If true, assume all are selected */
239 this.getSelected = function(
241 callback /* If you want a "good" idea of "all" lineitems, you must
242 provide a callback that accepts an array parameter, rather than
243 relying on the return value of this method itself. */,
247 return this.getAll(callback, id_only);
249 var indices = {}; /* use to uniqify. needed in paging situations. */
250 dojo.forEach(this.selectors,
253 indices[i.parentNode.parentNode.getAttribute('li')] = true;
257 var result = openils.Util.objectProperties(indices);
260 result = result.map(function(liId) { return self.liCache[liId]; });
268 this.setRowAttr = function(td, liWrapper, field, type) {
269 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
270 td.appendChild(document.createTextNode(val));
273 this.setClaimPolicyControl = function(li, row) {
274 if (!self.claimPolicyPicker) {
275 self.claimPolicyPicker = true; /* prevents a race condition */
276 new openils.widget.AutoFieldWidget({
277 "parentNode": "acq-lit-li-claim-policy",
279 "selfReference": true,
280 "dijitArgs": {"required": true}
281 }).build(function(w) { self.claimPolicyPicker = w; });
284 if (!row) row = this._findLiRow(li);
286 var actViewPolicy = nodeByName("action_view_claim_policy", row);
287 if (li.claim_policy())
288 actViewPolicy.innerHTML = localeStrings.CHANGE_CLAIM_POLICY;
290 if (!actViewPolicy.onclick) {
291 actViewPolicy.onclick = function() {
292 if (li.claim_policy())
293 self.claimPolicyPicker.attr("value", li.claim_policy());
294 liClaimPolicyDialog.show();
295 liClaimPolicySave.onClick = function() {
296 self.changeClaimPolicy(
297 [li], self.claimPolicyPicker.attr("value"),
299 self.setClaimPolicyControl(li, row);
300 self.reconsiderClaimControl(li, row);
301 liClaimPolicyDialog.hide();
309 this.fetchClaimInfo = function(liId, force, callback, row) {
311 liId, function(full) {
312 self.liCache[full.id()] = full;
313 self.checkClaimEligibility(full, callback, row);
319 * Inserts a single lineitem into the growing table of lineitems
320 * @param {Object} li The lineitem object to insert
322 this.addLineitem = function(li, skip_final_placement) {
323 this.liCache[li.id()] = li;
325 // insert the row right away so that final order isn't
326 // dependent on how long subsequent async request take
327 // for a given line item
328 var row = self.rowTemplate.cloneNode(true);
329 if (!skip_final_placement) {
330 self.tbody.appendChild(row);
332 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
334 // sort the lineitem notes on edit_time
335 if(!li.lineitem_notes()) li.lineitem_notes([]);
337 var liWrapper = new openils.acq.Lineitem({lineitem:li});
338 row.setAttribute('li', li.id());
339 var tds = dojo.query('[attr]', row);
340 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
341 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
344 liWrapper.findAttr("isbn", "lineitem_marc_attr_definition") ||
345 liWrapper.findAttr("upc", "lineitem_marc_attr_definition");
347 // XXX media prefix for added content
349 nodeByName("jacket", row).setAttribute(
350 "src", "/opac/extras/ac/jacket/small/" + identifier
354 nodeByName("liid", row).innerHTML += li.id();
357 openils.Util.show(nodeByName('catalog', row), 'inline');
358 nodeByName("catalog_link", row).onclick = this.generateMakeRecTab(li.eg_bib_id());
360 openils.Util.show(nodeByName('link_to_catalog', row), 'inline');
361 nodeByName("link_to_catalog_link", row).onclick = function() { self.drawBibFinder(li) };
364 nodeByName("worksheet_link", row).href =
365 oilsBasePath + "/acq/lineitem/worksheet/" + li.id();
367 nodeByName("show_requests_link", row).href =
368 oilsBasePath + "/acq/picklist/user_request?lineitem=" + li.id();
370 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
371 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
372 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
374 if (!this.skipInitialEligibilityCheck)
378 function(full) { self.setClaimPolicyControl(full, row) },
382 this.updateLiNotesCount(li, row);
384 // show which PO this lineitem is a member of
385 if(li.purchase_order() && !this.isPO) {
387 this.poCache[li.purchase_order()] =
388 this.poCache[li.purchase_order()] ||
389 fieldmapper.standardRequest(
390 ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
392 this.authtoken, li.purchase_order(), {
393 "flesh_price_summary": true,
394 "flesh_provider" : true,
395 "flesh_lineitem_count": true
398 if(po && !this.isMeta) {
399 openils.Util.show(nodeByName('po', row), 'inline');
400 var link = nodeByName('po_link', row);
401 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
402 link.innerHTML += po.name();
404 openils.Util.show(nodeByName('pro', row), 'inline');
405 link = nodeByName('pro_link', row);
406 link.setAttribute('href', oilsBasePath + '/conify/global/acq/provider/' + po.provider().id())
407 link.innerHTML += po.provider().code();
411 // show which picklist this lineitem is a member of
412 if(li.picklist() && (this.isPO || this.isMeta || this.isUni)) {
414 this.plCache[li.picklist()] =
415 this.plCache[li.picklist()] ||
416 fieldmapper.standardRequest(
417 ['open-ils.acq', 'open-ils.acq.picklist.retrieve.authoritative'],
418 {params: [this.authtoken, li.picklist()]});
420 if (pl.name() == "") {
421 openils.Util.show(nodeByName("bib_origin", row), "inline");
425 openils.Util.show(nodeByName('pl', row), 'inline');
426 var link = nodeByName('pl_link', row);
427 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
428 link.innerHTML += pl.name();
433 var countNode = nodeByName('count', row);
434 var count = li.item_count() || 0;
435 if (typeof(this._copy_count_cb) == "function") {
436 this._copy_count_cb(li.id(), count);
438 countNode.innerHTML = count;
439 countNode.id = 'acq-lit-copy-count-label-' + li.id();
442 var priceInput = dojo.query('[name=price]', row)[0];
443 priceInput.value = li.estimated_unit_price() || '';
444 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
446 // show either "mark received" or "unreceive" as appropriate
447 this.updateLiState(li, row);
449 if (skip_final_placement) {
454 this._liCountClaims = function(li) {
456 for (var i = 0; i < li.lineitem_details().length; i++)
457 total += li.lineitem_details()[i].claims().length;
461 this._findLiRow = function(li) {
462 return dojo.query('tr[li="' + li.id() + '"]', "acq-lit-tbody")[0];
465 this.reconsiderClaimControl = function(li, row) {
466 if (!row) row = this._findLiRow(li);
467 var option = nodeByName("action_manage_claims", row);
468 var eligible = this.claimEligibleLidByLi[li.id()].length;
469 var count = this._liCountClaims(li);
471 option.disabled = !(count || eligible);
473 dojo.string.substitute(localeStrings.NUM_CLAIMS_EXISTING, [count]);
474 option.onclick = function() { self.claimDialog.show(li); };
477 this.clearEligibility = function(li) {
478 this.claimEligibleLidByLi[li.id()] = [];
480 if (li.lineitem_details()) {
481 li.lineitem_details().forEach(
482 function(lid) { delete self.claimEligibleLid[lid.id()]; }
486 if (this.copyCache) {
488 for (var k in this.copyCache) {
489 if (this.copyCache[k].lineitem() == li.id())
493 function(k) { delete self.claimEligibleLid[k]; }
498 this.checkClaimEligibility = function(li, callback, row) {
499 /* Assume always eligible, i.e. from this interface we don't care about
500 * claim eligibility any more. this is where the user would force a
502 this.clearEligibility(li);
503 this.claimEligibleLidByLi[li.id()] = li.lineitem_details().map(
504 function(lid) { return lid.id(); }
506 li.lineitem_details().forEach(
507 function(lid) { self.claimEligibleLid[lid.id()] = true; }
509 this.reconsiderClaimControl(li, row);
510 if (callback) callback(li);
512 this.clearEligibility(li);
513 fieldmapper.standardRequest(
514 ["open-ils.acq", "open-ils.acq.claim.eligible.lineitem_detail"], {
515 "params": [openils.User.authtoken, {"lineitem": li.id()}],
517 "onresponse": function(r) {
518 if (r = openils.Util.readResponse(r)) {
519 self.claimEligibleLidByLi[li.id()].push(
522 self.claimEligibleLid[r.lineitem_detail()] = true;
525 "oncomplete": function() {
526 self.reconsiderClaimControl(li, row);
527 if (typeof(callback) == "function")
535 this.updateLiNotesCount = function(li, row) {
536 if (!row) row = this._findLiRow(li);
538 var has_notes = (li.lineitem_notes().filter(
539 function(o) { return Boolean (o.alert_text()); }
542 /* U+2691 is the code point for a filled-in flag character */
543 nodeByName("notes_alert_flag", row).innerHTML =
544 has_notes ? "⚑" : "";
545 nodeByName("noteslink", row).style.fontStyle =
546 has_notes ? "italic" : "normal";
547 nodeByName("notes_count", row).innerHTML = li.lineitem_notes().length;
550 /* XXX NOT related to _updateLiState(). rethink */
551 this.updateLiState = function(li, row) {
552 if (!row) row = this._findLiRow(li);
554 var actReceive = nodeByName("action_mark_recv", row);
555 var actUnRecv = nodeByName("action_mark_unrecv", row);
556 var actUpdateBarcodes = nodeByName("action_update_barcodes", row);
557 var actHoldingsMaint = nodeByName("action_holdings_maint", row);
559 var actNewInvoice = nodeByName('action_new_invoice', row);
560 var actLinkInvoice = nodeByName('action_link_invoice', row);
561 var actViewInvoice = nodeByName('action_view_invoice', row);
563 nodeByName('action_view_history', row).onclick =
564 function() { location.href = oilsBasePath + '/acq/lineitem/history/' + li.id(); };
566 var state_cell = nodeByName("li_state", row);
568 if (li.state() == "cancelled") {
569 if (typeof li.cancel_reason() == "object") {
570 var holds_state = dojo.create(
572 "style": "border-bottom: 1px dashed #000;",
573 "innerHTML": li.state()
574 }, state_cell, "only"
578 "label": "<em>" + li.cancel_reason().label() +
579 "</em><br />" + li.cancel_reason().description(),
580 "connectId": [holds_state]
581 }, dojo.create("span", null, state_cell, "last")
584 state_cell.innerHTML = li.state(); // TODO i18n state labels
587 state_cell.innerHTML = li.state(); // TODO i18n state labels
591 /* handle row coloring for based on LI state */
592 openils.Util.removeCSSClass(row, /^oils-acq-li-state-/);
593 openils.Util.addCSSClass(row, "oils-acq-li-state-" + li.state());
595 /* handle links that appear/disappear based on whether LI is received */
599 actNewInvoice.onclick = function() {
600 location.href = oilsBasePath + '/acq/invoice/view?create=1&attach_li=' + li.id();
601 nodeByName("action_none", row).selected = true;
603 actLinkInvoice.onclick = function() {
604 if (!self.invoiceLinkDialogManager) {
605 self.invoiceLinkDialogManager =
606 new InvoiceLinkDialogManager("li");
608 self.invoiceLinkDialogManager.target = li;
609 acqLitLinkInvoiceDialog.show();
610 nodeByName("action_none", row).selected = true;
612 actViewInvoice.onclick = function() {
613 location.href = oilsBasePath +
614 "/acq/search/unified?so=" +
615 base64Encode({"jub":[{"id": li.id()}]}) +
617 nodeByName("action_none", row).selected = true;
620 actNewInvoice.disabled = false;
621 actLinkInvoice.disabled = false;
622 actViewInvoice.disabled = false;
626 actReceive.disabled = false;
627 actReceive.onclick = function() {
628 if (self.checkLiAlerts(li.id()))
629 self.issueReceive(li);
630 nodeByName("action_none", row).selected = true;
635 actUnRecv.disabled = false;
636 actUnRecv.onclick = function() {
637 if (confirm(localeStrings.UNRECEIVE_LI))
638 self.issueReceive(li, /* rollback */ true);
639 nodeByName("action_none", row).selected = true;
641 // TODO we should allow editing before receipt, in which case the
642 // test should be "if 1 or more real (acp) copies exist
643 actUpdateBarcodes.disabled = false;
644 actUpdateBarcodes.onclick = function() {
645 self.showRealCopyEditUI(li);
646 nodeByName("action_none", row).selected = true;
648 actHoldingsMaint.disabled = false;
649 actHoldingsMaint.onclick = self.generateMakeRecTab( li.eg_bib_id(), 'copy_browser', row );
657 this._setAlertStore = function() {
658 acqLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
660 "data": acqliat.toStoreData(
662 "acqliat", {"id": {"!=": null}}
667 acqLitAlertAlertText.setValue(); /* make the store "live" */
668 acqLitAlertAlertText._store_ready = true;
672 * Draws and shows the lineitem notes pane
674 this.drawLiNotes = function(li) {
677 if (!acqLitAlertAlertText._store_ready)
678 this._setAlertStore();
681 li.lineitem_notes().sort(
683 if(a.edit_time() < b.edit_time()) return 1;
689 while(this.liNotesTbody.childNodes[0])
690 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
693 acqLitCreateNoteSubmit.onClick = function() {
694 var value = acqLitCreateNoteText.attr('value');
696 var note = new fieldmapper.acqlin();
699 Boolean(acqLitCreateNoteVendorPublic.attr('checked'))
702 note.lineitem(li.id());
704 self.updateLiNotes(li, note);
705 acqLitCreateNoteVendorPublic.attr("checked", false);
706 acqLitCreateNoteText.attr("value", "");
709 acqLitCreateAlertSubmit.onClick = function() {
710 if (!acqLitAlertAlertText.item) {
711 alert(localeStrings.ALERT_UNSELECTED);
715 var alert_text = new fieldmapper.acqliat().fromStoreItem(
716 acqLitAlertAlertText.item
718 var value = acqLitAlertNoteValue.attr("value") || "";
720 var note = new fieldmapper.acqlin();
722 note.lineitem(li.id());
724 note.alert_text(alert_text);
726 self.updateLiNotes(li, note);
729 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
733 * Draws a single lineitem note in the notes pane
735 this.addLiNote = function(li, note) {
736 if(note.isdeleted()) return;
738 var row = self.liNotesRow.cloneNode(true);
739 nodeByName("value", row).innerHTML = note.value();
740 var alert_node = nodeByName("alert_code", row);
741 if (note.alert_text()) {
742 alert_node.innerHTML = note.alert_text().code();
743 if (note.alert_text().description()) {
746 "connectId": [alert_node],
747 "label": note.alert_text().description()
748 }, dojo.create("span", null, alert_node, "after")
753 if (openils.Util.isTrue(note.vendor_public()))
754 nodeByName("vendor_public", row).innerHTML =
755 localeStrings.VENDOR_PUBLIC;
757 nodeByName("delete", row).onclick = function() {
758 note.isdeleted(true);
759 self.liNotesTbody.removeChild(row);
760 self.updateLiNotes(li);
763 if(note.edit_time()) {
764 nodeByName("edit_time", row).innerHTML =
765 dojo.date.locale.format(
766 dojo.date.stamp.fromISOString(note.edit_time()),
767 {formatLength:'short'});
770 self.liNotesTbody.appendChild(row);
774 * Updates any new/changed/deleted notes on the server
776 this.updateLiNotes = function(li, newNote) {
782 notes = li.lineitem_notes().filter(
784 if(note.ischanged() || note.isnew() || note.isdeleted())
790 if(notes.length == 0) return;
791 progressDialog.show();
793 fieldmapper.standardRequest(
794 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
796 params : [this.authtoken, notes],
797 onresponse : function(r) {
798 var resp = openils.Util.readResponse(r);
803 // remove the old changed notes
805 dojo.forEach(li.lineitem_notes(),
807 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
811 li.lineitem_notes(list);
814 progressDialog.hide();
815 self.updateLiNotesCount(li);
816 self.drawLiNotes(li);
820 progressDialog.update(resp);
821 var newnote = resp.note;
823 if(!newnote.isdeleted()) {
824 newnote.isnew(false);
825 newnote.ischanged(false);
826 li.lineitem_notes().push(newnote);
833 this.updateLiPrice = function(input, li) {
835 var price = input.value;
836 if(Number(price) == Number(li.estimated_unit_price())) return;
838 fieldmapper.standardRequest(
839 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
840 { async : false, // redundant w/ timeout
842 params : [this.authtoken, li.id(), price],
843 oncomplete : function(r) {
844 openils.Util.readResponse(r);
845 li.estimated_unit_price(price); // update local copy
851 this.removeLineitem = function(liId) {
852 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
853 delete this.liCache[liId];
854 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
857 this.drawInfo = function(liId) {
858 if (!this._isRelatedViewer) {
859 var d = dojo.byId("acq-lit-info-related");
860 if (!this.relCache[liId]) {
861 fieldmapper.standardRequest(
864 "open-ils.acq.lineitems_for_bib.by_lineitem_id.count"
867 "params": [openils.User.authtoken, liId],
868 "onresponse": function(r) {
869 self.relCache[liId] = openils.Util.readResponse(r);
870 nodeByName("related_number", d).innerHTML =
873 self.relCache[liId] >1 ? "show" : "hide"
879 nodeByName("related_number", d).innerHTML = this.relCache[liId];
880 openils.Util[this.relCache[liId] > 1 ? "show" : "hide"](d);
885 openils.acq.Lineitem.fetchAttrDefs(
887 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
892 /* For a given list of lineitem ids, build a list of full lineitems
893 * re-using the fetching logic that is otherwise typical to use in this
896 * If we've already got a lineitem in the cache, just use that.
898 * Once we've built a list of lineitems, call callback(thatlist).
900 this.fetchLineitemsById = function(id_list, callback) {
901 var total = id_list.length;
902 var result_list = [];
904 var inner = function(li) {
907 callback(result_list);
910 id_list.forEach(function(id) { self._fetchLineitem(id, inner); });
913 this._fetchLineitem = function(liId, handler, force) {
915 var li = this.liCache[liId];
916 if(li && li.marc() && li.lineitem_details() && !force)
919 fieldmapper.standardRequest(
920 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve.authoritative'],
923 params: [self.authtoken, liId, {
925 flesh_cancel_reason: true,
926 flesh_li_details: true,
928 flesh_fund_debit: true }],
930 oncomplete: function(r) {
931 var li = openils.Util.readResponse(r);
932 self.liCache[liId] = li;
939 this._drawInfo = function(li) {
941 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
944 openils.Util.hide('acq-lit-marc-order-record-label');
945 openils.Util.hide(acqLitEditOrderMarc.domNode);
946 openils.Util.show('acq-lit-marc-real-record-label');
948 openils.Util.show('acq-lit-marc-order-record-label');
949 openils.Util.show(acqLitEditOrderMarc.domNode);
950 openils.Util.hide('acq-lit-marc-real-record-label');
953 this.drawMarcHTML(li);
954 this.infoTbody = dojo.byId('acq-lit-info-tbody');
957 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
958 while(this.infoTbody.childNodes[0])
959 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
961 for(var i = 0; i < li.attributes().length; i++) {
962 var attr = li.attributes()[i];
963 var row = this.infoRow.cloneNode(true);
965 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
966 var name = openils.acq.Lineitem.attrDefs[type].filter(
968 return (a.code() == attr.attr_name());
970 ).pop().description();
972 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
973 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
974 this.infoTbody.appendChild(row);
977 if (!this._isRelatedViewer) {
978 nodeByName("rel_link", dojo.byId("acq-lit-info-related")).href =
979 oilsBasePath + "/acq/lineitem/related/" + li.id();
984 this.generateMakeRecTab = function(bib_id,default_view, row) {
988 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
991 show_nav_buttons : true,
992 show_print_button : true,
993 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + bib_id),
994 default_view : default_view
998 if(row) nodeByName("action_none", row).selected = true;
1002 this.drawMarcHTML = function(li) {
1003 var params = [null, true, li.marc()];
1005 params = [li.eg_bib_id(), true];
1007 fieldmapper.standardRequest(
1008 ['open-ils.search', 'open-ils.search.biblio.record.html'],
1011 oncomplete: function(r) {
1012 dojo.byId('acq-lit-marc-div').innerHTML =
1013 openils.Util.readResponse(r);
1019 this.drawCopies = function(liId, force_fetch) {
1020 if (typeof force_fetch == "undefined")
1021 force_fetch = false;
1023 openils.acq.Lineitem.fetchAndRender(liId, {},
1024 function(li, html) {
1025 dojo.byId('acq-lit-copies-li-summary').innerHTML = html;
1029 this.show('copies');
1031 this.copyCache = {};
1032 this.copyWidgetCache = {};
1033 this.oldCopyWidgetCache = {};
1034 this.virtDfaCounts = {};
1035 this.realDfaCache = {};
1038 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
1039 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
1040 acqLitCopyCountInput.attr('value', '0');
1042 while(this.copyTbody.childNodes[0])
1043 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
1045 this._drawBatchCopyWidgets();
1047 this._drawDistribApplied(liId);
1049 this._fetchDistribFormulas(
1051 openils.acq.Lineitem.fetchAttrDefs(
1053 self._fetchLineitem(liId, function(li){self._drawCopies(li);}, force_fetch);
1060 this._saveDistribAppliedTemplates = function() {
1061 if (!this._appliedDistribTemplate) {
1062 this._appliedDistribTemplate =
1063 dojo.byId("acq-lit-distrib-applied-tbody").
1064 removeChild(dojo.byId("acq-lit-distrib-applied-row"));
1065 dojo.attr(this._appliedDistribTemplate, "id");
1069 this._drawDistribApplied = function(liId) {
1070 /* Build this table while hidden to prevent rendering artifacts */
1071 openils.Util.hide("acq-lit-distrib-applied-tbody");
1073 this._saveDistribAppliedTemplates();
1075 /* Remove any rows in the table from previous populations */
1076 dojo.query("tr[formula]", "acq-lit-distrib-applied-tbody").
1077 forEach(dojo.destroy);
1079 /* Unregister all dijits previously created (for some reason this isn't
1080 * covered by the above destroy calls). */
1081 dijit.registry.forEach(
1082 function(w) { if (/^dfa-/.test(w.id)) w.destroyRecursive(); }
1085 /* Populate the table with our liId */
1087 fieldmapper.standardRequest(
1089 "open-ils.acq.distribution_formula_application.ranged.retrieve"],
1092 "params": [self.authtoken, liId],
1093 "onresponse": function(r) {
1094 var dfa = openils.Util.readResponse(r);
1097 self.realDfaCache[dfa.id()] = dfa;
1098 self._drawDistribAppliedUnit(dfa);
1101 "oncomplete": function() {
1102 /* Reveal built table */
1105 "acq-lit-distrib-applied-tbody", "table-row-group"
1113 this._drawDistribAppliedUnit = function(dfa) {
1114 var new_row = false;
1115 var row = dojo.query(
1116 'tr[formula="' + dfa.formula().id() + '"]',
1117 "acq-lit-distrib-applied-tbody"
1122 row = dojo.clone(this._appliedDistribTemplate);
1123 dojo.attr(row, "formula", dfa.formula().id());
1124 dojo.query("th", row)[0].innerHTML = dfa.formula().name();
1127 var td = dojo.query("td", row)[0];
1129 dojo.create("span", {"id": "dfa-button-" + dfa.id()}, td, "last");
1130 dojo.create("span", {"id": "dfa-tip-" + dfa.id()}, td, "last");
1133 dojo.place(row, "acq-lit-distrib-applied-tbody", "last");
1135 new dijit.form.Button(
1137 "onClick": function() {
1138 if (confirm(localeStrings.EXPLAIN_DFA_MGMT))
1139 self.deleteDfa(dfa);
1142 /* XXX I /cannot/ make the following work in as a CSS class
1143 * for some reason. So frustrating... */
1144 "style": function(id) {
1146 "font-weight: bold; color: #c00;" :
1148 }(dfa.id()) + "margin: 0 6px;display: inline;"
1149 }, "dfa-button-" + dfa.id()
1153 "connectId": ["dfa-button-" + dfa.id()],
1154 "label": dojo.string.substitute(
1155 localeStrings.DFA_TIP, dfa.id() > 0 ? [
1156 openils.User.formalName(dfa.creator()),
1157 dojo.date.locale.format(
1158 dojo.date.stamp.fromISOString(dfa.create_time()),
1159 {"formatLength":"short"}
1161 ] : [localeStrings.ITS_YOU, localeStrings.JUST_NOW]
1163 }, "dfa-tip-" + dfa.id()
1167 this.deleteDfa = function(dfa) {
1168 if (dfa.id() > 0) { /* real */
1169 this.pcrud.eliminate(
1172 "oncomplete": function() {
1173 self._removeDistribApplied(dfa.id());
1174 delete self.realDfaCache[dfa.id()];
1178 } else { /* virtual */
1179 if (--(this.virtDfaCounts[dfa.formula().id()]) < 0)
1180 this.virtDfaCounts[dfa.formula().id()] = 0;
1181 /* hasn't been saved yet, so no need to do anything server side */
1182 this._removeDistribApplied(dfa.id());
1187 this._removeDistribApplied = function(dfaId) {
1188 var re = new RegExp("^dfa-\\w+-" + String(dfaId));
1189 dijit.registry.forEach(
1190 function(w) { if (re.test(w.id)) w.destroyRecursive(); }
1192 this._removeDistribAppliedEmptyRows();
1195 this._removeAllDistribAppliedVirtual = function() {
1196 /* Unregister dijits */
1197 dijit.registry.forEach(
1198 function(w) { if (/^dfa-\w+--/.test(w.id)) w.destroyRecursive(); }
1200 this._removeDistribAppliedEmptyRows();
1203 this._removeDistribAppliedEmptyRows = function() {
1204 /* Remove any rows with no DFA at all */
1205 dojo.query("tr[formula] td", "acq-lit-distrib-applied-tbody").forEach(
1207 if (o.childNodes.length < 1) dojo.destroy(o.parentNode);
1213 * Insert a new row into the distribution formula selection form
1215 this._addDistribFormulaRow = function() {
1218 if (!self.distribForms) {
1219 // no formulas, hide the form
1220 openils.Util.hide('acq-lit-distrib-formula-table');
1224 if(!this.distribFormulaTemplate)
1225 this.distribFormulaTemplate =
1226 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
1228 var row = this.distribFormulaTemplate.cloneNode(true);
1229 dojo.place(row, "acq-lit-distrib-formula-tbody", "only");
1231 this.dfSelector = new dijit.form.FilteringSelect(
1232 {"labelAttr": "dynLabel", "labelType": "html"},
1233 nodeByName("selector", row)
1235 this._updateFormulaStore();
1236 this.dfSelector.fetchProperties =
1237 {"sort": [{"attribute": "use_count", "descending": true}]};
1239 var apply = new dijit.form.Button(
1240 {"label": localeStrings.APPLY},
1241 nodeByName('set_button', row)
1244 var reset = new dijit.form.Button(
1245 {"label": localeStrings.RESET_FORMULAE, "disabled": true},
1246 nodeByName("reset_button", row)
1249 dojo.connect(apply, 'onClick',
1251 var form_id = self.dfSelector.attr("value");
1252 if(!form_id) return;
1253 self._applyDistribFormula(form_id);
1254 reset.attr("disabled", false);
1258 dojo.connect(reset, 'onClick',
1260 self.restoreCopyFieldsBeforeDF();
1261 self.virtDfaCounts = {};
1262 self.virtDfaId = -1;
1264 self._updateFormulaStore();
1265 self._removeAllDistribAppliedVirtual();
1266 reset.attr("disabled", "true");
1273 * Applies a distrib formula to the current set of copies
1275 this._applyDistribFormula = function(formula) {
1276 if(!formula) return;
1278 formula = this.distribForms.filter(
1279 function(form) { return form.id() == formula; }
1282 var copyRows = dojo.query('tr', self.copyTbody);
1284 if (this.dfeOffset >= copyRows.length) {
1285 alert(localeStrings.OUT_OF_COPIES);
1289 var entries_applied = 0;
1291 var rowIndex = this.dfeOffset;
1292 rowIndex < copyRows.length;
1296 var row = copyRows[rowIndex];
1297 var copy_id = row.getAttribute('copy_id');
1298 var copyWidgets = this.copyWidgetCache[copy_id];
1299 var entryIndex = this.dfeOffset;
1302 // find the correct entry for the current row
1303 dojo.forEach(formula.entries(),
1306 entryIndex += e.item_count();
1307 if(entryIndex > rowIndex)
1315 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
1316 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
1319 this.saveCopyFieldsBeforeDF(copy_id);
1320 this._copy_fields_for_acqdf.forEach(
1322 if(entry[field]()) {
1323 copyWidgets[field].attr('value', (entry[field]()));
1330 if (entries_applied) {
1331 this.virtDfaCounts[formula.id()] =
1332 ++(this.virtDfaCounts[formula.id()]) || 1;
1333 this._updateFormulaStore();
1334 this._drawDistribAppliedUnit(
1336 var dfa = new acqdfa();
1337 dfa.formula(df); dfa.id(self.virtDfaId--); return dfa;
1340 this.dfeOffset += entries_applied;
1345 * This function updates the DF store for the dropdown so that use_counts
1346 * can reflect DF applications from this session before they're saved
1349 this._updateFormulaStore = function() {
1350 this.dfSelector.store = new dojo.data.ItemFileReadStore(
1352 "data": self._labelFormulasWithCounts(
1353 acqdf.toStoreData(self.distribForms)
1359 this.saveCopyFieldsBeforeDF = function(copy_id) {
1361 if (!this.oldCopyWidgetCache[copy_id]) {
1362 var copyWidgets = this.copyWidgetCache[copy_id];
1364 this.oldCopyWidgetCache[copy_id] = {};
1365 this._copy_fields_for_acqdf.forEach(
1367 self.oldCopyWidgetCache[copy_id][f] =
1368 copyWidgets[f].attr("value");
1374 this.restoreCopyFieldsBeforeDF = function() {
1376 for (var copy_id in this.oldCopyWidgetCache) {
1377 this._copy_fields_for_acqdf.forEach(
1379 self.copyWidgetCache[copy_id][f].attr(
1380 "value", self.oldCopyWidgetCache[copy_id][f]
1387 this._labelFormulasWithCounts = function(store_data) {
1388 for (var key in store_data.items) {
1389 var obj = store_data.items[key];
1390 obj.use_count = Number(obj.use_count); /* needed for sorting */
1392 if (this.virtDfaCounts[obj.id])
1393 obj.use_count = obj.use_count + Number(this.virtDfaCounts[obj.id]);
1395 obj.dynLabel = "<span class='acq-lit-distrib-form-use-count'>[" +
1396 obj.use_count + "]</span> " + obj.name;
1402 * This method formerly would not refetch the DF formulas if they'd been
1403 * loaded already, but now it always re-fetches, since use_count changes.
1405 /** TODO: port distrib-formula selector to autofieldwidget+pcrud/dojo store */
1406 this._fetchDistribFormulas = function(onload) {
1407 fieldmapper.standardRequest(
1409 "open-ils.acq.distribution_formula.ranged.retrieve.atomic"],
1412 "params": [openils.User.authtoken, 0, 500],
1413 "oncomplete": function(r) {
1414 self.distribForms = openils.Util.readResponse(r);
1415 if(!self.distribForms || self.distribForms.length == 0) {
1416 self.distribForms = [];
1418 self._addDistribFormulaRow();
1425 this._drawBatchCopyWidgets = function() {
1426 var row = this.copyBatchRow;
1427 dojo.forEach(liDetailBatchFields,
1429 if(self.copyBatchRowDrawn) {
1430 self.copyBatchWidgets[field].attr('value', null);
1432 var widget = new openils.widget.AutoFieldWidget({
1435 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1436 searchFormat : (field == 'fund') ? fundSearchFormat : null,
1437 searchFilter : (field == 'fund') ? {"active": "t"} : null,
1438 parentNode : dojo.query('[name='+field+']', row)[0],
1439 orgLimitPerms : ['CREATE_PICKLIST'],
1442 "labelType": (field == "fund") ? "html" : null
1444 noCache: (field == "fund"),
1449 if (field == "fund" && w.store)
1450 self._ensureCSSFundClasses(w.store);
1451 self.copyBatchWidgets[field] = w;
1454 if (field == "fund") {
1456 widget.widget, "onChange", function(val) {
1457 self._updateFundSelectorStyle(widget, val);
1464 this.copyBatchRowDrawn = true;
1467 this.batchCopyUpdate = function() {
1469 for(var k in this.copyWidgetCache) {
1470 var cache = this.copyWidgetCache[k];
1471 dojo.forEach(liDetailBatchFields, function(f) {
1472 var newval = self.copyBatchWidgets[f].attr('value');
1473 if(newval) cache[f].attr('value', newval);
1478 this._drawCopies = function(li) {
1481 // this button sets the total number of copies for a given lineitem
1482 acqLitAddCopyCount.onClick = function() {
1483 var count = acqLitCopyCountInput.attr('value');
1486 while(self.copyCount() < count)
1489 // delete rows if necessary
1490 var diff = self.copyCount() - count;
1492 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
1493 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
1494 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
1496 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1502 if(li.lineitem_details().length > 0) {
1503 dojo.forEach(li.lineitem_details(),
1505 self.addCopy(li, copy);
1513 this.copyCount = function() {
1515 for(var id in this.copyCache) {
1516 if(!this.copyCache[id].isdeleted())
1522 this.virtCopyId = -1;
1523 this.addCopy = function(li, copy) {
1524 var row = this.copyRow.cloneNode(true);
1525 this.copyTbody.appendChild(row);
1529 copy = new fieldmapper.acqlid();
1531 copy.id(this.virtCopyId--);
1532 copy.lineitem(li.id());
1535 this.copyCache[copy.id()] = copy;
1536 row.setAttribute('copy_id', copy.id());
1537 self.copyWidgetCache[copy.id()] = {};
1539 acqLitCopyCountInput.attr('value', self.copyCount()+'');
1541 var rcvr = copy.receiver();
1543 if (!userCache[rcvr]) {
1544 if(rcvr == openils.User.user.id()) {
1545 userCache[rcvr] = openils.User.user;
1547 userCache[rcvr] = fieldmapper.standardRequest(
1548 ['open-ils.actor', 'open-ils.actor.user.retrieve'],
1549 {params: [openils.User.authtoken, rcvr]}
1553 dojo.query('[name=receiver]', row)[0].innerHTML = userCache[rcvr].usrname();
1556 dojo.forEach(liDetailFields,
1559 if (field == "fund") {
1560 searchFilter = (copy.fund() ?
1561 {"-or": {"active": "t", "id": copy.fund()}} :
1564 searchFilter = null;
1567 var readOnly = false;
1569 // TODO: Add support for changing the owning_lib after real copies have been made.
1570 // owning_lib is order data as much as its item data
1571 if(copy.eg_copy_id() && ['owning_lib', 'location', 'circ_modifier', 'cn_label', 'barcode'].indexOf(field) >= 0) {
1575 // TODO: add support for changing the fund after debits have been created
1576 // Note: invoicing allows the change
1577 if(copy.fund_debit() && field == 'fund') {
1582 var widget = new openils.widget.AutoFieldWidget({
1585 labelFormat : (field == 'fund') ? fundLabelFormat : null,
1586 searchFormat : (field == 'fund') ? fundSearchFormat : null,
1587 dijitArgs: {"labelType": (field == 'fund') ? "html" : null},
1588 searchFilter : searchFilter,
1589 noCache: (field == "fund"),
1591 parentNode : dojo.query('[name='+field+']', row)[0],
1592 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
1593 readOnly : readOnly,
1594 orgDefaultsToWs : true
1598 // make sure we capture the value from any async widgets
1601 if (field == "fund" && w.store)
1602 self._ensureCSSFundClasses(w.store);
1605 copy[field](ww.getFormattedValue())
1607 self.copyWidgetCache[copy.id()][field] = w;
1609 dojo.connect(w, 'onChange',
1611 if (field == "fund")
1612 self._updateFundSelectorStyle(widget, val);
1614 if (!readOnly && (copy.isnew() || val != copy[field]())) {
1615 // prevent setting ischanged() automatically on widget load for existing copies
1616 copy[field](widget.getFormattedValue())
1617 copy.ischanged(true);
1626 this.updateLidState(copy, row);
1629 this._ensureCSSFundClass = function(id) {
1630 if (!this.fundStyleSheet) {
1632 "style", {"type": "text/css"},
1633 document.getElementsByTagName("head")[0], "last"
1635 this.fundStyleSheet = document.styleSheets[
1636 document.styleSheets.length - 1
1640 var cn = "fund_" + id;
1641 if (!this.haveFundClass[cn]) {
1642 fieldmapper.standardRequest(
1643 ["open-ils.acq", "open-ils.acq.fund.check_balance_percentages"],
1645 "params": [openils.User.authtoken, id],
1647 "oncomplete": function(r) {
1648 r = openils.Util.readResponse(r);
1649 self.fundBalanceState[id] = r;
1651 if (r[0] /* stop */)
1652 style = fundStyles.stop;
1653 else if (r[1] /* warning */)
1654 style = fundStyles.warning;
1655 self.fundStyleSheet.insertRule(
1656 "." + cn + " { " + style + " }",
1657 self.fundStyleSheet.cssRules.length
1659 self.haveFundClass[cn] = true;
1666 this._ensureCSSFundClasses = function(store) {
1668 "query": {"id": "*"},
1669 "onItem": function(o) { self._ensureCSSFundClass(o.id[0]); }
1673 this._updateFundSelectorStyle = function(widget, fund_id) {
1674 openils.Util.removeCSSClass(widget.widget.domNode, /fund_\d+/);
1675 openils.Util.addCSSClass(widget.widget.domNode, "fund_" + fund_id);
1678 this.updateLidState = function(copy, row) {
1679 if (typeof(row) == "undefined") {
1681 'tr[copy_id="' + copy.id() + '"]', this.copyTbody
1686 var recv_link = nodeByName("receive", row);
1687 var unrecv_link = nodeByName("unreceive", row);
1688 var del_link = nodeByName("delete", row);
1689 var cxl_link = nodeByName("cancel", row);
1690 var claim_link = nodeByName("claim", row);
1691 var cxl_reason_link = nodeByName("cancel_reason", row);
1693 if (copy.cancel_reason()) {
1694 openils.Util.hide(del_link.parentNode);
1695 openils.Util.hide(recv_link);
1696 openils.Util.hide(unrecv_link);
1697 openils.Util.hide(cxl_link);
1698 openils.Util.hide(claim_link);
1700 /* XXX the following may leak memory in a long lived table: dijits may not get destroyed... not positive. revisit. */
1701 var holds_reason = dojo.create(
1703 "style": "border-bottom: 1px dashed #000;",
1704 "innerHTML": "Cancelled" /* XXX [sic] and i18n */
1705 }, cxl_reason_link, "only"
1709 "label": "<em>" + copy.cancel_reason().label() +
1710 "</em><br />" + copy.cancel_reason().description(),
1711 "connectId": [holds_reason]
1712 }, dojo.create("span", null, cxl_reason_link, "last")
1714 openils.Util.show(cxl_reason_link, "inline");
1715 } else if (this.isPO) {
1716 /* Only using this in one place so far, but may want it for better
1717 * decisions on when to display certain controls. */
1718 var li_state = this.liCache[copy.lineitem()].state();
1720 openils.Util.hide(del_link.parentNode);
1721 openils.Util.hide(cxl_reason_link);
1723 /* Avoid showing (un)receive links, cancel links, for virt copies */
1724 if (copy.id() > 0) {
1725 if (copy.recv_time()) {
1726 openils.Util.hide(cxl_link);
1727 openils.Util.hide(recv_link);
1728 openils.Util.hide(claim_link);
1730 openils.Util.show(unrecv_link, "inline");
1731 unrecv_link.onclick = function() {
1732 if (confirm(localeStrings.UNRECEIVE_LID))
1733 self.issueReceive(copy, /* rollback */ true);
1736 openils.Util.hide(unrecv_link);
1738 if (this.claimEligibleLid[copy.id()]) {
1739 openils.Util.show(claim_link, "inline");
1740 claim_link.onclick = function() {
1741 self.claimDialog.show(
1742 self.liCache[copy.lineitem()], copy.id()
1746 openils.Util.hide(claim_link);
1749 openils.Util[li_state == "on-order" ? "show" : "hide"](
1752 openils.Util.show(cxl_link, "inline");
1753 recv_link.onclick = function() {
1754 if (self.checkLiAlerts(copy.lineitem()))
1755 self.issueReceive(copy);
1757 cxl_link.onclick = function() {
1758 self.cancelLid(copy.id());
1762 openils.Util.hide(cxl_link);
1763 openils.Util.hide(unrecv_link);
1764 openils.Util.hide(recv_link);
1765 openils.Util.hide(claim_link);
1768 openils.Util.hide(unrecv_link);
1769 openils.Util.hide(recv_link);
1770 openils.Util.hide(cxl_reason_link);
1771 openils.Util.hide(claim_link);
1773 del_link.onclick = function() { self.deleteCopy(row) };
1774 openils.Util.show(del_link.parentNode);
1778 this.cancelLid = function(lid_id) {
1779 lidCancelDialog._lid_id = lid_id;
1780 openils.Util.show(lidCancelDialog.domNode.parentNode);
1781 lidCancelDialog.show();
1782 if (!lidCancelDialog._prepared) {
1783 var widget = new openils.widget.AutoFieldWidget({
1784 "fmField": "cancel_reason",
1785 "fmClass": "acqlid",
1786 "parentNode": dojo.byId("acq-lit-lid-cancel-reason"),
1787 "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
1792 acqLidCancelButton.onClick = function() {
1793 if (w.attr("value")) {
1794 if (confirm(localeStrings.LID_CANCEL_CONFIRM)) {
1796 lidCancelDialog._lid_id,
1800 lidCancelDialog.hide();
1803 lidCancelDialog._prepared = true;
1809 this._cancelLid = function(lid_id, reason) {
1810 fieldmapper.standardRequest(
1811 ["open-ils.acq", "open-ils.acq.lineitem_detail.cancel"], {
1812 "params": [openils.User.authtoken, lid_id, reason],
1814 "onresponse": function(r) {
1815 if (r = openils.Util.readResponse(r)) {
1817 for (var id in r.lid) {
1818 /* actually this should only iterate once */
1819 self.copyCache[id].cancel_reason(
1820 r.lid[id].cancel_reason
1822 self.updateLidState(self.copyCache[id]);
1831 this._confirmAlert = function(li, lin) {
1833 dojo.string.substitute(
1834 localeStrings.CONFIRM_LI_ALERT, [
1835 (new openils.acq.Lineitem({"lineitem": li})).findAttr(
1836 "title", "lineitem_marc_attr_definition"
1838 lin.alert_text().code(),
1839 lin.alert_text().description() || "",
1846 this.checkLiAlerts = function(li_id) {
1847 var li = this.liCache[li_id];
1849 var alert_notes = li.lineitem_notes().filter(
1850 function(o) { return Boolean(o.alert_text()); }
1853 /* this is _intentionally_ not done in a call to forEach() ... */
1854 for (var i = 0; i < alert_notes.length; i++) {
1855 if (this.noteAcks[alert_notes[i].id()])
1857 else if (!this._confirmAlert(li, alert_notes[i]))
1860 this.noteAcks[alert_notes[i].id()] = true;
1866 this.deleteCopy = function(row) {
1867 var copy = this.copyCache[row.getAttribute('copy_id')];
1868 copy.isdeleted(true);
1870 delete this.copyCache[copy.id()];
1871 this.copyTbody.removeChild(row);
1874 this._virtDfaCountsAsList = function() {
1876 for (var key in this.virtDfaCounts) {
1877 for (var i = 0; i < this.virtDfaCounts[key]; i++)
1883 this.confirmBreachedCopyFunds = function(copies) {
1884 var stop = 0, warning = 0;
1888 var state = self.fundBalanceState[o.fund()];
1889 if (state[0] /* stop */)
1891 else if (state[1] /* warning */)
1898 return confirm(localeStrings.CONFIRM_FUNDS_AT_STOP);
1899 } else if (warning) {
1900 return confirm(localeStrings.CONFIRM_FUNDS_AT_WARNING);
1905 this.saveCopyChanges = function(liId) {
1911 for(var id in this.copyCache) {
1912 var c = this.copyCache[id];
1913 if(!c.isdeleted()) total++;
1914 if(c.isnew() || c.ischanged() || c.isdeleted()) {
1915 if(c.id() < 0) c.id(null);
1921 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
1924 if (copies.length > 0) {
1925 if (!this.confirmBreachedCopyFunds(copies))
1928 if (typeof(this._copy_count_cb) == "function")
1929 this._copy_count_cb(liId, total);
1931 openils.Util.show("acq-lit-update-copies-progress");
1932 fieldmapper.standardRequest(
1933 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
1935 params: [openils.User.authtoken, copies],
1936 onresponse: function(r) {
1937 var res = openils.Util.readResponse(r);
1938 litUpdateCopiesProgress.update(res);
1940 oncomplete: function() {
1941 self.drawCopies(liId, true /* force_fetch */);
1942 openils.Util.hide("acq-lit-update-copies-progress");
1948 var dfa_list = this._virtDfaCountsAsList();
1949 if (dfa_list.length > 0) {
1950 fieldmapper.standardRequest(
1952 "open-ils.acq.distribution_formula.record_application"],
1955 "params": [openils.User.authtoken, dfa_list, liId],
1956 "onresponse": function(r) {
1957 var res = openils.Util.readResponse(r);
1958 if (res && res.length < dfa_list.length)
1959 alert(localeStrings.DFA_NOT_ALL);
1963 this.virtDfaCounts = {};
1967 this._updateCreatePoPrepayCheckbox = function(prepay) {
1968 var prepay = openils.Util.isTrue(prepay);
1969 this._prepayRequiredByVendor = prepay;
1970 dijit.byId("acq-lit-po-prepay").attr("checked", prepay);
1973 this._confirmPoPrepaySituation = function() {
1974 var want_prepay = dijit.byId("acq-lit-po-prepay").attr("checked");
1975 if (want_prepay != this._prepayRequiredByVendor) {
1978 localeStrings.VENDOR_SAYS_PREPAY_NOT_NEEDED :
1979 localeStrings.VENDOR_SAYS_PREPAY_NEEDED
1986 this.applySelectedLiAction = function(action) {
1990 case 'delete_selected':
1991 this._deleteLiList(self.getSelected());
1994 case 'create_order':
1995 this._loadPOSelect();
1996 acqLitPoCreateDialog.show();
1999 case 'save_picklist':
2000 acqLitSavePlDialog.show();
2003 case 'selector_ready':
2005 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
2006 acqLitChangeLiStateDialog.show();
2014 location.href = oilsBasePath + '/acq/po/history/' + this.isPO;
2021 case 'rollback_receive_po':
2022 this.rollbackPoReceive();
2025 case 'create_assets':
2026 this.createAssets();
2029 case 'export_attr_list':
2030 this.chooseExportAttr();
2033 case 'batch_apply_funds':
2034 this.applyBatchLiFunds();
2037 case 'add_brief_record':
2039 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
2041 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
2045 case "cancel_lineitems":
2046 this.maybeCancelLineitems();
2049 case "change_claim_policy":
2050 var li_list = this.getSelected();
2051 this.claimPolicyPicker.attr("value", null);
2052 liClaimPolicyDialog.show();
2053 liClaimPolicySave.onClick = function() {
2054 self.changeClaimPolicy(
2056 self.claimPolicyPicker.attr("value"),
2060 self.setClaimPolicyControl(li);
2061 self.reconsiderClaimControl(li);
2064 liClaimPolicyDialog.hide();
2072 this.changeClaimPolicy = function(li_list, value, callback) {
2074 function(li) { li.claim_policy(value); }
2076 fieldmapper.standardRequest(
2077 ["open-ils.acq", "open-ils.acq.lineitem.update"], {
2078 "params": [openils.User.authtoken, li_list],
2080 "oncomplete": function(r) {
2081 r = openils.Util.readResponse(r);
2082 if (callback) callback(r);
2088 this.createAssets = function() {
2089 if(!this.isPO) return;
2090 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
2091 this.show('acq-lit-progress-numbers');
2093 fieldmapper.standardRequest(
2094 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
2096 params: [this.authtoken, this.isPO],
2097 onresponse: function(r) {
2098 var resp = openils.Util.readResponse(r);
2099 self._updateProgressNumbers(resp, true);
2105 this.maybeCancelLineitems = function() {
2106 openils.Util.show("acq-lit-cancel-reason", "inline");
2107 if (!acqLitCancelLineitemsButton._prepared) {
2108 var widget = new openils.widget.AutoFieldWidget({
2109 "fmField": "cancel_reason",
2111 "parentNode": dojo.byId("acq-lit-cancel-reason-selector"),
2112 "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
2117 acqLitCancelLineitemsButton.onClick = function() {
2118 if (w.attr("value")) {
2119 if (confirm(localeStrings.LI_CANCEL_CONFIRM)) {
2120 self._cancelLineitems(w.attr("value"));
2122 openils.Util.hide("acq-lit-cancel-reason");
2125 acqLitCancelLineitemsButton._prepared = true;
2131 this._cancelLineitems = function(reason) {
2132 var id_list = this.getSelected().map(function(o) { return o.id(); });
2133 fieldmapper.standardRequest(
2134 ["open-ils.acq", "open-ils.acq.lineitem.cancel.batch"], {
2135 "params": [openils.User.authtoken, id_list, reason],
2137 "onresponse": function(r) {
2138 if (r = openils.Util.readResponse(r)) {
2140 for (var id in r.li) {
2141 self.liCache[id].state(r.li[id].state);
2142 self.liCache[id].cancel_reason(
2143 r.li[id].cancel_reason
2145 self.updateLiState(self.liCache[id]);
2148 if (r.lid && self.copyCache) {
2149 for (var id in r.lid) {
2150 if (self.copyCache[id]) {
2151 self.copyCache[id].cancel_reason(
2152 r.lid[id].cancel_reason
2154 self.updateLidState(self.copyCache[id]);
2164 this.chooseExportAttr = function() {
2165 if (!acqLitExportAttrSelector._li_setup) {
2167 acqLitExportAttrSelector.store = new dojo.data.ItemFileReadStore(
2169 "data": acqlimad.toStoreData(
2171 "acqlimad", {"code": li_exportable_attrs}
2176 acqLitExportAttrSelector.setValue();
2177 acqLitExportAttrButton.onClick = function(){self.exportAttrList();};
2178 acqLitExportAttrSelector._li_setup = true;
2180 openils.Util.show("acq-lit-export-attr-holder", "inline");
2183 this.exportAttrList = function() {
2184 var attr_def = acqLitExportAttrSelector.item;
2185 var li_list = this.getSelected();
2186 var value_list = li_list.map(
2188 return (new openils.acq.Lineitem({"lineitem": li})).findAttr(
2189 attr_def.code, "lineitem_marc_attr_definition"
2192 ).filter(function(attr) { return Boolean(attr); });
2194 if (value_list.length > 0) {
2195 if (value_list.length < li_list.length) {
2197 dojo.string.substitute(
2198 localeStrings.EXPORT_SHORT_LIST, [attr_def.description]
2205 openils.XUL.contentToFileSaveDialog(
2206 value_list.join("\n"),
2207 localeStrings.EXPORT_SAVE_DIALOG_TITLE
2213 alert(dojo.string.substitute(
2214 localeStrings.EXPORT_EMPTY_LIST, [attr_def.description]
2218 openils.Util.hide("acq-lit-export-attr-holder");
2221 this.printPO = function() {
2222 if(!this.isPO) return;
2223 progressDialog.show(true);
2224 fieldmapper.standardRequest(
2225 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
2227 params: [this.authtoken, this.isPO, 'html'],
2228 oncomplete: function(r) {
2229 progressDialog.hide();
2230 var evt = openils.Util.readResponse(r);
2231 if(evt && evt.template_output()) {
2232 openils.Util.printHtmlString(evt.template_output().data());
2240 this.receivePO = function() {
2241 if (!this.isPO) return;
2243 for (var id in this.liCache) {
2244 /* assumption: liCache reflects exactly the
2245 * set of LIs that belong to our PO */
2246 if (this.liCache[id].state() != "received" &&
2247 !this.checkLiAlerts(id)) return;
2250 this.show('acq-lit-progress-numbers');
2252 fieldmapper.standardRequest(
2253 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
2255 params: [this.authtoken, this.isPO],
2256 onresponse : function(r) {
2257 var resp = openils.Util.readResponse(r);
2258 self._updateProgressNumbers(resp, true);
2264 this.issueReceive = function(obj, rollback) {
2265 /* (For now) there shall be no marking LI or LIDs (un)received
2266 * except from the actual "view PO" interface. */
2267 if (!this.isPO) return;
2270 {"jub": "lineitem", "acqlid": "lineitem_detail"}[obj.classname];
2272 "open-ils.acq." + part + ".receive" + (rollback ? ".rollback" : "");
2274 progressDialog.show(true);
2275 fieldmapper.standardRequest(
2276 ["open-ils.acq", method], {
2278 "params": [this.authtoken, obj.id()],
2279 "onresponse": function(r) {
2280 if (r = openils.Util.readResponse(r)) {
2281 self.fetchClaimInfo(
2282 part == "lineitem" ? obj.id() : obj.lineitem(),
2284 function() { self.handleReceive(r); }
2286 progressDialog.hide();
2294 * Handles the responses from receive and rollback ML calls.
2296 this.handleReceive = function(resp) {
2299 for (var li_id in resp.li) {
2300 for (var key in resp.li[li_id])
2301 self.liCache[li_id][key](resp.li[li_id][key]);
2302 self.updateLiState(self.liCache[li_id]);
2306 if (typeof(self.poUpdateCallback) == "function")
2307 self.poUpdateCallback(resp.po);
2310 for (var lid_id in resp.lid) {
2311 for (var key in resp.lid[lid_id])
2312 self.copyCache[lid_id][key](resp.lid[lid_id][key]);
2313 self.updateLidState(self.copyCache[lid_id]);
2319 this.rollbackPoReceive = function() {
2320 if(!this.isPO) return;
2321 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
2322 this.show('acq-lit-progress-numbers');
2324 fieldmapper.standardRequest(
2325 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
2327 params: [this.authtoken, this.isPO],
2328 onresponse : function(r) {
2329 var resp = openils.Util.readResponse(r);
2330 self._updateProgressNumbers(resp, true);
2336 this._updateProgressNumbers = function(resp, reloadOnComplete) {
2338 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
2339 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
2340 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
2341 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
2342 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
2343 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
2344 if(resp.complete && reloadOnComplete)
2345 location.href = location.href;
2349 this._createPO = function(fields) {
2350 var wantall = (fields.create_from == "all");
2352 /* If we're a picklist or purchase order already and the user wants
2353 * all lineitems, we might have pages' worth of lineitems haven't all
2354 * been loaded yet, so getSelected() won't find them. The server,
2355 * however, should know about all our lineitems, so let's ask the
2356 * server for a complete list.
2361 true, function(list) {
2362 self._createPOFromLineitems(fields, list);
2363 }, /* id_list */ true
2366 this._createPOFromLineitems(fields, this.getSelected(false, null, true /* id_list */));
2370 this._createPOFromLineitems = function(fields, selected) {
2371 if (selected.length == 0) return;
2373 this.show("acq-lit-progress-numbers");
2374 var po = new fieldmapper.acqpo();
2375 po.provider(this.createPoProviderSelector.attr("value"));
2376 po.ordering_agency(this.createPoAgencySelector.attr("value"));
2377 po.prepayment_required(fields.prepayment_required[0] ? true : false);
2379 fieldmapper.standardRequest(
2380 ["open-ils.acq", "open-ils.acq.purchase_order.create"],
2383 openils.User.authtoken,
2385 lineitems : selected,
2386 create_assets : fields.create_assets[0],
2390 onresponse : function(r) {
2391 var resp = openils.Util.readResponse(r);
2392 self._updateProgressNumbers(resp);
2393 if (resp.complete) {
2394 location.href = oilsBasePath + "/acq/po/view/" +
2395 resp.purchase_order.id();
2403 this.batchFundWidget = null;
2405 this.applyBatchLiFunds = function() {
2407 var liIds = this.getSelected().map(function(li) { return li.id(); });
2408 if(liIds.length == 0) return; // warn?
2411 batchFundUpdateDialog.show();
2413 if(!this.batchFundWidget) {
2414 this.batchFundWidget = new openils.widget.AutoFieldWidget({
2416 selfReference : true,
2417 labelFormat : fundLabelFormat,
2418 searchFormat : fundSearchFormat,
2419 searchFilter : {"active": "t"},
2420 parentNode : dojo.byId('acq-lit-batch-fund-selector'),
2421 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
2422 dijitArgs : { "required": true, "labelType": "html" },
2425 this.batchFundWidget.build();
2428 dojo.connect(batchFundUpdateCancel, 'onClick', function() { batchFundUpdateDialog.hide(); });
2429 dojo.connect(batchFundUpdateSubmit, 'onClick',
2432 // TODO: call .dry_run first to test thresholds
2433 fieldmapper.standardRequest(
2434 ['open-ils.acq', 'open-ils.acq.lineitem.fund.update.batch'],
2437 openils.User.authtoken,
2439 self.batchFundWidget.widget.attr('value')
2441 oncomplete : function(r) {
2442 var resp = openils.Util.readResponse(r);
2444 location.href = location.href;
2453 this._deleteLiList = function(list, idx) {
2454 if(idx == null) idx = 0;
2455 if(idx >= list.length) return;
2460 if (this.isPO && (li.state() == "on-order" || li.state() == "received")) {
2461 /* It makes little sense to delete a lineitem from a PO that has
2462 * already been marked 'on-order'. Especially if EDI is in use,
2463 * such a purchase order will probably have already been shipped
2464 * off to a vendor, and mucking with it at this point could leave
2465 * your data in a bad state that doesn't jive with reality.
2467 * I could see making this restriction even firmer.
2469 * I could also see adjusting the li state comparisons, extending
2470 * the comparison to the PO's state, and/or providing functions
2471 * that house the logic for comparing states in a single location.
2473 * Yes, this will be really annoying if you have selected a lot
2474 * of lineitems to cancel that have been ordered. You'll get a
2475 * confirm dialog for each one.
2478 if (!confirm(localeStrings.DEL_LI_FROM_PO)) {
2479 self._deleteLiList(list, ++idx); /* move on to next in list */
2484 fieldmapper.standardRequest(
2486 this.isPO ? 'open-ils.acq.purchase_order.lineitem.delete' : 'open-ils.acq.picklist.lineitem.delete'],
2488 params: [openils.User.authtoken, liId],
2489 oncomplete: function(r) {
2490 self.removeLineitem(liId);
2491 self._deleteLiList(list, ++idx);
2497 this.editOrderMarc = function(li) {
2499 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
2500 to true in about:config */
2502 if(!openils.XUL.enableXPConnect()) return;
2504 if(openils.XUL.isXUL()) {
2505 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
2507 win = window.open('/xul/server/cat/marcedit.xul');
2511 record : {marc : li.marc(), "rtype": "bre"},
2513 label: 'Save Record', // XXX I18N
2514 func: function(xmlString) {
2516 fieldmapper.standardRequest(
2517 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
2519 params: [openils.User.authtoken, li],
2520 oncomplete: function(r) {
2521 openils.Util.readResponse(r);
2523 self.drawInfo(li.id())
2529 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
2530 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
2534 this._savePl = function(values) {
2536 (values.which == 'all'),
2537 function(list) { self._savePlFromLineitems(values, list); }
2541 this._savePlFromLineitems = function(values, selected) {
2542 openils.Util.show("acq-lit-generic-progress");
2544 if(values.new_name) {
2545 openils.acq.Picklist.create(
2546 {name: values.new_name},
2552 oilsBasePath + "/acq/picklist/view/" + id;
2557 } else if(values.existing_pl) {
2558 // update lineitems to use an existing picklist
2560 values.existing_pl, selected, 0,
2563 oilsBasePath + "/acq/picklist/view/" +
2570 this._updateLiState = function(values, state) {
2571 progressDialog.show(true);
2573 (values.which == 'all'),
2575 self._updateLiStateFromLineitems(values, state, list);
2580 this._updateLiStateFromLineitems = function(values, state, selected) {
2581 if(!selected.length) return;
2582 dojo.forEach(selected, function(li) {li.state(state);});
2583 self._updateLiList(null, selected, 0,
2584 // TODO consider inline updates for efficiency
2585 function() { location.href = location.href }
2589 this._updateLiList = function(pl, list, idx, oncomplete) {
2590 if(idx >= list.length) return oncomplete();
2592 if(pl != null) li.picklist(pl);
2593 litGenericProgress.update({maximum: list.length, progress: idx});
2594 new openils.acq.Lineitem({lineitem:li}).update(
2596 self._updateLiList(pl, list, ++idx, oncomplete);
2601 this._loadPOSelect = function() {
2602 if (!this.createPoProviderSelector) {
2603 var widget = new openils.widget.AutoFieldWidget({
2604 "fmField": "provider",
2606 "searchFilter": {"active": "t"},
2607 "parentNode": dojo.byId("acq-lit-po-provider"),
2609 "onChange": function() {
2611 self._updateCreatePoPrepayCheckbox(
2612 this.item.prepayment_required()
2618 widget.build(function(w) { self.createPoProviderSelector = w; });
2621 if (!this.createPoAgencySelector) {
2622 var widget = new openils.widget.AutoFieldWidget({
2623 "fmField": "ordering_agency",
2625 "parentNode": dojo.byId("acq-lit-po-agency"),
2626 "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
2628 widget.build(function(w) { self.createPoAgencySelector = w; });
2632 this.showRealCopyEditUI = function(li) {
2637 this._fetchLineitem(li.id(),
2639 li = self.liCache[li.id()] = fullLi;
2643 id : li.lineitem_details().map(
2644 function(item) { return item.eg_copy_id() }
2648 oncomplete : function(r) {
2650 var r_list = openils.Util.readResponse( r );
2651 for (var i = 0; i < r_list.length; i++) {
2652 var copy = r_list[i];
2653 var volId = copy.call_number();
2654 var volume = self.volCache[volId];
2656 volume = self.volCache[volId] = self.pcrud.retrieve('acn', volId);
2658 copy.call_number(volume);
2659 copyList.push(copy);
2662 xulG.volume_item_creator( { 'existing_copies' : copyList } );
2665 alert('error in oncomplete: ' + E);
2674 this.drawBibFinder = function(li) {
2677 var liWrapper = new openils.acq.Lineitem({lineitem:li});
2680 ['isbn', 'upc', 'issn', 'title', 'author'],
2682 var val = liWrapper.findAttr(field, 'lineitem_marc_attr_definition');
2684 if(field == 'title' || field == 'author') {
2685 query += field +':' + val + ' ';
2687 query += 'identifier|' + field + ':' + val + ' ';
2694 oilsBasePath + '/acq/lineitem/findbib?query=' + escape(query),
2695 '', 'resizable,scrollbars=1');
2697 win.window.recordFound = function(bibId) {
2700 var attrs = li.attributes();
2701 li.attributes(null);
2702 li.eg_bib_id(bibId);
2704 fieldmapper.standardRequest(
2705 ["open-ils.acq", "open-ils.acq.lineitem.update"],
2707 "params": [openils.User.authtoken, li],
2709 "oncomplete": function(r) {
2710 if(openils.Util.readResponse(r)) {
2711 location.href = location.href;