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() {
37 this.toggleState = false;
38 this.tbody = dojo.byId('acq-lit-tbody');
40 this.authtoken = openils.User.authtoken;
41 this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
42 this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
43 this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
44 this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
45 this.copyBatchWidgets = {};
46 this.liNotesTbody = dojo.byId('acq-lit-notes-tbody');
47 this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row'));
48 this.realCopiesTbody = dojo.byId('acq-lit-real-copies-tbody');
49 this.realCopiesRow = this.realCopiesTbody.removeChild(dojo.byId('acq-lit-real-copies-row'));
51 dojo.connect(acqLitLiActionsSelector, 'onChange',
53 self.applySelectedLiAction(this.attr('value'))
54 acqLitLiActionsSelector.attr('value', '_');
57 acqLitCreatePoSubmit.onClick = function() {
58 acqLitPoCreateDialog.hide();
59 self._createPO(acqLitPoCreateDialog.getValues());
62 acqLitSavePlButton.onClick = function() {
63 acqLitSavePlDialog.hide();
64 self._savePl(acqLitSavePlDialog.getValues());
67 acqLitCancelLiStateButton.onClick = function() {
68 acqLitChangeLiStateDialog.hide();
70 acqLitSaveLiStateButton.onClick = function() {
71 acqLitChangeLiStateDialog.hide();
72 self._updateLiState(acqLitChangeLiStateDialog.getValues(), acqLitChangeLiStateDialog.attr('state'));
76 //dojo.byId('acq-lit-notes-new-button').onclick = function(){acqLitCreateLiNoteDialog.show();}
78 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
79 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
80 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
81 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
82 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
84 this.reset = function() {
85 while(self.tbody.childNodes[0])
86 self.tbody.removeChild(self.tbody.childNodes[0]);
90 this.setNext = function(handler) {
91 var link = dojo.byId('acq-lit-next');
93 dojo.style(link, 'visibility', 'visible');
94 link.onclick = handler;
96 dojo.style(link, 'visibility', 'hidden');
100 this.setPrev = function(handler) {
101 var link = dojo.byId('acq-lit-prev');
103 dojo.style(link, 'visibility', 'visible');
104 link.onclick = handler;
106 dojo.style(link, 'visibility', 'hidden');
110 this.show = function(div) {
111 openils.Util.hide('acq-lit-table-div');
112 openils.Util.hide('acq-lit-info-div');
113 openils.Util.hide('acq-lit-li-details');
114 openils.Util.hide('acq-lit-notes-div');
115 openils.Util.hide('acq-lit-real-copies-div');
118 openils.Util.show('acq-lit-table-div');
121 openils.Util.show('acq-lit-info-div');
124 openils.Util.show('acq-lit-li-details');
127 openils.Util.show('acq-lit-real-copies-div');
130 openils.Util.show('acq-lit-notes-div');
134 openils.Util.show(div);
138 this.hide = function() {
142 this.toggleSelect = function() {
144 dojo.forEach(self.selectors, function(i){i.checked = false});
146 dojo.forEach(self.selectors, function(i){i.checked = true});
147 self.toggleState = !self.toggleState;
151 /** @param all If true, assume all are selected */
152 this.getSelected = function(all) {
154 dojo.forEach(self.selectors,
157 selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
163 this.setRowAttr = function(td, liWrapper, field, type) {
164 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
165 td.appendChild(document.createTextNode(val));
169 * Inserts a single lineitem into the growing table of lineitems
170 * @param {Object} li The lineitem object to insert
172 this.addLineitem = function(li, skip_final_placement) {
173 this.liCache[li.id()] = li;
175 // sort the lineitem notes on edit_time
176 if(!li.lineitem_notes()) li.lineitem_notes([]);
178 var liWrapper = new openils.acq.Lineitem({lineitem:li});
179 var row = self.rowTemplate.cloneNode(true);
180 row.setAttribute('li', li.id());
181 var tds = dojo.query('[attr]', row);
182 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
183 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
185 var isbn = liWrapper.findAttr('isbn', 'lineitem_marc_attr_definition');
187 // XXX media prefix for added content
188 dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
191 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
192 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
193 dojo.query('[name=notes_count]', row)[0].innerHTML = li.lineitem_notes().length;
194 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
196 // show which PO this lineitem is a member of
197 if(li.purchase_order() && !this.isPO) {
199 this.poCache[li.purchase_order()] =
200 this.poCache[li.purchase_order()] ||
201 fieldmapper.standardRequest(
202 ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
204 this.authtoken, li.purchase_order(), {
205 "flesh_price_summary": true,
206 "flesh_lineitem_count": true
209 if(po && !this.isMeta) {
210 openils.Util.show(nodeByName('po', row), 'inline');
211 var link = nodeByName('po_link', row);
212 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
213 link.innerHTML = 'PO: ' + po.name(); // TODO i18n
217 // show which picklist this lineitem is a member of
218 if(li.picklist() && (this.isPO || this.isMeta)) {
220 this.plCache[li.picklist()] =
221 this.plCache[li.picklist()] ||
222 fieldmapper.standardRequest(
223 ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
224 {params: [this.authtoken, li.picklist()]});
226 openils.Util.show(nodeByName('pl', row), 'inline');
227 var link = nodeByName('pl_link', row);
228 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
229 link.innerHTML = 'PL: '+pl.name(); // TODO i18n
233 var countNode = nodeByName('count', row);
234 var count = li.item_count() || 0;
235 if (typeof(this._copy_count_cb) == "function") {
236 this._copy_count_cb(li.id(), count);
238 countNode.innerHTML = count;
239 countNode.id = 'acq-lit-copy-count-label-' + li.id();
242 nodeByName('li_state', row).innerHTML = li.state(); // TODO i18n state labels
243 openils.Util.addCSSClass(row, 'oils-acq-li-state-' + li.state());
246 var priceInput = dojo.query('[name=price]', row)[0];
247 var priceData = liWrapper.getPrice();
248 priceInput.value = (priceData) ? priceData.price : '';
249 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
251 var recv_link = dojo.query('[name=receive_link]', row)[0];
253 if(li.state() == 'on-order') {
254 recv_link.onclick = function() {
256 openils.Util.hide(recv_link)
259 openils.Util.hide(recv_link);
262 // TODO we should allow editing before receipt, in which case the
263 // test should be "if 1 or more real (acp) copies exist
264 if(li.state() == 'received') {
265 var real_copies_link = dojo.query('[name=real_copies_link]', row)[0];
266 openils.Util.show(real_copies_link);
267 real_copies_link.onclick = function() {
268 self.showRealCopies(li);
272 if (!skip_final_placement) {
273 self.tbody.appendChild(row);
274 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
281 * Draws and shows the lineitem notes pane
283 this.drawLiNotes = function(li) {
287 li.lineitem_notes().sort(
289 if(a.edit_time() < b.edit_time()) return 1;
295 while(this.liNotesTbody.childNodes[0])
296 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
299 acqLitCreateLiNoteSubmit.onClick = function() {
300 var value = acqLitCreateNoteText.attr('value');
302 var note = new fieldmapper.acqlin();
305 note.lineitem(li.id());
306 self.updateLiNotes(li, note);
309 dojo.byId('acq-lit-notes-save-button').onclick = function() {
310 self.updateLiNotes(li);
313 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
317 * Draws a single lineitem note in the notes pane
319 this.addLiNote = function(li, note) {
320 if(note.isdeleted()) return;
322 var row = self.liNotesRow.cloneNode(true);
323 dojo.query('[name=value]', row)[0].innerHTML = note.value();
325 dojo.query('[name=delete]', row)[0].onclick = function() {
326 note.isdeleted(true);
327 self.liNotesTbody.removeChild(row);
330 if(note.edit_time()) {
331 dojo.query('[name=edit_time]', row)[0].innerHTML =
332 dojo.date.locale.format(
333 dojo.date.stamp.fromISOString(note.edit_time()),
334 {formatLength:'short'});
337 self.liNotesTbody.appendChild(row);
341 * Updates any new/changed/deleted notes on the server
343 this.updateLiNotes = function(li, newNote) {
349 notes = li.lineitem_notes().filter(
351 if(note.ischanged() || note.isnew() || note.isdeleted())
357 if(notes.length == 0) return;
358 progressDialog.show();
360 fieldmapper.standardRequest(
361 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
363 params : [this.authtoken, notes],
364 onresponse : function(r) {
365 var resp = openils.Util.readResponse(r);
370 // remove the old changed notes
372 dojo.forEach(li.lineitem_notes(),
374 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
378 li.lineitem_notes(list);
381 progressDialog.hide();
382 self.drawLiNotes(li);
386 progressDialog.update(resp);
387 var newnote = resp.note;
389 if(!newnote.isdeleted()) {
390 newnote.isnew(false);
391 newnote.ischanged(false);
392 li.lineitem_notes().push(newnote);
399 this.updateLiPrice = function(input, li) {
401 var price = input.value;
402 var liWrapper = new openils.acq.Lineitem({lineitem:li});
403 var oldPrice = liWrapper.getPrice() || null;
405 if(oldPrice) oldPrice = oldPrice.price;
406 if(price == oldPrice) return;
408 fieldmapper.standardRequest(
409 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
411 params : [this.authtoken, li.id(), price],
412 oncomplete : function(r) {
413 openils.Util.readResponse(r);
419 this.removeLineitem = function(liId) {
420 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
421 delete this.liCache[liId];
422 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
425 this.drawInfo = function(liId) {
427 openils.acq.Lineitem.fetchAttrDefs(
429 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
434 this._fetchLineitem = function(liId, handler) {
436 var li = this.liCache[liId];
437 if(li && li.marc() && li.lineitem_details())
440 fieldmapper.standardRequest(
441 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
444 params: [self.authtoken, liId, {
446 flesh_li_details: true,
447 flesh_fund_debit: true }],
449 oncomplete: function(r) {
450 var li = openils.Util.readResponse(r);
457 this._drawInfo = function(li) {
459 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
462 openils.Util.hide('acq-lit-marc-order-record-label');
463 openils.Util.hide(acqLitEditOrderMarc.domNode);
464 openils.Util.show('acq-lit-marc-real-record-label');
466 openils.Util.show('acq-lit-marc-order-record-label');
467 openils.Util.show(acqLitEditOrderMarc.domNode);
468 openils.Util.hide('acq-lit-marc-real-record-label');
471 this.drawMarcHTML(li);
472 this.infoTbody = dojo.byId('acq-lit-info-tbody');
475 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
476 while(this.infoTbody.childNodes[0])
477 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
479 for(var i = 0; i < li.attributes().length; i++) {
480 var attr = li.attributes()[i];
481 var row = this.infoRow.cloneNode(true);
483 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
484 var name = openils.acq.Lineitem.attrDefs[type].filter(
486 return (a.code() == attr.attr_name());
488 ).pop().description();
490 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
491 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
492 this.infoTbody.appendChild(row);
496 openils.Util.show('acq-lit-info-cat-link');
497 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
499 if(openils.XUL.isXUL()) {
501 var makeRecTab = function() {
504 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
507 show_nav_buttons : true,
508 show_print_button : true,
509 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
513 link.setAttribute('href', 'javascript:void(0);');
514 link.onclick = makeRecTab;
517 var href = link.getAttribute('href');
519 link.setAttribute('href', href + li.eg_bib_id());
522 openils.Util.hide('acq-lit-info-cat-link');
526 this.drawMarcHTML = function(li) {
527 var params = [null, true, li.marc()];
529 params = [li.eg_bib_id(), true];
531 fieldmapper.standardRequest(
532 ['open-ils.search', 'open-ils.search.biblio.record.html'],
535 oncomplete: function(r) {
536 dojo.byId('acq-lit-marc-div').innerHTML =
537 openils.Util.readResponse(r);
543 this.drawCopies = function(liId) {
547 this.copyWidgetCache = {};
549 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
550 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
551 acqLitCopyCountInput.attr('value', '0');
553 while(this.copyTbody.childNodes[0])
554 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
556 this._drawBatchCopyWidgets();
558 this._fetchDistribFormulas(
560 openils.acq.Lineitem.fetchAttrDefs(
562 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
570 * Insert a new row into the distribution formula selection form
572 this._addDistribFormulaRow = function() {
575 if(!self.distribFormulaStore) {
576 // no formulas, hide the form
577 openils.Util.hide('acq-lit-distrib-formula-tbody');
581 if(!this.distribFormulaTemplate)
582 this.distribFormulaTemplate =
583 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
585 var row = dojo.byId('acq-lit-distrib-formula-tbody').appendChild(this.distribFormulaTemplate.cloneNode(true));
587 var selector = new dijit.form.FilteringSelect(
588 {store : self.distribFormulaStore},
589 nodeByName('selector', row)
592 var apply = new dijit.form.Button(
593 {label : 'Apply'}, // TODO i18n
594 nodeByName('set_button', row)
597 var release = new dijit.form.Button(
598 {label : 'Release', disabled: true}, // TODO i18n
599 nodeByName('rel_button', row)
602 dojo.connect(apply, 'onClick',
604 var form_id = selector.attr('value');
606 apply.attr('disabled', true);
607 release.attr('disabled', false);
608 self._applyDistribFormula(form_id);
612 dojo.connect(release, 'onClick',
614 apply.attr('disabled', false);
615 release.attr('disabled', true);
621 * Applies a distrib formula to the current set of copies
623 this._applyDistribFormula = function(formula) {
626 formula = this.distribForms.filter(
628 return form.id() == formula;
632 var copyRows = dojo.query('tr', self.copyTbody);
634 for(var rowIndex = 0; rowIndex < copyRows.length; rowIndex++) {
636 var row = copyRows[rowIndex];
637 var copy_id = row.getAttribute('copy_id');
638 var copyWidgets = this.copyWidgetCache[copy_id];
642 // find the correct entry for the current row
643 dojo.forEach(formula.entries(),
646 entryIndex += e.item_count();
647 if(entryIndex > rowIndex)
655 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
656 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
659 ['owning_lib', 'location'],
662 copyWidgets[field].attr('value', (entry[field]()));
669 this._fetchDistribFormulas = function(onload) {
670 if(this.distribForms) {
674 fieldmapper.standardRequest(
675 ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve.atomic'],
677 params: [openils.User.authtoken],
678 oncomplete: function(r) {
679 self.distribForms = openils.Util.readResponse(r);
680 if(!self.distribForms || self.distribForms.length == 0) {
681 self.distribForms = [];
684 self.distribFormulaStore =
685 new dojo.data.ItemFileReadStore(
686 {data:acqdf.toStoreData(self.distribForms)});
687 self._addDistribFormulaRow();
695 this._drawBatchCopyWidgets = function() {
696 var row = this.copyBatchRow;
697 dojo.forEach(liDetailBatchFields,
699 if(self.copyBatchRowDrawn) {
700 self.copyBatchWidgets[field].attr('value', null);
702 var widget = new openils.widget.AutoFieldWidget({
705 parentNode : dojo.query('[name='+field+']', row)[0],
706 orgLimitPerms : ['CREATE_PICKLIST'],
707 dijitArgs : {required:false},
712 self.copyBatchWidgets[field] = w;
718 this.copyBatchRowDrawn = true;
721 this.batchCopyUpdate = function() {
723 for(var k in this.copyWidgetCache) {
724 var cache = this.copyWidgetCache[k];
725 dojo.forEach(liDetailBatchFields, function(f) {
726 var newval = self.copyBatchWidgets[f].attr('value');
727 if(newval) cache[f].attr('value', newval);
732 this._drawCopies = function(li) {
735 // this button sets the total number of copies for a given lineitem
736 acqLitAddCopyCount.onClick = function() {
737 var count = acqLitCopyCountInput.attr('value');
740 while(self.copyCount() < count)
743 // delete rows if necessary
744 var diff = self.copyCount() - count;
746 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
747 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
748 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
750 acqLitCopyCountInput.attr('value', self.copyCount()+'');
756 if(li.lineitem_details().length > 0) {
757 dojo.forEach(li.lineitem_details(),
759 self.addCopy(li, copy);
767 this.copyCount = function() {
769 for(var id in this.copyCache) {
770 if(!this.copyCache[id].isdeleted())
776 this.virtCopyId = -1;
777 this.addCopy = function(li, copy) {
778 var row = this.copyRow.cloneNode(true);
779 this.copyTbody.appendChild(row);
783 copy = new fieldmapper.acqlid();
785 copy.id(this.virtCopyId--);
786 copy.lineitem(li.id());
789 this.copyCache[copy.id()] = copy;
790 row.setAttribute('copy_id', copy.id());
791 self.copyWidgetCache[copy.id()] = {};
793 acqLitCopyCountInput.attr('value', self.copyCount()+'');
795 dojo.forEach(liDetailFields,
797 var widget = new openils.widget.AutoFieldWidget({
801 parentNode : dojo.query('[name='+field+']', row)[0],
802 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
803 readOnly : Boolean(copy.eg_copy_id())
806 // make sure we capture the value from any async widgets
808 copy[field](ww.getFormattedValue())
809 self.copyWidgetCache[copy.id()][field] = w;
812 dojo.connect(widget.widget, 'onChange',
814 if(copy.isnew() || val != copy[field]()) {
815 // prevent setting ischanged() automatically on widget load for existing copies
816 copy[field](widget.getFormattedValue())
817 copy.ischanged(true);
824 var recv_link = dojo.query('[name=receive]', row)[0];
825 if(copy.recv_time()) {
826 openils.Util.hide(recv_link);
828 recv_link.onclick = function() {
829 self.receiveLid(copy);
830 openils.Util.hide(recv_link);
835 openils.Util.hide(dojo.query('[name=delete]', row)[0].parentNode);
837 dojo.query('[name=delete]', row)[0].onclick =
838 function() { self.deleteCopy(row) };
842 this.deleteCopy = function(row) {
843 var copy = this.copyCache[row.getAttribute('copy_id')];
844 copy.isdeleted(true);
846 delete this.copyCache[copy.id()];
847 this.copyTbody.removeChild(row);
850 this.saveCopyChanges = function(liId) {
855 openils.Util.show('acq-lit-update-copies-progress');
858 for(var id in this.copyCache) {
859 var c = this.copyCache[id];
860 if(!c.isdeleted()) total++;
861 if(c.isnew() || c.ischanged() || c.isdeleted()) {
862 if(c.id() < 0) c.id(null);
867 if (typeof(this._copy_count_cb) == "function") {
868 this._copy_count_cb(liId, total);
871 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
873 if(copies.length == 0)
876 fieldmapper.standardRequest(
877 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
879 params: [openils.User.authtoken, copies],
880 onresponse: function(r) {
881 var res = openils.Util.readResponse(r);
882 litUpdateCopiesProgress.update(res);
884 oncomplete: function() {
885 openils.Util.hide('acq-lit-update-copies-progress');
886 self.drawCopies(liId);
892 this.applySelectedLiAction = function(action) {
896 case 'delete_selected':
897 this._deleteLiList(self.getSelected());
902 if(!this.createPoProviderSelector) {
903 var widget = new openils.widget.AutoFieldWidget({
904 fmField : 'provider',
906 parentNode : dojo.byId('acq-lit-po-provider'),
909 function(w) { self.createPoProviderSelector = w; }
913 if(!this.createPoAgencySelector) {
914 var widget = new openils.widget.AutoFieldWidget({
915 fmField : 'ordering_agency',
917 parentNode : dojo.byId('acq-lit-po-agency'),
918 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
921 function(w) { self.createPoAgencySelector = w; }
926 acqLitPoCreateDialog.show();
929 case 'save_picklist':
930 this._loadPLSelect();
931 acqLitSavePlDialog.show();
934 case 'selector_ready':
936 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
937 acqLitChangeLiStateDialog.show();
948 case 'rollback_receive_po':
949 this.rollbackPoReceive();
952 case 'create_assets':
956 case 'add_brief_record':
958 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
960 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
964 this.createAssets = function() {
965 if(!this.isPO) return;
966 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
967 this.show('acq-lit-progress-numbers');
969 fieldmapper.standardRequest(
970 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
972 params: [this.authtoken, this.isPO],
973 onresponse: function(r) {
974 var resp = openils.Util.readResponse(r);
975 self._updateProgressNumbers(resp, true);
981 this.printPO = function() {
982 if(!this.isPO) return;
983 progressDialog.show(true);
984 fieldmapper.standardRequest(
985 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
987 params: [this.authtoken, this.isPO, 'html'],
988 oncomplete: function(r) {
989 progressDialog.hide();
990 var evt = openils.Util.readResponse(r);
991 if(evt && evt.template_output()) {
992 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
993 win.document.body.innerHTML = evt.template_output().data();
1001 this.receivePO = function() {
1002 if(!this.isPO) return;
1003 this.show('acq-lit-progress-numbers');
1005 fieldmapper.standardRequest(
1006 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
1008 params: [this.authtoken, this.isPO],
1009 onresponse : function(r) {
1010 var resp = openils.Util.readResponse(r);
1011 self._updateProgressNumbers(resp, true);
1017 this.receiveLi = function(li) {
1018 if(!this.isPO) return;
1019 progressDialog.show(true);
1020 fieldmapper.standardRequest(
1021 ['open-ils.acq', 'open-ils.acq.lineitem.receive'],
1023 params: [this.authtoken, li.id()],
1024 onresponse : function(r) {
1025 var resp = openils.Util.readResponse(r);
1026 progressDialog.hide();
1032 this.receiveLid = function(li) {
1033 if(!this.isPO) return;
1034 progressDialog.show(true);
1035 fieldmapper.standardRequest(
1036 ['open-ils.acq', 'open-ils.acq.lineitem_detail.receive'],
1038 params: [this.authtoken, li.id()],
1039 onresponse : function(r) {
1040 var resp = openils.Util.readResponse(r);
1041 progressDialog.hide();
1047 this.rollbackPoReceive = function() {
1048 if(!this.isPO) return;
1049 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
1050 this.show('acq-lit-progress-numbers');
1052 fieldmapper.standardRequest(
1053 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
1055 params: [this.authtoken, this.isPO],
1056 onresponse : function(r) {
1057 var resp = openils.Util.readResponse(r);
1058 self._updateProgressNumbers(resp, true);
1064 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1066 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1067 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1068 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1069 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1070 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1071 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1072 if(resp.complete && reloadOnComplete)
1073 location.href = location.href;
1077 this._createPO = function(fields) {
1078 this.show('acq-lit-progress-numbers');
1079 var po = new fieldmapper.acqpo();
1080 po.provider(this.createPoProviderSelector.attr('value'));
1081 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1083 var selected = this.getSelected( (fields.create_from == 'all') );
1084 if(selected.length == 0) return;
1086 var max = selected.length * 3;
1089 fieldmapper.standardRequest(
1090 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1093 openils.User.authtoken,
1096 lineitems : selected.map(function(li) { return li.id() }),
1097 create_assets : fields.create_assets[0],
1101 onresponse : function(r) {
1102 var resp = openils.Util.readResponse(r);
1103 self._updateProgressNumbers(resp);
1105 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1111 this._deleteLiList = function(list, idx) {
1112 if(idx == null) idx = 0;
1113 if(idx >= list.length) return;
1114 var liId = list[idx].id();
1115 fieldmapper.standardRequest(
1116 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1118 params: [openils.User.authtoken, liId],
1119 oncomplete: function(r) {
1120 self.removeLineitem(liId);
1121 self._deleteLiList(list, ++idx);
1127 this.editOrderMarc = function(li) {
1129 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1130 to true in about:config */
1132 if(!openils.XUL.enableXPConnect()) return;
1134 if(openils.XUL.isXUL()) {
1135 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1137 win = window.open('/xul/server/cat/marcedit.xul');
1141 record : {marc : li.marc()},
1143 label: 'Save Record', // XXX I18N
1144 func: function(xmlString) {
1146 fieldmapper.standardRequest(
1147 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1149 params: [openils.User.authtoken, li],
1150 oncomplete: function(r) {
1151 openils.Util.readResponse(r);
1153 self.drawInfo(li.id())
1162 this._savePl = function(values) {
1164 var selected = this.getSelected( (values.which == 'all') );
1165 openils.Util.show('acq-lit-generic-progress');
1167 if(values.new_name) {
1168 openils.acq.Picklist.create(
1169 {name: values.new_name},
1171 self._updateLiList(id, selected, 0,
1173 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1177 } else if(values.existing_pl) {
1178 // update lineitems to use an existing picklist
1179 self._updateLiList(values.existing_pl, selected, 0,
1181 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1186 this._updateLiState = function(values, state) {
1188 var selected = this.getSelected( (values.which == 'all') );
1189 if(!selected.length) return;
1190 dojo.forEach(selected, function(li) {li.state(state);});
1191 self._updateLiList(null, selected, 0,
1192 // TODO consider inline updates for efficiency
1193 function() { location.href = location.href }
1197 this._updateLiList = function(pl, list, idx, oncomplete) {
1198 if(idx >= list.length) return oncomplete();
1200 if(pl != null) li.picklist(pl);
1201 litGenericProgress.update({maximum: list.length, progress: idx});
1202 new openils.acq.Lineitem({lineitem:li}).update(
1204 self._updateLiList(pl, list, ++idx, oncomplete);
1209 this._loadPLSelect = function() {
1210 if(this._plSelectLoaded) return;
1212 function handleResponse(r) {
1213 plList.push(r.recv().content());
1215 var method = 'open-ils.acq.picklist.user.retrieve';
1216 fieldmapper.standardRequest(
1217 ['open-ils.acq', method],
1219 params: [this.authtoken],
1220 onresponse: handleResponse,
1221 oncomplete: function() {
1222 self._plSelectLoaded = true;
1223 acqLitAddExistingSelect.store =
1224 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1225 acqLitAddExistingSelect.setValue();
1231 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1232 this.showRealCopies = function(li) {
1233 while(this.realCopiesTbody.childNodes[0])
1234 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1235 this.show('real-copies');
1237 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1238 this.realCopyList = [];
1240 var tabIndex = 1000;
1243 acqLitSaveRealCopies.onClick = function() {
1244 self.saveRealCopies();
1247 this._fetchLineitem(li.id(),
1249 li = self.liCache[li.id()] = fullLi;
1253 id : li.lineitem_details().map(
1254 function(item) { return item.eg_copy_id() }
1259 onresponse : function(r) {
1260 var copy = openils.Util.readResponse(r);
1261 var volId = copy.call_number();
1262 var volume = self.volCache[volId];
1264 volume = self.volCache[volId] = pcrud.retrieve('acn', volId);
1266 self.addRealCopy(volume, copy, tabIndex++);
1274 this.addRealCopy = function(volume, copy, tabIndex) {
1275 var row = this.realCopiesRow.cloneNode(true);
1276 this.realCopyList.push(copy);
1280 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1283 var isvol = (field == 'owning_lib' || field == 'label');
1284 var widget = new openils.widget.AutoFieldWidget({
1286 fmObject : isvol ? volume : copy,
1287 parentNode : nodeByName(field, row),
1288 readOnly : (field != 'barcode'),
1291 var widgetDrawn = null;
1293 if(field == 'barcode') {
1295 widgetDrawn = function(w, ww) {
1296 var node = w.domNode;
1297 node.setAttribute('tabindex', ''+tabIndex);
1299 // on enter, select the next barcode input
1300 dojo.connect(w, 'onKeyDown',
1302 if(e.keyCode == dojo.keys.ENTER) {
1303 var ti = node.getAttribute('tabindex');
1304 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1305 if(nextNode) nextNode.select();
1310 dojo.connect(w, 'onChange',
1312 if(!val || val == copy.barcode()) return;
1313 copy.ischanged(true);
1319 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1324 widget.build(widgetDrawn);
1328 this.realCopiesTbody.appendChild(row);
1329 if(selectNode) selectNode.select();
1332 this.saveRealCopies = function() {
1333 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1334 progressDialog.show(true);
1335 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1336 pcrud.update(list, {oncomplete: function() {
1337 progressDialog.hide();