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() {
35 this.toggleState = false;
36 this.tbody = dojo.byId('acq-lit-tbody');
38 this.authtoken = openils.User.authtoken;
39 this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
40 this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
41 this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
42 this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
43 this.copyBatchWidgets = {};
44 this.liNotesTbody = dojo.byId('acq-lit-notes-tbody');
45 this.liNotesRow = this.liNotesTbody.removeChild(dojo.byId('acq-lit-notes-row'));
46 this.realCopiesTbody = dojo.byId('acq-lit-real-copies-tbody');
47 this.realCopiesRow = this.realCopiesTbody.removeChild(dojo.byId('acq-lit-real-copies-row'));
49 dojo.connect(acqLitLiActionsSelector, 'onChange',
51 self.applySelectedLiAction(this.attr('value'))
52 acqLitLiActionsSelector.attr('value', '_');
55 acqLitCreatePoSubmit.onClick = function() {
56 acqLitPoCreateDialog.hide();
57 self._createPO(acqLitPoCreateDialog.getValues());
60 acqLitSavePlButton.onClick = function() {
61 acqLitSavePlDialog.hide();
62 self._savePl(acqLitSavePlDialog.getValues());
66 //dojo.byId('acq-lit-notes-new-button').onclick = function(){acqLitCreateLiNoteDialog.show();}
68 dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
69 dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
70 dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
71 dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
72 dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
74 this.reset = function() {
75 while(self.tbody.childNodes[0])
76 self.tbody.removeChild(self.tbody.childNodes[0]);
80 this.setNext = function(handler) {
81 var link = dojo.byId('acq-lit-next');
83 dojo.style(link, 'visibility', 'visible');
84 link.onclick = handler;
86 dojo.style(link, 'visibility', 'hidden');
90 this.setPrev = function(handler) {
91 var link = dojo.byId('acq-lit-prev');
93 dojo.style(link, 'visibility', 'visible');
94 link.onclick = handler;
96 dojo.style(link, 'visibility', 'hidden');
100 this.show = function(div) {
101 openils.Util.hide('acq-lit-table-div');
102 openils.Util.hide('acq-lit-info-div');
103 openils.Util.hide('acq-lit-li-details');
104 openils.Util.hide('acq-lit-notes-div');
105 openils.Util.hide('acq-lit-real-copies-div');
108 openils.Util.show('acq-lit-table-div');
111 openils.Util.show('acq-lit-info-div');
114 openils.Util.show('acq-lit-li-details');
117 openils.Util.show('acq-lit-real-copies-div');
120 openils.Util.show('acq-lit-notes-div');
124 openils.Util.show(div);
128 this.hide = function() {
132 this.toggleSelect = function() {
134 dojo.forEach(self.selectors, function(i){i.checked = false});
136 dojo.forEach(self.selectors, function(i){i.checked = true});
137 self.toggleState = !self.toggleState;
141 /** @param all If true, assume all are selected */
142 this.getSelected = function(all) {
144 dojo.forEach(self.selectors,
147 selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
153 this.setRowAttr = function(td, liWrapper, field, type) {
154 var val = liWrapper.findAttr(field, type || 'lineitem_marc_attr_definition') || '';
155 td.appendChild(document.createTextNode(val));
158 this.addLineitem = function(li) {
159 this.liCache[li.id()] = li;
161 // sort the lineitem notes on edit_time
162 if(!li.lineitem_notes()) li.lineitem_notes([]);
164 var liWrapper = new openils.acq.Lineitem({lineitem:li});
165 var row = self.rowTemplate.cloneNode(true);
166 row.setAttribute('li', li.id());
167 var tds = dojo.query('[attr]', row);
168 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
169 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
171 var isbn = liWrapper.findAttr('isbn', 'lineitem_marc_attr_definition');
173 // XXX media prefix for added content
174 dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
177 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
178 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
179 dojo.query('[name=notes_count]', row)[0].innerHTML = li.lineitem_notes().length;
180 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
182 var countNode = nodeByName('count', row);
183 countNode.innerHTML = li.item_count() || 0;
184 countNode.id = 'acq-lit-copy-count-label-' + li.id();
186 var priceInput = dojo.query('[name=price]', row)[0];
187 var priceData = liWrapper.getPrice();
188 priceInput.value = (priceData) ? priceData.price : '';
189 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
191 var recv_link = dojo.query('[name=receive_link]', row)[0];
193 if(li.state() == 'received') {
194 // if the LI is received, hide the receive link and show the 'update barcodes' link
195 openils.Util.hide(recv_link)
197 recv_link.onclick = function() {
199 openils.Util.hide(recv_link)
204 var real_copies_link = dojo.query('[name=real_copies_link]', row)[0];
205 openils.Util.show(real_copies_link);
206 real_copies_link.onclick = function() {
207 self.showRealCopies(li);
211 self.tbody.appendChild(row);
212 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
215 this.drawLiNotes = function(li) {
219 li.lineitem_notes().sort(
221 if(a.edit_time() < b.edit_time()) return 1;
227 while(this.liNotesTbody.childNodes[0])
228 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
231 acqLitCreateLiNoteSubmit.onClick = function() {
232 var value = acqLitCreateNoteText.attr('value');
234 var note = new fieldmapper.acqlin();
237 note.lineitem(li.id());
238 self.updateLiNotes(li, note);
241 dojo.byId('acq-lit-notes-save-button').onclick = function() {
242 self.updateLiNotes(li);
245 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
248 this.addLiNote = function(li, note) {
249 if(note.isdeleted()) return;
251 var row = self.liNotesRow.cloneNode(true);
252 dojo.query('[name=value]', row)[0].innerHTML = note.value();
254 dojo.query('[name=delete]', row)[0].onclick = function() {
255 note.isdeleted(true);
256 self.liNotesTbody.removeChild(row);
259 if(note.edit_time()) {
260 dojo.query('[name=edit_time]', row)[0].innerHTML =
261 dojo.date.locale.format(
262 dojo.date.stamp.fromISOString(note.edit_time()),
263 {formatLength:'short'});
266 self.liNotesTbody.appendChild(row);
269 this.updateLiNotes = function(li, newNote) {
275 notes = li.lineitem_notes().filter(
277 if(note.ischanged() || note.isnew() || note.isdeleted())
283 if(notes.length == 0) return;
284 progressDialog.show();
286 fieldmapper.standardRequest(
287 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
289 params : [this.authtoken, notes],
290 onresponse : function(r) {
291 var resp = openils.Util.readResponse(r);
296 // remove the old changed notes
298 dojo.forEach(li.lineitem_notes(),
300 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
304 li.lineitem_notes(list);
307 progressDialog.hide();
308 self.drawLiNotes(li);
312 progressDialog.update(resp);
313 var newnote = resp.note;
315 if(!newnote.isdeleted()) {
316 newnote.isnew(false);
317 newnote.ischanged(false);
318 li.lineitem_notes().push(newnote);
325 this.updateLiPrice = function(input, li) {
327 var price = input.value;
328 var liWrapper = new openils.acq.Lineitem({lineitem:li});
329 var oldPrice = liWrapper.getPrice() || null;
331 if(oldPrice) oldPrice = oldPrice.price;
332 if(price == oldPrice) return;
334 fieldmapper.standardRequest(
335 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
337 params : [this.authtoken, li.id(), price],
338 oncomplete : function(r) {
339 openils.Util.readResponse(r);
345 this.removeLineitem = function(liId) {
346 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
347 delete this.liCache[liId];
348 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
351 this.drawInfo = function(liId) {
353 openils.acq.Lineitem.fetchAttrDefs(
355 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
360 this._fetchLineitem = function(liId, handler) {
362 var li = this.liCache[liId];
363 if(li && li.marc() && li.lineitem_details())
366 fieldmapper.standardRequest(
367 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
370 params: [self.authtoken, liId, {
372 flesh_li_details: true,
373 flesh_fund_debit: true }],
375 oncomplete: function(r) {
376 var li = openils.Util.readResponse(r);
383 this._drawInfo = function(li) {
385 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
388 openils.Util.hide('acq-lit-marc-order-record-label');
389 openils.Util.hide(acqLitEditOrderMarc.domNode);
390 openils.Util.show('acq-lit-marc-real-record-label');
392 openils.Util.show('acq-lit-marc-order-record-label');
393 openils.Util.show(acqLitEditOrderMarc.domNode);
394 openils.Util.hide('acq-lit-marc-real-record-label');
397 this.drawMarcHTML(li);
398 this.infoTbody = dojo.byId('acq-lit-info-tbody');
401 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
402 while(this.infoTbody.childNodes[0])
403 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
405 for(var i = 0; i < li.attributes().length; i++) {
406 var attr = li.attributes()[i];
407 var row = this.infoRow.cloneNode(true);
409 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
410 var name = openils.acq.Lineitem.attrDefs[type].filter(
412 return (a.code() == attr.attr_name());
414 ).pop().description();
416 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
417 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
418 this.infoTbody.appendChild(row);
422 openils.Util.show('acq-lit-info-cat-link');
423 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
425 if(openils.XUL.isXUL()) {
427 var makeRecTab = function() {
430 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
433 show_nav_buttons : true,
434 show_print_button : true,
435 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
439 link.setAttribute('href', 'javascript:void(0);');
440 link.onclick = makeRecTab;
443 var href = link.getAttribute('href');
445 link.setAttribute('href', href + li.eg_bib_id());
448 openils.Util.hide('acq-lit-info-cat-link');
452 this.drawMarcHTML = function(li) {
453 var params = [null, true, li.marc()];
455 params = [li.eg_bib_id(), true];
457 fieldmapper.standardRequest(
458 ['open-ils.search', 'open-ils.search.biblio.record.html'],
461 oncomplete: function(r) {
462 dojo.byId('acq-lit-marc-div').innerHTML =
463 openils.Util.readResponse(r);
469 this.drawCopies = function(liId) {
473 this.copyWidgetCache = {};
475 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
476 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
478 while(this.copyTbody.childNodes[0])
479 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
481 this._drawBatchCopyWidgets();
483 this._fetchDistribFormulas(
485 openils.acq.Lineitem.fetchAttrDefs(
487 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
494 this._fetchDistribFormulas = function(onload) {
495 if(this.distribForms) {
499 fieldmapper.standardRequest(
500 ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve.atomic'],
502 params: [openils.User.authtoken],
503 oncomplete: function(r) {
504 self.distribForms = openils.Util.readResponse(r);
505 if(!self.distribForms || self.distribForms.length == 0) {
506 self.distribForms = [];
509 self.distribFormulaStore =
510 new dojo.data.ItemFileReadStore(
511 {data:acqdf.toStoreData(self.distribForms)});
519 this._drawBatchCopyWidgets = function() {
520 var row = this.copyBatchRow;
521 dojo.forEach(liDetailBatchFields,
523 if(self.copyBatchRowDrawn) {
524 self.copyBatchWidgets[field].attr('value', null);
526 var widget = new openils.widget.AutoFieldWidget({
529 parentNode : dojo.query('[name='+field+']', row)[0],
530 orgLimitPerms : ['CREATE_PICKLIST'],
531 dijitArgs : {required:false},
536 self.copyBatchWidgets[field] = w;
542 this.copyBatchRowDrawn = true;
545 this.batchCopyUpdate = function() {
547 for(var k in this.copyWidgetCache) {
548 var cache = this.copyWidgetCache[k];
549 dojo.forEach(liDetailBatchFields, function(f) {
550 var newval = self.copyBatchWidgets[f].attr('value');
551 if(newval) cache[f].attr('value', newval);
556 this._drawCopies = function(li) {
557 acqLitAddCopyCount.onClick = function() {
558 var count = acqLitCopyCountInput.attr('value');
559 for(var i = 0; i < count; i++)
562 if(li.lineitem_details().length > 0) {
563 dojo.forEach(li.lineitem_details(),
565 self.addCopy(li, copy);
573 this.virtCopyId = -1;
574 this.addCopy = function(li, copy) {
575 var row = this.copyRow.cloneNode(true);
576 this.copyTbody.appendChild(row);
580 copy = new fieldmapper.acqlid();
582 copy.id(this.virtCopyId--);
583 copy.lineitem(li.id());
586 this.copyCache[copy.id()] = copy;
587 row.setAttribute('copy_id', copy.id());
588 self.copyWidgetCache[copy.id()] = {};
590 dojo.forEach(liDetailFields,
592 var widget = new openils.widget.AutoFieldWidget({
596 parentNode : dojo.query('[name='+field+']', row)[0],
597 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
598 readOnly : Boolean(copy.eg_copy_id())
601 // make sure we capture the value from any async widgets
603 copy[field](ww.getFormattedValue())
604 self.copyWidgetCache[copy.id()][field] = w;
607 dojo.connect(widget.widget, 'onChange',
609 if(copy.isnew() || val != copy[field]()) {
610 // prevent setting ischanged() automatically on widget load for existing copies
611 copy[field](widget.getFormattedValue())
612 copy.ischanged(true);
619 var recv_link = dojo.query('[name=receive]', row)[0];
620 if(copy.recv_time()) {
621 openils.Util.hide(recv_link);
623 recv_link.onclick = function() {
624 self.receiveLid(copy);
625 openils.Util.hide(recv_link);
630 openils.Util.hide(dojo.query('[name=delete]', row)[0].parentNode);
632 dojo.query('[name=delete]', row)[0].onclick =
633 function() { self.deleteCopy(row) };
637 this.deleteCopy = function(row) {
638 var copy = this.copyCache[row.getAttribute('copy_id')];
639 copy.isdeleted(true);
641 delete this.copyCache[copy.id()];
642 this.copyTbody.removeChild(row);
645 this.saveCopyChanges = function(liId) {
650 openils.Util.show('acq-lit-update-copies-progress');
653 for(var id in this.copyCache) {
654 var c = this.copyCache[id];
655 if(!c.isdeleted()) total++;
656 if(c.isnew() || c.ischanged() || c.isdeleted()) {
657 if(c.id() < 0) c.id(null);
662 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
664 if(copies.length == 0)
667 fieldmapper.standardRequest(
668 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
670 params: [openils.User.authtoken, copies],
671 onresponse: function(r) {
672 var res = openils.Util.readResponse(r);
673 litUpdateCopiesProgress.update(res);
675 oncomplete: function() {
676 openils.Util.hide('acq-lit-update-copies-progress');
677 self.drawCopies(liId);
683 this.applySelectedLiAction = function(action) {
687 case 'delete_selected':
688 this._deleteLiList(self.getSelected());
693 if(!this.createPoProviderSelector) {
694 var widget = new openils.widget.AutoFieldWidget({
695 fmField : 'provider',
697 parentNode : dojo.byId('acq-lit-po-provider'),
700 function(w) { self.createPoProviderSelector = w; }
704 if(!this.createPoAgencySelector) {
705 var widget = new openils.widget.AutoFieldWidget({
706 fmField : 'ordering_agency',
708 parentNode : dojo.byId('acq-lit-po-agency'),
709 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
712 function(w) { self.createPoAgencySelector = w; }
717 acqLitPoCreateDialog.show();
720 case 'save_picklist':
721 this._loadPLSelect();
722 acqLitSavePlDialog.show();
733 case 'rollback_receive_po':
734 this.rollbackPoReceive();
737 case 'create_assets':
741 case 'add_brief_record':
743 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
745 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
749 this.createAssets = function() {
750 if(!this.isPO) return;
751 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
752 this.show('acq-lit-progress-numbers');
754 fieldmapper.standardRequest(
755 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
757 params: [this.authtoken, this.isPO],
758 onresponse: function(r) {
759 var resp = openils.Util.readResponse(r);
760 self._updateProgressNumbers(resp, true);
766 this.printPO = function() {
767 if(!this.isPO) return;
768 progressDialog.show(true);
769 fieldmapper.standardRequest(
770 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
772 params: [this.authtoken, this.isPO, 'html'],
773 oncomplete: function(r) {
774 progressDialog.hide();
775 var evt = openils.Util.readResponse(r);
776 if(evt && evt.template_output()) {
777 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
778 win.document.body.innerHTML = evt.template_output().data();
786 this.receivePO = function() {
787 if(!this.isPO) return;
788 this.show('acq-lit-progress-numbers');
790 fieldmapper.standardRequest(
791 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
793 params: [this.authtoken, this.isPO],
794 onresponse : function(r) {
795 var resp = openils.Util.readResponse(r);
796 self._updateProgressNumbers(resp, true);
802 this.receiveLi = function(li) {
803 if(!this.isPO) return;
804 progressDialog.show(true);
805 fieldmapper.standardRequest(
806 ['open-ils.acq', 'open-ils.acq.lineitem.receive'],
808 params: [this.authtoken, li.id()],
809 onresponse : function(r) {
810 var resp = openils.Util.readResponse(r);
811 progressDialog.hide();
817 this.receiveLid = function(li) {
818 if(!this.isPO) return;
819 progressDialog.show(true);
820 fieldmapper.standardRequest(
821 ['open-ils.acq', 'open-ils.acq.lineitem_detail.receive'],
823 params: [this.authtoken, li.id()],
824 onresponse : function(r) {
825 var resp = openils.Util.readResponse(r);
826 progressDialog.hide();
832 this.rollbackPoReceive = function() {
833 if(!this.isPO) return;
834 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
835 this.show('acq-lit-progress-numbers');
837 fieldmapper.standardRequest(
838 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
840 params: [this.authtoken, this.isPO],
841 onresponse : function(r) {
842 var resp = openils.Util.readResponse(r);
843 self._updateProgressNumbers(resp, true);
849 this._updateProgressNumbers = function(resp, reloadOnComplete) {
851 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
852 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
853 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
854 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
855 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
856 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
857 if(resp.complete && reloadOnComplete)
858 location.href = location.href;
862 this._createPO = function(fields) {
863 this.show('acq-lit-progress-numbers');
864 var po = new fieldmapper.acqpo();
865 po.provider(this.createPoProviderSelector.attr('value'));
866 po.ordering_agency(this.createPoAgencySelector.attr('value'));
868 var selected = this.getSelected( (fields.create_from == 'all') );
869 if(selected.length == 0) return;
871 var max = selected.length * 3;
874 fieldmapper.standardRequest(
875 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
878 openils.User.authtoken,
881 lineitems : selected.map(function(li) { return li.id() }),
882 create_assets : fields.create_assets[0],
886 onresponse : function(r) {
887 var resp = openils.Util.readResponse(r);
888 self._updateProgressNumbers(resp);
890 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
896 this._deleteLiList = function(list, idx) {
897 if(idx == null) idx = 0;
898 if(idx >= list.length) return;
899 var liId = list[idx].id();
900 fieldmapper.standardRequest(
901 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
903 params: [openils.User.authtoken, liId],
904 oncomplete: function(r) {
905 self.removeLineitem(liId);
906 self._deleteLiList(list, ++idx);
912 this.editOrderMarc = function(li) {
914 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
915 to true in about:config */
917 if(!openils.XUL.enableXPConnect()) return;
919 if(openils.XUL.isXUL()) {
920 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
923 win = window.open('/xul/server/cat/marcedit.xul');
926 record : {marc : li.marc()},
928 label: 'Save Record', // XXX I18N
929 func: function(xmlString) {
931 fieldmapper.standardRequest(
932 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
934 params: [openils.User.authtoken, li],
935 oncomplete: function(r) {
936 openils.Util.readResponse(r);
938 self.drawInfo(li.id())
948 this._savePl = function(values) {
950 var selected = this.getSelected( (values.which == 'all') );
951 openils.Util.show('acq-lit-generic-progress');
953 if(values.new_name) {
954 openils.acq.Picklist.create(
955 {name: values.new_name},
957 self._updateLiList(id, selected, 0,
959 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
963 } else if(values.existing_pl) {
964 // update lineitems to use an existing picklist
965 self._updateLiList(values.existing_pl, selected, 0,
967 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
972 this._updateLiList = function(pl, list, idx, oncomplete) {
973 if(idx >= list.length) return oncomplete();
976 litGenericProgress.update({maximum: list.length, progress: idx});
977 new openils.acq.Lineitem({lineitem:li}).update(
979 self._updateLiList(pl, list, ++idx, oncomplete);
984 this._loadPLSelect = function() {
985 if(this._plSelectLoaded) return;
987 function handleResponse(r) {
988 plList.push(r.recv().content());
990 var method = 'open-ils.acq.picklist.user.retrieve';
991 fieldmapper.standardRequest(
992 ['open-ils.acq', method],
994 params: [this.authtoken],
995 onresponse: handleResponse,
996 oncomplete: function() {
997 self._plSelectLoaded = true;
998 acqLitAddExistingSelect.store =
999 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1000 acqLitAddExistingSelect.setValue();
1006 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1007 this.showRealCopies = function(li) {
1008 while(this.realCopiesTbody.childNodes[0])
1009 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1010 this.show('real-copies');
1012 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1013 this.realCopyList = [];
1015 var tabIndex = 1000;
1018 acqLitSaveRealCopies.onClick = function() {
1019 self.saveRealCopies();
1022 this._fetchLineitem(li.id(),
1024 li = self.liCache[li.id()] = fullLi;
1028 id : li.lineitem_details().map(
1029 function(item) { return item.eg_copy_id() }
1034 onresponse : function(r) {
1035 var copy = openils.Util.readResponse(r);
1036 var volId = copy.call_number();
1037 var volume = self.volCache[volId];
1039 volume = self.volCache[volId] = pcrud.retrieve('acn', volId);
1041 self.addRealCopy(volume, copy, tabIndex++);
1049 this.addRealCopy = function(volume, copy, tabIndex) {
1050 var row = this.realCopiesRow.cloneNode(true);
1051 this.realCopyList.push(copy);
1055 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1058 var isvol = (field == 'owning_lib' || field == 'label');
1059 var widget = new openils.widget.AutoFieldWidget({
1061 fmObject : isvol ? volume : copy,
1062 parentNode : nodeByName(field, row),
1063 readOnly : (field != 'barcode'),
1066 var widgetDrawn = null;
1068 if(field == 'barcode') {
1070 widgetDrawn = function(w, ww) {
1071 var node = w.domNode;
1072 node.setAttribute('tabindex', ''+tabIndex);
1074 // on enter, select the next barcode input
1075 dojo.connect(w, 'onKeyDown',
1077 if(e.keyCode == dojo.keys.ENTER) {
1078 var ti = node.getAttribute('tabindex');
1079 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1080 if(nextNode) nextNode.select();
1085 dojo.connect(w, 'onChange',
1087 if(!val || val == copy.barcode()) return;
1088 copy.ischanged(true);
1094 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1099 widget.build(widgetDrawn);
1103 this.realCopiesTbody.appendChild(row);
1104 if(selectNode) selectNode.select();
1107 this.saveRealCopies = function() {
1108 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1109 progressDialog.show(true);
1110 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1111 pcrud.update(list, {oncomplete: function() {
1112 progressDialog.hide();