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));
159 * Inserts a single lineitem into the growing table of lineitems
160 * @param {Object} li The lineitem object to insert
162 this.addLineitem = function(li) {
163 this.liCache[li.id()] = li;
165 // sort the lineitem notes on edit_time
166 if(!li.lineitem_notes()) li.lineitem_notes([]);
168 var liWrapper = new openils.acq.Lineitem({lineitem:li});
169 var row = self.rowTemplate.cloneNode(true);
170 row.setAttribute('li', li.id());
171 var tds = dojo.query('[attr]', row);
172 dojo.forEach(tds, function(td) {self.setRowAttr(td, liWrapper, td.getAttribute('attr'), td.getAttribute('attr_type'));});
173 dojo.query('[name=source_label]', row)[0].appendChild(document.createTextNode(li.source_label()));
175 var isbn = liWrapper.findAttr('isbn', 'lineitem_marc_attr_definition');
177 // XXX media prefix for added content
178 dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
181 dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
182 dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
183 dojo.query('[name=notes_count]', row)[0].innerHTML = li.lineitem_notes().length;
184 dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
186 if(li.purchase_order() && !this.isPO) {
187 openils.Util.show(nodeByName('po', row), 'inline');
188 nodeByName('po_link', row).setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
191 var countNode = nodeByName('count', row);
192 countNode.innerHTML = li.item_count() || 0;
193 countNode.id = 'acq-lit-copy-count-label-' + li.id();
196 nodeByName('li_state', row).innerHTML = li.state(); // TODO i18n state labels
199 var priceInput = dojo.query('[name=price]', row)[0];
200 var priceData = liWrapper.getPrice();
201 priceInput.value = (priceData) ? priceData.price : '';
202 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
204 var recv_link = dojo.query('[name=receive_link]', row)[0];
206 if(li.state() == 'on-order') {
207 recv_link.onclick = function() {
209 openils.Util.hide(recv_link)
212 openils.Util.hide(recv_link);
215 // TODO we should allow editing before receipt, in which case the
216 // test should be "if 1 or more real (acp) copies exist
217 if(li.state() == 'received') {
218 var real_copies_link = dojo.query('[name=real_copies_link]', row)[0];
219 openils.Util.show(real_copies_link);
220 real_copies_link.onclick = function() {
221 self.showRealCopies(li);
225 self.tbody.appendChild(row);
226 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
230 * Draws and shows the lineitem notes pane
232 this.drawLiNotes = function(li) {
236 li.lineitem_notes().sort(
238 if(a.edit_time() < b.edit_time()) return 1;
244 while(this.liNotesTbody.childNodes[0])
245 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
248 acqLitCreateLiNoteSubmit.onClick = function() {
249 var value = acqLitCreateNoteText.attr('value');
251 var note = new fieldmapper.acqlin();
254 note.lineitem(li.id());
255 self.updateLiNotes(li, note);
258 dojo.byId('acq-lit-notes-save-button').onclick = function() {
259 self.updateLiNotes(li);
262 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
266 * Draws a single lineitem note in the notes pane
268 this.addLiNote = function(li, note) {
269 if(note.isdeleted()) return;
271 var row = self.liNotesRow.cloneNode(true);
272 dojo.query('[name=value]', row)[0].innerHTML = note.value();
274 dojo.query('[name=delete]', row)[0].onclick = function() {
275 note.isdeleted(true);
276 self.liNotesTbody.removeChild(row);
279 if(note.edit_time()) {
280 dojo.query('[name=edit_time]', row)[0].innerHTML =
281 dojo.date.locale.format(
282 dojo.date.stamp.fromISOString(note.edit_time()),
283 {formatLength:'short'});
286 self.liNotesTbody.appendChild(row);
290 * Updates any new/changed/deleted notes on the server
292 this.updateLiNotes = function(li, newNote) {
298 notes = li.lineitem_notes().filter(
300 if(note.ischanged() || note.isnew() || note.isdeleted())
306 if(notes.length == 0) return;
307 progressDialog.show();
309 fieldmapper.standardRequest(
310 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
312 params : [this.authtoken, notes],
313 onresponse : function(r) {
314 var resp = openils.Util.readResponse(r);
319 // remove the old changed notes
321 dojo.forEach(li.lineitem_notes(),
323 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
327 li.lineitem_notes(list);
330 progressDialog.hide();
331 self.drawLiNotes(li);
335 progressDialog.update(resp);
336 var newnote = resp.note;
338 if(!newnote.isdeleted()) {
339 newnote.isnew(false);
340 newnote.ischanged(false);
341 li.lineitem_notes().push(newnote);
348 this.updateLiPrice = function(input, li) {
350 var price = input.value;
351 var liWrapper = new openils.acq.Lineitem({lineitem:li});
352 var oldPrice = liWrapper.getPrice() || null;
354 if(oldPrice) oldPrice = oldPrice.price;
355 if(price == oldPrice) return;
357 fieldmapper.standardRequest(
358 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
360 params : [this.authtoken, li.id(), price],
361 oncomplete : function(r) {
362 openils.Util.readResponse(r);
368 this.removeLineitem = function(liId) {
369 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
370 delete this.liCache[liId];
371 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
374 this.drawInfo = function(liId) {
376 openils.acq.Lineitem.fetchAttrDefs(
378 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
383 this._fetchLineitem = function(liId, handler) {
385 var li = this.liCache[liId];
386 if(li && li.marc() && li.lineitem_details())
389 fieldmapper.standardRequest(
390 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
393 params: [self.authtoken, liId, {
395 flesh_li_details: true,
396 flesh_fund_debit: true }],
398 oncomplete: function(r) {
399 var li = openils.Util.readResponse(r);
406 this._drawInfo = function(li) {
408 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
411 openils.Util.hide('acq-lit-marc-order-record-label');
412 openils.Util.hide(acqLitEditOrderMarc.domNode);
413 openils.Util.show('acq-lit-marc-real-record-label');
415 openils.Util.show('acq-lit-marc-order-record-label');
416 openils.Util.show(acqLitEditOrderMarc.domNode);
417 openils.Util.hide('acq-lit-marc-real-record-label');
420 this.drawMarcHTML(li);
421 this.infoTbody = dojo.byId('acq-lit-info-tbody');
424 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
425 while(this.infoTbody.childNodes[0])
426 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
428 for(var i = 0; i < li.attributes().length; i++) {
429 var attr = li.attributes()[i];
430 var row = this.infoRow.cloneNode(true);
432 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
433 var name = openils.acq.Lineitem.attrDefs[type].filter(
435 return (a.code() == attr.attr_name());
437 ).pop().description();
439 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
440 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
441 this.infoTbody.appendChild(row);
445 openils.Util.show('acq-lit-info-cat-link');
446 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
448 if(openils.XUL.isXUL()) {
450 var makeRecTab = function() {
453 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
456 show_nav_buttons : true,
457 show_print_button : true,
458 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
462 link.setAttribute('href', 'javascript:void(0);');
463 link.onclick = makeRecTab;
466 var href = link.getAttribute('href');
468 link.setAttribute('href', href + li.eg_bib_id());
471 openils.Util.hide('acq-lit-info-cat-link');
475 this.drawMarcHTML = function(li) {
476 var params = [null, true, li.marc()];
478 params = [li.eg_bib_id(), true];
480 fieldmapper.standardRequest(
481 ['open-ils.search', 'open-ils.search.biblio.record.html'],
484 oncomplete: function(r) {
485 dojo.byId('acq-lit-marc-div').innerHTML =
486 openils.Util.readResponse(r);
492 this.drawCopies = function(liId) {
496 this.copyWidgetCache = {};
498 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
499 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
500 acqLitCopyCountInput.attr('value', '0');
502 while(this.copyTbody.childNodes[0])
503 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
505 this._drawBatchCopyWidgets();
507 this._fetchDistribFormulas(
509 openils.acq.Lineitem.fetchAttrDefs(
511 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
519 * Insert a new row into the distribution formula selection form
521 this._addDistribFormulaRow = function() {
524 if(!self.distribFormulaStore) {
525 // no formulas, hide the form
526 openils.Util.hide('acq-lit-distrib-formula-tbody');
530 if(!this.distribFormulaTemplate)
531 this.distribFormulaTemplate =
532 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
534 var row = dojo.byId('acq-lit-distrib-formula-tbody').appendChild(this.distribFormulaTemplate.cloneNode(true));
536 var selector = new dijit.form.FilteringSelect(
537 {store : self.distribFormulaStore},
538 nodeByName('selector', row)
541 var apply = new dijit.form.Button(
542 {label : 'Apply'}, // TODO i18n
543 nodeByName('set_button', row)
546 var release = new dijit.form.Button(
547 {label : 'Release', disabled: true}, // TODO i18n
548 nodeByName('rel_button', row)
551 dojo.connect(apply, 'onClick',
553 var form_id = selector.attr('value');
555 apply.attr('disabled', true);
556 release.attr('disabled', false);
557 self._applyDistribFormula(form_id);
561 dojo.connect(release, 'onClick',
563 apply.attr('disabled', false);
564 release.attr('disabled', true);
570 * Applies a distrib formula to the current set of copies
572 this._applyDistribFormula = function(formula) {
575 formula = this.distribForms.filter(
577 return form.id() == formula;
581 var copyRows = dojo.query('tr', self.copyTbody);
583 for(var rowIndex = 0; rowIndex < copyRows.length; rowIndex++) {
585 var row = copyRows[rowIndex];
586 var copy_id = row.getAttribute('copy_id');
587 var copyWidgets = this.copyWidgetCache[copy_id];
591 // find the correct entry for the current row
592 dojo.forEach(formula.entries(),
595 entryIndex += e.item_count();
596 if(entryIndex > rowIndex)
604 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
605 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
608 ['owning_lib', 'location'],
611 copyWidgets[field].attr('value', (entry[field]()));
618 this._fetchDistribFormulas = function(onload) {
619 if(this.distribForms) {
623 fieldmapper.standardRequest(
624 ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve.atomic'],
626 params: [openils.User.authtoken],
627 oncomplete: function(r) {
628 self.distribForms = openils.Util.readResponse(r);
629 if(!self.distribForms || self.distribForms.length == 0) {
630 self.distribForms = [];
633 self.distribFormulaStore =
634 new dojo.data.ItemFileReadStore(
635 {data:acqdf.toStoreData(self.distribForms)});
636 self._addDistribFormulaRow();
644 this._drawBatchCopyWidgets = function() {
645 var row = this.copyBatchRow;
646 dojo.forEach(liDetailBatchFields,
648 if(self.copyBatchRowDrawn) {
649 self.copyBatchWidgets[field].attr('value', null);
651 var widget = new openils.widget.AutoFieldWidget({
654 parentNode : dojo.query('[name='+field+']', row)[0],
655 orgLimitPerms : ['CREATE_PICKLIST'],
656 dijitArgs : {required:false},
661 self.copyBatchWidgets[field] = w;
667 this.copyBatchRowDrawn = true;
670 this.batchCopyUpdate = function() {
672 for(var k in this.copyWidgetCache) {
673 var cache = this.copyWidgetCache[k];
674 dojo.forEach(liDetailBatchFields, function(f) {
675 var newval = self.copyBatchWidgets[f].attr('value');
676 if(newval) cache[f].attr('value', newval);
681 this._drawCopies = function(li) {
684 // this button sets the total number of copies for a given lineitem
685 acqLitAddCopyCount.onClick = function() {
686 var count = acqLitCopyCountInput.attr('value');
689 while(self.copyCount() < count)
692 // delete rows if necessary
693 var diff = self.copyCount() - count;
695 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
696 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
697 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
699 acqLitCopyCountInput.attr('value', self.copyCount()+'');
705 if(li.lineitem_details().length > 0) {
706 dojo.forEach(li.lineitem_details(),
708 self.addCopy(li, copy);
716 this.copyCount = function() {
718 for(var id in this.copyCache) {
719 if(!this.copyCache[id].isdeleted())
725 this.virtCopyId = -1;
726 this.addCopy = function(li, copy) {
727 var row = this.copyRow.cloneNode(true);
728 this.copyTbody.appendChild(row);
732 copy = new fieldmapper.acqlid();
734 copy.id(this.virtCopyId--);
735 copy.lineitem(li.id());
738 this.copyCache[copy.id()] = copy;
739 row.setAttribute('copy_id', copy.id());
740 self.copyWidgetCache[copy.id()] = {};
742 acqLitCopyCountInput.attr('value', self.copyCount()+'');
744 dojo.forEach(liDetailFields,
746 var widget = new openils.widget.AutoFieldWidget({
750 parentNode : dojo.query('[name='+field+']', row)[0],
751 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
752 readOnly : Boolean(copy.eg_copy_id())
755 // make sure we capture the value from any async widgets
757 copy[field](ww.getFormattedValue())
758 self.copyWidgetCache[copy.id()][field] = w;
761 dojo.connect(widget.widget, 'onChange',
763 if(copy.isnew() || val != copy[field]()) {
764 // prevent setting ischanged() automatically on widget load for existing copies
765 copy[field](widget.getFormattedValue())
766 copy.ischanged(true);
773 var recv_link = dojo.query('[name=receive]', row)[0];
774 if(copy.recv_time()) {
775 openils.Util.hide(recv_link);
777 recv_link.onclick = function() {
778 self.receiveLid(copy);
779 openils.Util.hide(recv_link);
784 openils.Util.hide(dojo.query('[name=delete]', row)[0].parentNode);
786 dojo.query('[name=delete]', row)[0].onclick =
787 function() { self.deleteCopy(row) };
791 this.deleteCopy = function(row) {
792 var copy = this.copyCache[row.getAttribute('copy_id')];
793 copy.isdeleted(true);
795 delete this.copyCache[copy.id()];
796 this.copyTbody.removeChild(row);
799 this.saveCopyChanges = function(liId) {
804 openils.Util.show('acq-lit-update-copies-progress');
807 for(var id in this.copyCache) {
808 var c = this.copyCache[id];
809 if(!c.isdeleted()) total++;
810 if(c.isnew() || c.ischanged() || c.isdeleted()) {
811 if(c.id() < 0) c.id(null);
816 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
818 if(copies.length == 0)
821 fieldmapper.standardRequest(
822 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
824 params: [openils.User.authtoken, copies],
825 onresponse: function(r) {
826 var res = openils.Util.readResponse(r);
827 litUpdateCopiesProgress.update(res);
829 oncomplete: function() {
830 openils.Util.hide('acq-lit-update-copies-progress');
831 self.drawCopies(liId);
837 this.applySelectedLiAction = function(action) {
841 case 'delete_selected':
842 this._deleteLiList(self.getSelected());
847 if(!this.createPoProviderSelector) {
848 var widget = new openils.widget.AutoFieldWidget({
849 fmField : 'provider',
851 parentNode : dojo.byId('acq-lit-po-provider'),
854 function(w) { self.createPoProviderSelector = w; }
858 if(!this.createPoAgencySelector) {
859 var widget = new openils.widget.AutoFieldWidget({
860 fmField : 'ordering_agency',
862 parentNode : dojo.byId('acq-lit-po-agency'),
863 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
866 function(w) { self.createPoAgencySelector = w; }
871 acqLitPoCreateDialog.show();
874 case 'save_picklist':
875 this._loadPLSelect();
876 acqLitSavePlDialog.show();
887 case 'rollback_receive_po':
888 this.rollbackPoReceive();
891 case 'create_assets':
895 case 'add_brief_record':
897 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
899 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
903 this.createAssets = function() {
904 if(!this.isPO) return;
905 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
906 this.show('acq-lit-progress-numbers');
908 fieldmapper.standardRequest(
909 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
911 params: [this.authtoken, this.isPO],
912 onresponse: function(r) {
913 var resp = openils.Util.readResponse(r);
914 self._updateProgressNumbers(resp, true);
920 this.printPO = function() {
921 if(!this.isPO) return;
922 progressDialog.show(true);
923 fieldmapper.standardRequest(
924 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
926 params: [this.authtoken, this.isPO, 'html'],
927 oncomplete: function(r) {
928 progressDialog.hide();
929 var evt = openils.Util.readResponse(r);
930 if(evt && evt.template_output()) {
931 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
932 win.document.body.innerHTML = evt.template_output().data();
940 this.receivePO = function() {
941 if(!this.isPO) return;
942 this.show('acq-lit-progress-numbers');
944 fieldmapper.standardRequest(
945 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
947 params: [this.authtoken, this.isPO],
948 onresponse : function(r) {
949 var resp = openils.Util.readResponse(r);
950 self._updateProgressNumbers(resp, true);
956 this.receiveLi = function(li) {
957 if(!this.isPO) return;
958 progressDialog.show(true);
959 fieldmapper.standardRequest(
960 ['open-ils.acq', 'open-ils.acq.lineitem.receive'],
962 params: [this.authtoken, li.id()],
963 onresponse : function(r) {
964 var resp = openils.Util.readResponse(r);
965 progressDialog.hide();
971 this.receiveLid = function(li) {
972 if(!this.isPO) return;
973 progressDialog.show(true);
974 fieldmapper.standardRequest(
975 ['open-ils.acq', 'open-ils.acq.lineitem_detail.receive'],
977 params: [this.authtoken, li.id()],
978 onresponse : function(r) {
979 var resp = openils.Util.readResponse(r);
980 progressDialog.hide();
986 this.rollbackPoReceive = function() {
987 if(!this.isPO) return;
988 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
989 this.show('acq-lit-progress-numbers');
991 fieldmapper.standardRequest(
992 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
994 params: [this.authtoken, this.isPO],
995 onresponse : function(r) {
996 var resp = openils.Util.readResponse(r);
997 self._updateProgressNumbers(resp, true);
1003 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1005 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1006 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1007 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1008 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1009 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1010 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1011 if(resp.complete && reloadOnComplete)
1012 location.href = location.href;
1016 this._createPO = function(fields) {
1017 this.show('acq-lit-progress-numbers');
1018 var po = new fieldmapper.acqpo();
1019 po.provider(this.createPoProviderSelector.attr('value'));
1020 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1022 var selected = this.getSelected( (fields.create_from == 'all') );
1023 if(selected.length == 0) return;
1025 var max = selected.length * 3;
1028 fieldmapper.standardRequest(
1029 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1032 openils.User.authtoken,
1035 lineitems : selected.map(function(li) { return li.id() }),
1036 create_assets : fields.create_assets[0],
1040 onresponse : function(r) {
1041 var resp = openils.Util.readResponse(r);
1042 self._updateProgressNumbers(resp);
1044 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1050 this._deleteLiList = function(list, idx) {
1051 if(idx == null) idx = 0;
1052 if(idx >= list.length) return;
1053 var liId = list[idx].id();
1054 fieldmapper.standardRequest(
1055 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1057 params: [openils.User.authtoken, liId],
1058 oncomplete: function(r) {
1059 self.removeLineitem(liId);
1060 self._deleteLiList(list, ++idx);
1066 this.editOrderMarc = function(li) {
1068 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1069 to true in about:config */
1071 if(!openils.XUL.enableXPConnect()) return;
1073 if(openils.XUL.isXUL()) {
1074 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1077 win = window.open('/xul/server/cat/marcedit.xul');
1080 record : {marc : li.marc()},
1082 label: 'Save Record', // XXX I18N
1083 func: function(xmlString) {
1085 fieldmapper.standardRequest(
1086 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1088 params: [openils.User.authtoken, li],
1089 oncomplete: function(r) {
1090 openils.Util.readResponse(r);
1092 self.drawInfo(li.id())
1102 this._savePl = function(values) {
1104 var selected = this.getSelected( (values.which == 'all') );
1105 openils.Util.show('acq-lit-generic-progress');
1107 if(values.new_name) {
1108 openils.acq.Picklist.create(
1109 {name: values.new_name},
1111 self._updateLiList(id, selected, 0,
1113 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1117 } else if(values.existing_pl) {
1118 // update lineitems to use an existing picklist
1119 self._updateLiList(values.existing_pl, selected, 0,
1121 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1126 this._updateLiList = function(pl, list, idx, oncomplete) {
1127 if(idx >= list.length) return oncomplete();
1130 litGenericProgress.update({maximum: list.length, progress: idx});
1131 new openils.acq.Lineitem({lineitem:li}).update(
1133 self._updateLiList(pl, list, ++idx, oncomplete);
1138 this._loadPLSelect = function() {
1139 if(this._plSelectLoaded) return;
1141 function handleResponse(r) {
1142 plList.push(r.recv().content());
1144 var method = 'open-ils.acq.picklist.user.retrieve';
1145 fieldmapper.standardRequest(
1146 ['open-ils.acq', method],
1148 params: [this.authtoken],
1149 onresponse: handleResponse,
1150 oncomplete: function() {
1151 self._plSelectLoaded = true;
1152 acqLitAddExistingSelect.store =
1153 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1154 acqLitAddExistingSelect.setValue();
1160 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1161 this.showRealCopies = function(li) {
1162 while(this.realCopiesTbody.childNodes[0])
1163 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1164 this.show('real-copies');
1166 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1167 this.realCopyList = [];
1169 var tabIndex = 1000;
1172 acqLitSaveRealCopies.onClick = function() {
1173 self.saveRealCopies();
1176 this._fetchLineitem(li.id(),
1178 li = self.liCache[li.id()] = fullLi;
1182 id : li.lineitem_details().map(
1183 function(item) { return item.eg_copy_id() }
1188 onresponse : function(r) {
1189 var copy = openils.Util.readResponse(r);
1190 var volId = copy.call_number();
1191 var volume = self.volCache[volId];
1193 volume = self.volCache[volId] = pcrud.retrieve('acn', volId);
1195 self.addRealCopy(volume, copy, tabIndex++);
1203 this.addRealCopy = function(volume, copy, tabIndex) {
1204 var row = this.realCopiesRow.cloneNode(true);
1205 this.realCopyList.push(copy);
1209 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1212 var isvol = (field == 'owning_lib' || field == 'label');
1213 var widget = new openils.widget.AutoFieldWidget({
1215 fmObject : isvol ? volume : copy,
1216 parentNode : nodeByName(field, row),
1217 readOnly : (field != 'barcode'),
1220 var widgetDrawn = null;
1222 if(field == 'barcode') {
1224 widgetDrawn = function(w, ww) {
1225 var node = w.domNode;
1226 node.setAttribute('tabindex', ''+tabIndex);
1228 // on enter, select the next barcode input
1229 dojo.connect(w, 'onKeyDown',
1231 if(e.keyCode == dojo.keys.ENTER) {
1232 var ti = node.getAttribute('tabindex');
1233 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1234 if(nextNode) nextNode.select();
1239 dojo.connect(w, 'onChange',
1241 if(!val || val == copy.barcode()) return;
1242 copy.ischanged(true);
1248 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1253 widget.build(widgetDrawn);
1257 this.realCopiesTbody.appendChild(row);
1258 if(selectNode) selectNode.select();
1261 this.saveRealCopies = function() {
1262 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1263 progressDialog.show(true);
1264 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1265 pcrud.update(list, {oncomplete: function() {
1266 progressDialog.hide();