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.ProgressBar');
8 dojo.require('openils.User');
9 dojo.require('openils.Util');
10 dojo.require('openils.acq.Lineitem');
11 dojo.require('openils.acq.PO');
12 dojo.require('openils.acq.Picklist');
13 dojo.require('openils.widget.AutoFieldWidget');
14 dojo.require('dojo.data.ItemFileReadStore');
15 dojo.require('openils.widget.ProgressDialog');
16 dojo.require('openils.PermaCrud');
17 dojo.require('openils.XUL');
19 dojo.requireLocalization('openils.acq', 'acq');
20 var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
21 const XUL_OPAC_WRAPPER = 'chrome://open_ils_staff_client/content/cat/opac.xul';
23 function nodeByName(name, context) {
24 return dojo.query('[name='+name+']', context)[0];
28 var liDetailBatchFields = ['fund', 'owning_lib', 'location', 'collection_code', 'circ_modifier', 'cn_label'];
29 var liDetailFields = liDetailBatchFields.concat(['barcode', 'note']);
31 function AcqLiTable() {
38 this.toggleState = false;
39 this.tbody = dojo.byId('acq-lit-tbody');
41 this.authtoken = openils.User.authtoken;
42 this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
43 this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
44 this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
45 this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
46 this.copyBatchWidgets = {};
47 this.liNotesTbody = dojo.byId('acq-lit-notes-tbody');
48 this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row'));
49 this.realCopiesTbody = dojo.byId('acq-lit-real-copies-tbody');
50 this.realCopiesRow = this.realCopiesTbody.removeChild(dojo.byId('acq-lit-real-copies-row'));
52 dojo.connect(acqLitLiActionsSelector, 'onChange',
54 self.applySelectedLiAction(this.attr('value'))
55 acqLitLiActionsSelector.attr('value', '_');
58 acqLitCreatePoSubmit.onClick = function() {
59 acqLitPoCreateDialog.hide();
60 self._createPO(acqLitPoCreateDialog.getValues());
63 acqLitSavePlButton.onClick = function() {
64 acqLitSavePlDialog.hide();
65 self._savePl(acqLitSavePlDialog.getValues());
68 acqLitCancelLiStateButton.onClick = function() {
69 acqLitChangeLiStateDialog.hide();
71 acqLitSaveLiStateButton.onClick = function() {
72 acqLitChangeLiStateDialog.hide();
73 self._updateLiState(acqLitChangeLiStateDialog.getValues(), acqLitChangeLiStateDialog.attr('state'));
77 //dojo.byId('acq-lit-notes-new-button').onclick = function(){acqLitCreateLiNoteDialog.show();}
79 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
80 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
81 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
82 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
83 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
85 this.reset = function() {
86 while(self.tbody.childNodes[0])
87 self.tbody.removeChild(self.tbody.childNodes[0]);
91 this.setNext = function(handler) {
92 var link = dojo.byId('acq-lit-next');
94 dojo.style(link, 'visibility', 'visible');
95 link.onclick = handler;
97 dojo.style(link, 'visibility', 'hidden');
101 this.setPrev = function(handler) {
102 var link = dojo.byId('acq-lit-prev');
104 dojo.style(link, 'visibility', 'visible');
105 link.onclick = handler;
107 dojo.style(link, 'visibility', 'hidden');
111 this.show = function(div) {
112 openils.Util.hide('acq-lit-table-div');
113 openils.Util.hide('acq-lit-info-div');
114 openils.Util.hide('acq-lit-li-details');
115 openils.Util.hide('acq-lit-notes-div');
116 openils.Util.hide('acq-lit-real-copies-div');
119 openils.Util.show('acq-lit-table-div');
122 openils.Util.show('acq-lit-info-div');
125 openils.Util.show('acq-lit-li-details');
128 openils.Util.show('acq-lit-real-copies-div');
131 openils.Util.show('acq-lit-notes-div');
135 openils.Util.show(div);
139 this.hide = function() {
143 this.toggleSelect = function() {
145 dojo.forEach(self.selectors, function(i){i.checked = false});
147 dojo.forEach(self.selectors, function(i){i.checked = true});
148 self.toggleState = !self.toggleState;
152 /** @param all If true, assume all are selected */
153 this.getSelected = function(all) {
155 dojo.forEach(self.selectors,
158 selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
164 this.setRowAttr = function(td, liWrapper, field, type) {
165 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
166 td.appendChild(document.createTextNode(val));
170 * Inserts a single lineitem into the growing table of lineitems
171 * @param {Object} li The lineitem object to insert
173 this.addLineitem = function(li, skip_final_placement) {
174 this.liCache[li.id()] = li;
176 // sort the lineitem notes on edit_time
177 if(!li.lineitem_notes()) li.lineitem_notes([]);
179 var liWrapper = new openils.acq.Lineitem({lineitem:li});
180 var row = self.rowTemplate.cloneNode(true);
181 row.setAttribute('li', li.id());
182 var tds = dojo.query('[attr]', row);
183 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
184 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
186 var isbn = liWrapper.findAttr('isbn', 'lineitem_marc_attr_definition');
188 // XXX media prefix for added content
189 dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
192 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
193 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
194 dojo.query('[name=notes_count]', row)[0].innerHTML = li.lineitem_notes().length;
195 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
197 // show which PO this lineitem is a member of
198 if(li.purchase_order() && !this.isPO) {
200 this.poCache[li.purchase_order()] =
201 this.poCache[li.purchase_order()] ||
202 fieldmapper.standardRequest(
203 ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
205 this.authtoken, li.purchase_order(), {
206 "flesh_price_summary": true,
207 "flesh_lineitem_count": true
210 if(po && !this.isMeta) {
211 openils.Util.show(nodeByName('po', row), 'inline');
212 var link = nodeByName('po_link', row);
213 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
214 link.innerHTML = 'PO: ' + po.name(); // TODO i18n
218 // show which picklist this lineitem is a member of
219 if(li.picklist() && (this.isPO || this.isMeta)) {
221 this.plCache[li.picklist()] =
222 this.plCache[li.picklist()] ||
223 fieldmapper.standardRequest(
224 ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
225 {params: [this.authtoken, li.picklist()]});
227 openils.Util.show(nodeByName('pl', row), 'inline');
228 var link = nodeByName('pl_link', row);
229 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
230 link.innerHTML = 'PL: '+pl.name(); // TODO i18n
234 var countNode = nodeByName('count', row);
235 var count = li.item_count() || 0;
236 if (typeof(this._copy_count_cb) == "function") {
237 this._copy_count_cb(li.id(), count);
239 countNode.innerHTML = count;
240 countNode.id = 'acq-lit-copy-count-label-' + li.id();
243 nodeByName('li_state', row).innerHTML = li.state(); // TODO i18n state labels
244 openils.Util.addCSSClass(row, 'oils-acq-li-state-' + li.state());
247 var priceInput = dojo.query('[name=price]', row)[0];
248 var priceData = liWrapper.getPrice();
249 priceInput.value = (priceData) ? priceData.price : '';
250 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
252 var recv_link = dojo.query('[name=receive_link]', row)[0];
254 if(li.state() == 'on-order') {
255 recv_link.onclick = function() {
257 openils.Util.hide(recv_link)
260 openils.Util.hide(recv_link);
263 // TODO we should allow editing before receipt, in which case the
264 // test should be "if 1 or more real (acp) copies exist
265 if(li.state() == 'received') {
266 var real_copies_link = dojo.query('[name=real_copies_link]', row)[0];
267 openils.Util.show(real_copies_link);
268 real_copies_link.onclick = function() {
269 self.showRealCopies(li);
273 if (!skip_final_placement) {
274 self.tbody.appendChild(row);
275 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
282 * Draws and shows the lineitem notes pane
284 this.drawLiNotes = function(li) {
288 li.lineitem_notes().sort(
290 if(a.edit_time() < b.edit_time()) return 1;
296 while(this.liNotesTbody.childNodes[0])
297 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
300 acqLitCreateLiNoteSubmit.onClick = function() {
301 var value = acqLitCreateNoteText.attr('value');
303 var note = new fieldmapper.acqlin();
306 note.lineitem(li.id());
307 self.updateLiNotes(li, note);
310 dojo.byId('acq-lit-notes-save-button').onclick = function() {
311 self.updateLiNotes(li);
314 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
318 * Draws a single lineitem note in the notes pane
320 this.addLiNote = function(li, note) {
321 if(note.isdeleted()) return;
323 var row = self.liNotesRow.cloneNode(true);
324 dojo.query('[name=value]', row)[0].innerHTML = note.value();
326 dojo.query('[name=delete]', row)[0].onclick = function() {
327 note.isdeleted(true);
328 self.liNotesTbody.removeChild(row);
331 if(note.edit_time()) {
332 dojo.query('[name=edit_time]', row)[0].innerHTML =
333 dojo.date.locale.format(
334 dojo.date.stamp.fromISOString(note.edit_time()),
335 {formatLength:'short'});
338 self.liNotesTbody.appendChild(row);
342 * Updates any new/changed/deleted notes on the server
344 this.updateLiNotes = function(li, newNote) {
350 notes = li.lineitem_notes().filter(
352 if(note.ischanged() || note.isnew() || note.isdeleted())
358 if(notes.length == 0) return;
359 progressDialog.show();
361 fieldmapper.standardRequest(
362 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
364 params : [this.authtoken, notes],
365 onresponse : function(r) {
366 var resp = openils.Util.readResponse(r);
371 // remove the old changed notes
373 dojo.forEach(li.lineitem_notes(),
375 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
379 li.lineitem_notes(list);
382 progressDialog.hide();
383 self.drawLiNotes(li);
387 progressDialog.update(resp);
388 var newnote = resp.note;
390 if(!newnote.isdeleted()) {
391 newnote.isnew(false);
392 newnote.ischanged(false);
393 li.lineitem_notes().push(newnote);
400 this.updateLiPrice = function(input, li) {
402 var price = input.value;
403 var liWrapper = new openils.acq.Lineitem({lineitem:li});
404 var oldPrice = liWrapper.getPrice() || null;
406 if(oldPrice) oldPrice = oldPrice.price;
407 if(price == oldPrice) return;
409 fieldmapper.standardRequest(
410 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
412 params : [this.authtoken, li.id(), price],
413 oncomplete : function(r) {
414 openils.Util.readResponse(r);
420 this.removeLineitem = function(liId) {
421 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
422 delete this.liCache[liId];
423 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
426 this.drawInfo = function(liId) {
428 openils.acq.Lineitem.fetchAttrDefs(
430 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
435 this._fetchLineitem = function(liId, handler) {
437 var li = this.liCache[liId];
438 if(li && li.marc() && li.lineitem_details())
441 fieldmapper.standardRequest(
442 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
445 params: [self.authtoken, liId, {
447 flesh_li_details: true,
448 flesh_fund_debit: true }],
450 oncomplete: function(r) {
451 var li = openils.Util.readResponse(r);
458 this._drawInfo = function(li) {
460 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
463 openils.Util.hide('acq-lit-marc-order-record-label');
464 openils.Util.hide(acqLitEditOrderMarc.domNode);
465 openils.Util.show('acq-lit-marc-real-record-label');
467 openils.Util.show('acq-lit-marc-order-record-label');
468 openils.Util.show(acqLitEditOrderMarc.domNode);
469 openils.Util.hide('acq-lit-marc-real-record-label');
472 this.drawMarcHTML(li);
473 this.infoTbody = dojo.byId('acq-lit-info-tbody');
476 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
477 while(this.infoTbody.childNodes[0])
478 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
480 for(var i = 0; i < li.attributes().length; i++) {
481 var attr = li.attributes()[i];
482 var row = this.infoRow.cloneNode(true);
484 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
485 var name = openils.acq.Lineitem.attrDefs[type].filter(
487 return (a.code() == attr.attr_name());
489 ).pop().description();
491 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
492 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
493 this.infoTbody.appendChild(row);
497 openils.Util.show('acq-lit-info-cat-link');
498 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
500 if(openils.XUL.isXUL()) {
502 var makeRecTab = function() {
505 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
508 show_nav_buttons : true,
509 show_print_button : true,
510 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
514 link.setAttribute('href', 'javascript:void(0);');
515 link.onclick = makeRecTab;
518 var href = link.getAttribute('href');
520 link.setAttribute('href', href + li.eg_bib_id());
523 openils.Util.hide('acq-lit-info-cat-link');
527 this.drawMarcHTML = function(li) {
528 var params = [null, true, li.marc()];
530 params = [li.eg_bib_id(), true];
532 fieldmapper.standardRequest(
533 ['open-ils.search', 'open-ils.search.biblio.record.html'],
536 oncomplete: function(r) {
537 dojo.byId('acq-lit-marc-div').innerHTML =
538 openils.Util.readResponse(r);
544 this.drawCopies = function(liId) {
548 this.copyWidgetCache = {};
551 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
552 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
553 acqLitCopyCountInput.attr('value', '0');
555 while(this.copyTbody.childNodes[0])
556 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
558 this._drawBatchCopyWidgets();
560 this._fetchDistribFormulas(
562 openils.acq.Lineitem.fetchAttrDefs(
564 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
572 * Insert a new row into the distribution formula selection form
574 this._addDistribFormulaRow = function() {
577 if(!self.distribFormulaStore) {
578 // no formulas, hide the form
579 openils.Util.hide('acq-lit-distrib-formula-tbody');
583 if(!this.distribFormulaTemplate)
584 this.distribFormulaTemplate =
585 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
587 var row = dojo.byId('acq-lit-distrib-formula-tbody').appendChild(this.distribFormulaTemplate.cloneNode(true));
589 var selector = new dijit.form.FilteringSelect(
590 {store : self.distribFormulaStore},
591 nodeByName('selector', row)
594 var apply = new dijit.form.Button(
595 {label : 'Apply'}, // TODO i18n
596 nodeByName('set_button', row)
599 var release = new dijit.form.Button(
600 {label : 'Release', disabled: true}, // TODO i18n
601 nodeByName('rel_button', row)
604 dojo.connect(apply, 'onClick',
606 var form_id = selector.attr('value');
608 apply.attr('disabled', true);
609 release.attr('disabled', false);
610 self._applyDistribFormula(form_id);
614 dojo.connect(release, 'onClick',
616 apply.attr('disabled', false);
617 release.attr('disabled', true);
623 * Applies a distrib formula to the current set of copies
625 this._applyDistribFormula = function(formula) {
628 formula = this.distribForms.filter(
630 return form.id() == formula;
634 var copyRows = dojo.query('tr', self.copyTbody);
637 for(var rowIndex = 0; rowIndex < copyRows.length; rowIndex++) {
639 var row = copyRows[rowIndex];
640 var copy_id = row.getAttribute('copy_id');
641 var copyWidgets = this.copyWidgetCache[copy_id];
645 // find the correct entry for the current row
646 dojo.forEach(formula.entries(),
649 entryIndex += e.item_count();
650 if(entryIndex > rowIndex)
658 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
659 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
662 ['owning_lib', 'location'],
666 copyWidgets[field].attr('value', (entry[field]()));
674 this.dfaCache.push(formula.id());
678 this._fetchDistribFormulas = function(onload) {
679 if(this.distribForms) {
683 fieldmapper.standardRequest(
684 ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve.atomic'],
686 params: [openils.User.authtoken],
687 oncomplete: function(r) {
688 self.distribForms = openils.Util.readResponse(r);
689 if(!self.distribForms || self.distribForms.length == 0) {
690 self.distribForms = [];
693 self.distribFormulaStore =
694 new dojo.data.ItemFileReadStore(
695 {data:acqdf.toStoreData(self.distribForms)});
696 self._addDistribFormulaRow();
704 this._drawBatchCopyWidgets = function() {
705 var row = this.copyBatchRow;
706 dojo.forEach(liDetailBatchFields,
708 if(self.copyBatchRowDrawn) {
709 self.copyBatchWidgets[field].attr('value', null);
711 var widget = new openils.widget.AutoFieldWidget({
714 parentNode : dojo.query('[name='+field+']', row)[0],
715 orgLimitPerms : ['CREATE_PICKLIST'],
716 dijitArgs : {required:false},
721 self.copyBatchWidgets[field] = w;
727 this.copyBatchRowDrawn = true;
730 this.batchCopyUpdate = function() {
732 for(var k in this.copyWidgetCache) {
733 var cache = this.copyWidgetCache[k];
734 dojo.forEach(liDetailBatchFields, function(f) {
735 var newval = self.copyBatchWidgets[f].attr('value');
736 if(newval) cache[f].attr('value', newval);
741 this._drawCopies = function(li) {
744 // this button sets the total number of copies for a given lineitem
745 acqLitAddCopyCount.onClick = function() {
746 var count = acqLitCopyCountInput.attr('value');
749 while(self.copyCount() < count)
752 // delete rows if necessary
753 var diff = self.copyCount() - count;
755 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
756 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
757 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
759 acqLitCopyCountInput.attr('value', self.copyCount()+'');
765 if(li.lineitem_details().length > 0) {
766 dojo.forEach(li.lineitem_details(),
768 self.addCopy(li, copy);
776 this.copyCount = function() {
778 for(var id in this.copyCache) {
779 if(!this.copyCache[id].isdeleted())
785 this.virtCopyId = -1;
786 this.addCopy = function(li, copy) {
787 var row = this.copyRow.cloneNode(true);
788 this.copyTbody.appendChild(row);
792 copy = new fieldmapper.acqlid();
794 copy.id(this.virtCopyId--);
795 copy.lineitem(li.id());
798 this.copyCache[copy.id()] = copy;
799 row.setAttribute('copy_id', copy.id());
800 self.copyWidgetCache[copy.id()] = {};
802 acqLitCopyCountInput.attr('value', self.copyCount()+'');
804 dojo.forEach(liDetailFields,
806 var widget = new openils.widget.AutoFieldWidget({
810 parentNode : dojo.query('[name='+field+']', row)[0],
811 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
812 readOnly : Boolean(copy.eg_copy_id())
815 // make sure we capture the value from any async widgets
817 copy[field](ww.getFormattedValue())
818 self.copyWidgetCache[copy.id()][field] = w;
821 dojo.connect(widget.widget, 'onChange',
823 if(copy.isnew() || val != copy[field]()) {
824 // prevent setting ischanged() automatically on widget load for existing copies
825 copy[field](widget.getFormattedValue())
826 copy.ischanged(true);
833 var recv_link = dojo.query('[name=receive]', row)[0];
834 if(copy.recv_time()) {
835 openils.Util.hide(recv_link);
837 recv_link.onclick = function() {
838 self.receiveLid(copy);
839 openils.Util.hide(recv_link);
844 openils.Util.hide(dojo.query('[name=delete]', row)[0].parentNode);
846 dojo.query('[name=delete]', row)[0].onclick =
847 function() { self.deleteCopy(row) };
851 this.deleteCopy = function(row) {
852 var copy = this.copyCache[row.getAttribute('copy_id')];
853 copy.isdeleted(true);
855 delete this.copyCache[copy.id()];
856 this.copyTbody.removeChild(row);
859 this.saveCopyChanges = function(liId) {
864 openils.Util.show('acq-lit-update-copies-progress');
867 for(var id in this.copyCache) {
868 var c = this.copyCache[id];
869 if(!c.isdeleted()) total++;
870 if(c.isnew() || c.ischanged() || c.isdeleted()) {
871 if(c.id() < 0) c.id(null);
876 if (typeof(this._copy_count_cb) == "function") {
877 this._copy_count_cb(liId, total);
880 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
882 if(copies.length == 0)
885 fieldmapper.standardRequest(
886 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
888 params: [openils.User.authtoken, copies],
889 onresponse: function(r) {
890 var res = openils.Util.readResponse(r);
891 litUpdateCopiesProgress.update(res);
893 oncomplete: function() {
894 openils.Util.hide('acq-lit-update-copies-progress');
895 self.drawCopies(liId);
900 if (this.dfaCache.length > 0) {
901 var oldlength = this.dfaCache.length;
902 fieldmapper.standardRequest(
904 "open-ils.acq.distribution_formula.record_application"],
907 "params": [openils.User.authtoken, this.dfaCache, liId],
908 "onresponse": function(r) {
909 var res = openils.Util.readResponse(r);
910 if (res && res.length != oldlength)
911 alert(localeStrings.DFA_NOT_ALL);
919 this.applySelectedLiAction = function(action) {
923 case 'delete_selected':
924 this._deleteLiList(self.getSelected());
929 if(!this.createPoProviderSelector) {
930 var widget = new openils.widget.AutoFieldWidget({
931 fmField : 'provider',
933 parentNode : dojo.byId('acq-lit-po-provider'),
936 function(w) { self.createPoProviderSelector = w; }
940 if(!this.createPoAgencySelector) {
941 var widget = new openils.widget.AutoFieldWidget({
942 fmField : 'ordering_agency',
944 parentNode : dojo.byId('acq-lit-po-agency'),
945 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
948 function(w) { self.createPoAgencySelector = w; }
953 acqLitPoCreateDialog.show();
956 case 'save_picklist':
957 this._loadPLSelect();
958 acqLitSavePlDialog.show();
961 case 'selector_ready':
963 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
964 acqLitChangeLiStateDialog.show();
975 case 'rollback_receive_po':
976 this.rollbackPoReceive();
979 case 'create_assets':
983 case 'add_brief_record':
985 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
987 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
991 this.createAssets = function() {
992 if(!this.isPO) return;
993 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
994 this.show('acq-lit-progress-numbers');
996 fieldmapper.standardRequest(
997 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
999 params: [this.authtoken, this.isPO],
1000 onresponse: function(r) {
1001 var resp = openils.Util.readResponse(r);
1002 self._updateProgressNumbers(resp, true);
1008 this.printPO = function() {
1009 if(!this.isPO) return;
1010 progressDialog.show(true);
1011 fieldmapper.standardRequest(
1012 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
1014 params: [this.authtoken, this.isPO, 'html'],
1015 oncomplete: function(r) {
1016 progressDialog.hide();
1017 var evt = openils.Util.readResponse(r);
1018 if(evt && evt.template_output()) {
1019 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
1020 win.document.body.innerHTML = evt.template_output().data();
1028 this.receivePO = function() {
1029 if(!this.isPO) return;
1030 this.show('acq-lit-progress-numbers');
1032 fieldmapper.standardRequest(
1033 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
1035 params: [this.authtoken, this.isPO],
1036 onresponse : function(r) {
1037 var resp = openils.Util.readResponse(r);
1038 self._updateProgressNumbers(resp, true);
1044 this.receiveLi = function(li) {
1045 if(!this.isPO) return;
1046 progressDialog.show(true);
1047 fieldmapper.standardRequest(
1048 ['open-ils.acq', 'open-ils.acq.lineitem.receive'],
1050 params: [this.authtoken, li.id()],
1051 onresponse : function(r) {
1052 var resp = openils.Util.readResponse(r);
1053 progressDialog.hide();
1059 this.receiveLid = function(li) {
1060 if(!this.isPO) return;
1061 progressDialog.show(true);
1062 fieldmapper.standardRequest(
1063 ['open-ils.acq', 'open-ils.acq.lineitem_detail.receive'],
1065 params: [this.authtoken, li.id()],
1066 onresponse : function(r) {
1067 var resp = openils.Util.readResponse(r);
1068 progressDialog.hide();
1074 this.rollbackPoReceive = function() {
1075 if(!this.isPO) return;
1076 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
1077 this.show('acq-lit-progress-numbers');
1079 fieldmapper.standardRequest(
1080 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
1082 params: [this.authtoken, this.isPO],
1083 onresponse : function(r) {
1084 var resp = openils.Util.readResponse(r);
1085 self._updateProgressNumbers(resp, true);
1091 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1093 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1094 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1095 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1096 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1097 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1098 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1099 if(resp.complete && reloadOnComplete)
1100 location.href = location.href;
1104 this._createPO = function(fields) {
1105 this.show('acq-lit-progress-numbers');
1106 var po = new fieldmapper.acqpo();
1107 po.provider(this.createPoProviderSelector.attr('value'));
1108 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1110 var selected = this.getSelected( (fields.create_from == 'all') );
1111 if(selected.length == 0) return;
1113 var max = selected.length * 3;
1116 fieldmapper.standardRequest(
1117 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1120 openils.User.authtoken,
1123 lineitems : selected.map(function(li) { return li.id() }),
1124 create_assets : fields.create_assets[0],
1128 onresponse : function(r) {
1129 var resp = openils.Util.readResponse(r);
1130 self._updateProgressNumbers(resp);
1132 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1138 this._deleteLiList = function(list, idx) {
1139 if(idx == null) idx = 0;
1140 if(idx >= list.length) return;
1141 var liId = list[idx].id();
1142 fieldmapper.standardRequest(
1143 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1145 params: [openils.User.authtoken, liId],
1146 oncomplete: function(r) {
1147 self.removeLineitem(liId);
1148 self._deleteLiList(list, ++idx);
1154 this.editOrderMarc = function(li) {
1156 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1157 to true in about:config */
1159 if(!openils.XUL.enableXPConnect()) return;
1161 if(openils.XUL.isXUL()) {
1162 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1164 win = window.open('/xul/server/cat/marcedit.xul');
1168 record : {marc : li.marc()},
1170 label: 'Save Record', // XXX I18N
1171 func: function(xmlString) {
1173 fieldmapper.standardRequest(
1174 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1176 params: [openils.User.authtoken, li],
1177 oncomplete: function(r) {
1178 openils.Util.readResponse(r);
1180 self.drawInfo(li.id())
1189 this._savePl = function(values) {
1191 var selected = this.getSelected( (values.which == 'all') );
1192 openils.Util.show('acq-lit-generic-progress');
1194 if(values.new_name) {
1195 openils.acq.Picklist.create(
1196 {name: values.new_name},
1198 self._updateLiList(id, selected, 0,
1200 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1204 } else if(values.existing_pl) {
1205 // update lineitems to use an existing picklist
1206 self._updateLiList(values.existing_pl, selected, 0,
1208 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1213 this._updateLiState = function(values, state) {
1215 var selected = this.getSelected( (values.which == 'all') );
1216 if(!selected.length) return;
1217 dojo.forEach(selected, function(li) {li.state(state);});
1218 self._updateLiList(null, selected, 0,
1219 // TODO consider inline updates for efficiency
1220 function() { location.href = location.href }
1224 this._updateLiList = function(pl, list, idx, oncomplete) {
1225 if(idx >= list.length) return oncomplete();
1227 if(pl != null) li.picklist(pl);
1228 litGenericProgress.update({maximum: list.length, progress: idx});
1229 new openils.acq.Lineitem({lineitem:li}).update(
1231 self._updateLiList(pl, list, ++idx, oncomplete);
1236 this._loadPLSelect = function() {
1237 if(this._plSelectLoaded) return;
1239 function handleResponse(r) {
1240 plList.push(r.recv().content());
1242 var method = 'open-ils.acq.picklist.user.retrieve';
1243 fieldmapper.standardRequest(
1244 ['open-ils.acq', method],
1246 params: [this.authtoken],
1247 onresponse: handleResponse,
1248 oncomplete: function() {
1249 self._plSelectLoaded = true;
1250 acqLitAddExistingSelect.store =
1251 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1252 acqLitAddExistingSelect.setValue();
1258 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1259 this.showRealCopies = function(li) {
1260 while(this.realCopiesTbody.childNodes[0])
1261 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1262 this.show('real-copies');
1264 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1265 this.realCopyList = [];
1267 var tabIndex = 1000;
1270 acqLitSaveRealCopies.onClick = function() {
1271 self.saveRealCopies();
1274 this._fetchLineitem(li.id(),
1276 li = self.liCache[li.id()] = fullLi;
1280 id : li.lineitem_details().map(
1281 function(item) { return item.eg_copy_id() }
1286 onresponse : function(r) {
1287 var copy = openils.Util.readResponse(r);
1288 var volId = copy.call_number();
1289 var volume = self.volCache[volId];
1291 volume = self.volCache[volId] = pcrud.retrieve('acn', volId);
1293 self.addRealCopy(volume, copy, tabIndex++);
1301 this.addRealCopy = function(volume, copy, tabIndex) {
1302 var row = this.realCopiesRow.cloneNode(true);
1303 this.realCopyList.push(copy);
1307 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1310 var isvol = (field == 'owning_lib' || field == 'label');
1311 var widget = new openils.widget.AutoFieldWidget({
1313 fmObject : isvol ? volume : copy,
1314 parentNode : nodeByName(field, row),
1315 readOnly : (field != 'barcode'),
1318 var widgetDrawn = null;
1320 if(field == 'barcode') {
1322 widgetDrawn = function(w, ww) {
1323 var node = w.domNode;
1324 node.setAttribute('tabindex', ''+tabIndex);
1326 // on enter, select the next barcode input
1327 dojo.connect(w, 'onKeyDown',
1329 if(e.keyCode == dojo.keys.ENTER) {
1330 var ti = node.getAttribute('tabindex');
1331 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1332 if(nextNode) nextNode.select();
1337 dojo.connect(w, 'onChange',
1339 if(!val || val == copy.barcode()) return;
1340 copy.ischanged(true);
1346 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1351 widget.build(widgetDrawn);
1355 this.realCopiesTbody.appendChild(row);
1356 if(selectNode) selectNode.select();
1359 this.saveRealCopies = function() {
1360 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1361 progressDialog.show(true);
1362 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1363 pcrud.update(list, {oncomplete: function() {
1364 progressDialog.hide();