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) {
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'],
203 {params: [this.authtoken, li.purchase_order()]});
205 openils.Util.show(nodeByName('po', row), 'inline');
206 var link = nodeByName('po_link', row);
207 link.setAttribute('href', oilsBasePath + '/acq/po/view/' + li.purchase_order());
208 link.innerHTML = 'PO: ' + po.name(); // TODO i18n
212 // show which picklist this lineitem is a member of
213 if(li.picklist() && this.isPO) {
215 this.plCache[li.picklist()] =
216 this.plCache[li.picklist()] ||
217 fieldmapper.standardRequest(
218 ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
219 {params: [this.authtoken, li.picklist()]});
221 openils.Util.show(nodeByName('pl', row), 'inline');
222 var link = nodeByName('pl_link', row);
223 link.setAttribute('href', oilsBasePath + '/acq/picklist/view/' + li.picklist());
224 link.innerHTML = 'PL: '+pl.name(); // TODO i18n
228 var countNode = nodeByName('count', row);
229 countNode.innerHTML = li.item_count() || 0;
230 countNode.id = 'acq-lit-copy-count-label-' + li.id();
233 nodeByName('li_state', row).innerHTML = li.state(); // TODO i18n state labels
234 openils.Util.addCSSClass(row, 'oils-acq-li-state-' + li.state());
237 var priceInput = dojo.query('[name=price]', row)[0];
238 var priceData = liWrapper.getPrice();
239 priceInput.value = (priceData) ? priceData.price : '';
240 priceInput.onchange = function() { self.updateLiPrice(priceInput, li) };
242 var recv_link = dojo.query('[name=receive_link]', row)[0];
244 if(li.state() == 'on-order') {
245 recv_link.onclick = function() {
247 openils.Util.hide(recv_link)
250 openils.Util.hide(recv_link);
253 // TODO we should allow editing before receipt, in which case the
254 // test should be "if 1 or more real (acp) copies exist
255 if(li.state() == 'received') {
256 var real_copies_link = dojo.query('[name=real_copies_link]', row)[0];
257 openils.Util.show(real_copies_link);
258 real_copies_link.onclick = function() {
259 self.showRealCopies(li);
263 self.tbody.appendChild(row);
264 self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
268 * Draws and shows the lineitem notes pane
270 this.drawLiNotes = function(li) {
274 li.lineitem_notes().sort(
276 if(a.edit_time() < b.edit_time()) return 1;
282 while(this.liNotesTbody.childNodes[0])
283 this.liNotesTbody.removeChild(this.liNotesTbody.childNodes[0]);
286 acqLitCreateLiNoteSubmit.onClick = function() {
287 var value = acqLitCreateNoteText.attr('value');
289 var note = new fieldmapper.acqlin();
292 note.lineitem(li.id());
293 self.updateLiNotes(li, note);
296 dojo.byId('acq-lit-notes-save-button').onclick = function() {
297 self.updateLiNotes(li);
300 dojo.forEach(li.lineitem_notes(), function(note) { self.addLiNote(li, note) });
304 * Draws a single lineitem note in the notes pane
306 this.addLiNote = function(li, note) {
307 if(note.isdeleted()) return;
309 var row = self.liNotesRow.cloneNode(true);
310 dojo.query('[name=value]', row)[0].innerHTML = note.value();
312 dojo.query('[name=delete]', row)[0].onclick = function() {
313 note.isdeleted(true);
314 self.liNotesTbody.removeChild(row);
317 if(note.edit_time()) {
318 dojo.query('[name=edit_time]', row)[0].innerHTML =
319 dojo.date.locale.format(
320 dojo.date.stamp.fromISOString(note.edit_time()),
321 {formatLength:'short'});
324 self.liNotesTbody.appendChild(row);
328 * Updates any new/changed/deleted notes on the server
330 this.updateLiNotes = function(li, newNote) {
336 notes = li.lineitem_notes().filter(
338 if(note.ischanged() || note.isnew() || note.isdeleted())
344 if(notes.length == 0) return;
345 progressDialog.show();
347 fieldmapper.standardRequest(
348 ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
350 params : [this.authtoken, notes],
351 onresponse : function(r) {
352 var resp = openils.Util.readResponse(r);
357 // remove the old changed notes
359 dojo.forEach(li.lineitem_notes(),
361 if(!(note.ischanged() || note.isnew() || note.isdeleted()))
365 li.lineitem_notes(list);
368 progressDialog.hide();
369 self.drawLiNotes(li);
373 progressDialog.update(resp);
374 var newnote = resp.note;
376 if(!newnote.isdeleted()) {
377 newnote.isnew(false);
378 newnote.ischanged(false);
379 li.lineitem_notes().push(newnote);
386 this.updateLiPrice = function(input, li) {
388 var price = input.value;
389 var liWrapper = new openils.acq.Lineitem({lineitem:li});
390 var oldPrice = liWrapper.getPrice() || null;
392 if(oldPrice) oldPrice = oldPrice.price;
393 if(price == oldPrice) return;
395 fieldmapper.standardRequest(
396 ['open-ils.acq', 'open-ils.acq.lineitem.price.set'],
398 params : [this.authtoken, li.id(), price],
399 oncomplete : function(r) {
400 openils.Util.readResponse(r);
406 this.removeLineitem = function(liId) {
407 this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
408 delete this.liCache[liId];
409 //selected.push(self.liCache[i.parentNode.parentNode.getAttribute('li')]);
412 this.drawInfo = function(liId) {
414 openils.acq.Lineitem.fetchAttrDefs(
416 self._fetchLineitem(liId, function(li){self._drawInfo(li);});
421 this._fetchLineitem = function(liId, handler) {
423 var li = this.liCache[liId];
424 if(li && li.marc() && li.lineitem_details())
427 fieldmapper.standardRequest(
428 ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
431 params: [self.authtoken, liId, {
433 flesh_li_details: true,
434 flesh_fund_debit: true }],
436 oncomplete: function(r) {
437 var li = openils.Util.readResponse(r);
444 this._drawInfo = function(li) {
446 acqLitEditOrderMarc.onClick = function() { self.editOrderMarc(li); }
449 openils.Util.hide('acq-lit-marc-order-record-label');
450 openils.Util.hide(acqLitEditOrderMarc.domNode);
451 openils.Util.show('acq-lit-marc-real-record-label');
453 openils.Util.show('acq-lit-marc-order-record-label');
454 openils.Util.show(acqLitEditOrderMarc.domNode);
455 openils.Util.hide('acq-lit-marc-real-record-label');
458 this.drawMarcHTML(li);
459 this.infoTbody = dojo.byId('acq-lit-info-tbody');
462 this.infoRow = this.infoTbody.removeChild(dojo.byId('acq-lit-info-row'));
463 while(this.infoTbody.childNodes[0])
464 this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
466 for(var i = 0; i < li.attributes().length; i++) {
467 var attr = li.attributes()[i];
468 var row = this.infoRow.cloneNode(true);
470 var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
471 var name = openils.acq.Lineitem.attrDefs[type].filter(
473 return (a.code() == attr.attr_name());
475 ).pop().description();
477 dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
478 dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
479 this.infoTbody.appendChild(row);
483 openils.Util.show('acq-lit-info-cat-link');
484 var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
486 if(openils.XUL.isXUL()) {
488 var makeRecTab = function() {
491 {tab_name: localeStrings.XUL_RECORD_DETAIL_PAGE, browser:false},
494 show_nav_buttons : true,
495 show_print_button : true,
496 opac_url : xulG.url_prefix(xulG.urls.opac_rdetail + '?r=' + li.eg_bib_id())
500 link.setAttribute('href', 'javascript:void(0);');
501 link.onclick = makeRecTab;
504 var href = link.getAttribute('href');
506 link.setAttribute('href', href + li.eg_bib_id());
509 openils.Util.hide('acq-lit-info-cat-link');
513 this.drawMarcHTML = function(li) {
514 var params = [null, true, li.marc()];
516 params = [li.eg_bib_id(), true];
518 fieldmapper.standardRequest(
519 ['open-ils.search', 'open-ils.search.biblio.record.html'],
522 oncomplete: function(r) {
523 dojo.byId('acq-lit-marc-div').innerHTML =
524 openils.Util.readResponse(r);
530 this.drawCopies = function(liId) {
534 this.copyWidgetCache = {};
536 acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
537 acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
538 acqLitCopyCountInput.attr('value', '0');
540 while(this.copyTbody.childNodes[0])
541 this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
543 this._drawBatchCopyWidgets();
545 this._fetchDistribFormulas(
547 openils.acq.Lineitem.fetchAttrDefs(
549 self._fetchLineitem(liId, function(li){self._drawCopies(li);});
557 * Insert a new row into the distribution formula selection form
559 this._addDistribFormulaRow = function() {
562 if(!self.distribFormulaStore) {
563 // no formulas, hide the form
564 openils.Util.hide('acq-lit-distrib-formula-tbody');
568 if(!this.distribFormulaTemplate)
569 this.distribFormulaTemplate =
570 dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
572 var row = dojo.byId('acq-lit-distrib-formula-tbody').appendChild(this.distribFormulaTemplate.cloneNode(true));
574 var selector = new dijit.form.FilteringSelect(
575 {store : self.distribFormulaStore},
576 nodeByName('selector', row)
579 var apply = new dijit.form.Button(
580 {label : 'Apply'}, // TODO i18n
581 nodeByName('set_button', row)
584 var release = new dijit.form.Button(
585 {label : 'Release', disabled: true}, // TODO i18n
586 nodeByName('rel_button', row)
589 dojo.connect(apply, 'onClick',
591 var form_id = selector.attr('value');
593 apply.attr('disabled', true);
594 release.attr('disabled', false);
595 self._applyDistribFormula(form_id);
599 dojo.connect(release, 'onClick',
601 apply.attr('disabled', false);
602 release.attr('disabled', true);
608 * Applies a distrib formula to the current set of copies
610 this._applyDistribFormula = function(formula) {
613 formula = this.distribForms.filter(
615 return form.id() == formula;
619 var copyRows = dojo.query('tr', self.copyTbody);
621 for(var rowIndex = 0; rowIndex < copyRows.length; rowIndex++) {
623 var row = copyRows[rowIndex];
624 var copy_id = row.getAttribute('copy_id');
625 var copyWidgets = this.copyWidgetCache[copy_id];
629 // find the correct entry for the current row
630 dojo.forEach(formula.entries(),
633 entryIndex += e.item_count();
634 if(entryIndex > rowIndex)
642 //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" +
643 // entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
646 ['owning_lib', 'location'],
649 copyWidgets[field].attr('value', (entry[field]()));
656 this._fetchDistribFormulas = function(onload) {
657 if(this.distribForms) {
661 fieldmapper.standardRequest(
662 ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve.atomic'],
664 params: [openils.User.authtoken],
665 oncomplete: function(r) {
666 self.distribForms = openils.Util.readResponse(r);
667 if(!self.distribForms || self.distribForms.length == 0) {
668 self.distribForms = [];
671 self.distribFormulaStore =
672 new dojo.data.ItemFileReadStore(
673 {data:acqdf.toStoreData(self.distribForms)});
674 self._addDistribFormulaRow();
682 this._drawBatchCopyWidgets = function() {
683 var row = this.copyBatchRow;
684 dojo.forEach(liDetailBatchFields,
686 if(self.copyBatchRowDrawn) {
687 self.copyBatchWidgets[field].attr('value', null);
689 var widget = new openils.widget.AutoFieldWidget({
692 parentNode : dojo.query('[name='+field+']', row)[0],
693 orgLimitPerms : ['CREATE_PICKLIST'],
694 dijitArgs : {required:false},
699 self.copyBatchWidgets[field] = w;
705 this.copyBatchRowDrawn = true;
708 this.batchCopyUpdate = function() {
710 for(var k in this.copyWidgetCache) {
711 var cache = this.copyWidgetCache[k];
712 dojo.forEach(liDetailBatchFields, function(f) {
713 var newval = self.copyBatchWidgets[f].attr('value');
714 if(newval) cache[f].attr('value', newval);
719 this._drawCopies = function(li) {
722 // this button sets the total number of copies for a given lineitem
723 acqLitAddCopyCount.onClick = function() {
724 var count = acqLitCopyCountInput.attr('value');
727 while(self.copyCount() < count)
730 // delete rows if necessary
731 var diff = self.copyCount() - count;
733 var rows = dojo.query('tr', self.copyTbody).reverse().slice(0, diff);
734 if(confirm(dojo.string.substitute(localeStrings.DELETE_LI_COPIES_CONFIRM, [diff]))) {
735 dojo.forEach(rows, function(row) {self.deleteCopy(row); });
737 acqLitCopyCountInput.attr('value', self.copyCount()+'');
743 if(li.lineitem_details().length > 0) {
744 dojo.forEach(li.lineitem_details(),
746 self.addCopy(li, copy);
754 this.copyCount = function() {
756 for(var id in this.copyCache) {
757 if(!this.copyCache[id].isdeleted())
763 this.virtCopyId = -1;
764 this.addCopy = function(li, copy) {
765 var row = this.copyRow.cloneNode(true);
766 this.copyTbody.appendChild(row);
770 copy = new fieldmapper.acqlid();
772 copy.id(this.virtCopyId--);
773 copy.lineitem(li.id());
776 this.copyCache[copy.id()] = copy;
777 row.setAttribute('copy_id', copy.id());
778 self.copyWidgetCache[copy.id()] = {};
780 acqLitCopyCountInput.attr('value', self.copyCount()+'');
782 dojo.forEach(liDetailFields,
784 var widget = new openils.widget.AutoFieldWidget({
788 parentNode : dojo.query('[name='+field+']', row)[0],
789 orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
790 readOnly : Boolean(copy.eg_copy_id())
793 // make sure we capture the value from any async widgets
795 copy[field](ww.getFormattedValue())
796 self.copyWidgetCache[copy.id()][field] = w;
799 dojo.connect(widget.widget, 'onChange',
801 if(copy.isnew() || val != copy[field]()) {
802 // prevent setting ischanged() automatically on widget load for existing copies
803 copy[field](widget.getFormattedValue())
804 copy.ischanged(true);
811 var recv_link = dojo.query('[name=receive]', row)[0];
812 if(copy.recv_time()) {
813 openils.Util.hide(recv_link);
815 recv_link.onclick = function() {
816 self.receiveLid(copy);
817 openils.Util.hide(recv_link);
822 openils.Util.hide(dojo.query('[name=delete]', row)[0].parentNode);
824 dojo.query('[name=delete]', row)[0].onclick =
825 function() { self.deleteCopy(row) };
829 this.deleteCopy = function(row) {
830 var copy = this.copyCache[row.getAttribute('copy_id')];
831 copy.isdeleted(true);
833 delete this.copyCache[copy.id()];
834 this.copyTbody.removeChild(row);
837 this.saveCopyChanges = function(liId) {
842 openils.Util.show('acq-lit-update-copies-progress');
845 for(var id in this.copyCache) {
846 var c = this.copyCache[id];
847 if(!c.isdeleted()) total++;
848 if(c.isnew() || c.ischanged() || c.isdeleted()) {
849 if(c.id() < 0) c.id(null);
854 dojo.byId('acq-lit-copy-count-label-' + liId).innerHTML = total;
856 if(copies.length == 0)
859 fieldmapper.standardRequest(
860 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
862 params: [openils.User.authtoken, copies],
863 onresponse: function(r) {
864 var res = openils.Util.readResponse(r);
865 litUpdateCopiesProgress.update(res);
867 oncomplete: function() {
868 openils.Util.hide('acq-lit-update-copies-progress');
869 self.drawCopies(liId);
875 this.applySelectedLiAction = function(action) {
879 case 'delete_selected':
880 this._deleteLiList(self.getSelected());
885 if(!this.createPoProviderSelector) {
886 var widget = new openils.widget.AutoFieldWidget({
887 fmField : 'provider',
889 parentNode : dojo.byId('acq-lit-po-provider'),
892 function(w) { self.createPoProviderSelector = w; }
896 if(!this.createPoAgencySelector) {
897 var widget = new openils.widget.AutoFieldWidget({
898 fmField : 'ordering_agency',
900 parentNode : dojo.byId('acq-lit-po-agency'),
901 orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
904 function(w) { self.createPoAgencySelector = w; }
909 acqLitPoCreateDialog.show();
912 case 'save_picklist':
913 this._loadPLSelect();
914 acqLitSavePlDialog.show();
917 case 'selector_ready':
919 acqLitChangeLiStateDialog.attr('state', action.replace('_', '-'));
920 acqLitChangeLiStateDialog.show();
931 case 'rollback_receive_po':
932 this.rollbackPoReceive();
935 case 'create_assets':
939 case 'add_brief_record':
941 location.href = oilsBasePath + '/acq/picklist/brief_record?po=' + this.isPO;
943 location.href = oilsBasePath + '/acq/picklist/brief_record?pl=' + this.isPL;
947 this.createAssets = function() {
948 if(!this.isPO) return;
949 if(!confirm(localeStrings.CREATE_PO_ASSETS_CONFIRM)) return;
950 this.show('acq-lit-progress-numbers');
952 fieldmapper.standardRequest(
953 ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
955 params: [this.authtoken, this.isPO],
956 onresponse: function(r) {
957 var resp = openils.Util.readResponse(r);
958 self._updateProgressNumbers(resp, true);
964 this.printPO = function() {
965 if(!this.isPO) return;
966 progressDialog.show(true);
967 fieldmapper.standardRequest(
968 ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
970 params: [this.authtoken, this.isPO, 'html'],
971 oncomplete: function(r) {
972 progressDialog.hide();
973 var evt = openils.Util.readResponse(r);
974 if(evt && evt.template_output()) {
975 win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
976 win.document.body.innerHTML = evt.template_output().data();
984 this.receivePO = function() {
985 if(!this.isPO) return;
986 this.show('acq-lit-progress-numbers');
988 fieldmapper.standardRequest(
989 ['open-ils.acq', 'open-ils.acq.purchase_order.receive'],
991 params: [this.authtoken, this.isPO],
992 onresponse : function(r) {
993 var resp = openils.Util.readResponse(r);
994 self._updateProgressNumbers(resp, true);
1000 this.receiveLi = function(li) {
1001 if(!this.isPO) return;
1002 progressDialog.show(true);
1003 fieldmapper.standardRequest(
1004 ['open-ils.acq', 'open-ils.acq.lineitem.receive'],
1006 params: [this.authtoken, li.id()],
1007 onresponse : function(r) {
1008 var resp = openils.Util.readResponse(r);
1009 progressDialog.hide();
1015 this.receiveLid = function(li) {
1016 if(!this.isPO) return;
1017 progressDialog.show(true);
1018 fieldmapper.standardRequest(
1019 ['open-ils.acq', 'open-ils.acq.lineitem_detail.receive'],
1021 params: [this.authtoken, li.id()],
1022 onresponse : function(r) {
1023 var resp = openils.Util.readResponse(r);
1024 progressDialog.hide();
1030 this.rollbackPoReceive = function() {
1031 if(!this.isPO) return;
1032 if(!confirm(localeStrings.ROLLBACK_PO_RECEIVE_CONFIRM)) return;
1033 this.show('acq-lit-progress-numbers');
1035 fieldmapper.standardRequest(
1036 ['open-ils.acq', 'open-ils.acq.purchase_order.receive.rollback'],
1038 params: [this.authtoken, this.isPO],
1039 onresponse : function(r) {
1040 var resp = openils.Util.readResponse(r);
1041 self._updateProgressNumbers(resp, true);
1047 this._updateProgressNumbers = function(resp, reloadOnComplete) {
1049 dojo.byId('acq-pl-lit-li-processed').innerHTML = resp.li;
1050 dojo.byId('acq-pl-lit-lid-processed').innerHTML = resp.lid;
1051 dojo.byId('acq-pl-lit-debits-processed').innerHTML = resp.debits_accrued;
1052 dojo.byId('acq-pl-lit-bibs-processed').innerHTML = resp.bibs;
1053 dojo.byId('acq-pl-lit-indexed-processed').innerHTML = resp.indexed;
1054 dojo.byId('acq-pl-lit-copies-processed').innerHTML = resp.copies;
1055 if(resp.complete && reloadOnComplete)
1056 location.href = location.href;
1060 this._createPO = function(fields) {
1061 this.show('acq-lit-progress-numbers');
1062 var po = new fieldmapper.acqpo();
1063 po.provider(this.createPoProviderSelector.attr('value'));
1064 po.ordering_agency(this.createPoAgencySelector.attr('value'));
1066 var selected = this.getSelected( (fields.create_from == 'all') );
1067 if(selected.length == 0) return;
1069 var max = selected.length * 3;
1072 fieldmapper.standardRequest(
1073 ['open-ils.acq', 'open-ils.acq.purchase_order.create'],
1076 openils.User.authtoken,
1079 lineitems : selected.map(function(li) { return li.id() }),
1080 create_assets : fields.create_assets[0],
1084 onresponse : function(r) {
1085 var resp = openils.Util.readResponse(r);
1086 self._updateProgressNumbers(resp);
1088 location.href = oilsBasePath + '/eg/acq/po/view/' + resp.purchase_order.id();
1094 this._deleteLiList = function(list, idx) {
1095 if(idx == null) idx = 0;
1096 if(idx >= list.length) return;
1097 var liId = list[idx].id();
1098 fieldmapper.standardRequest(
1099 ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
1101 params: [openils.User.authtoken, liId],
1102 oncomplete: function(r) {
1103 self.removeLineitem(liId);
1104 self._deleteLiList(list, ++idx);
1110 this.editOrderMarc = function(li) {
1112 /* To run in Firefox directly, must set signed.applets.codebase_principal_support
1113 to true in about:config */
1115 if(!openils.XUL.enableXPConnect()) return;
1117 if(openils.XUL.isXUL()) {
1118 win = window.open('/xul/' + openils.XUL.buildId() + '/server/cat/marcedit.xul');
1120 win = window.open('/xul/server/cat/marcedit.xul');
1124 record : {marc : li.marc()},
1126 label: 'Save Record', // XXX I18N
1127 func: function(xmlString) {
1129 fieldmapper.standardRequest(
1130 ['open-ils.acq', 'open-ils.acq.lineitem.update'],
1132 params: [openils.User.authtoken, li],
1133 oncomplete: function(r) {
1134 openils.Util.readResponse(r);
1136 self.drawInfo(li.id())
1145 this._savePl = function(values) {
1147 var selected = this.getSelected( (values.which == 'all') );
1148 openils.Util.show('acq-lit-generic-progress');
1150 if(values.new_name) {
1151 openils.acq.Picklist.create(
1152 {name: values.new_name},
1154 self._updateLiList(id, selected, 0,
1156 location.href = oilsBasePath + '/eg/acq/picklist/view/' + id;
1160 } else if(values.existing_pl) {
1161 // update lineitems to use an existing picklist
1162 self._updateLiList(values.existing_pl, selected, 0,
1164 location.href = oilsBasePath + '/eg/acq/picklist/view/' + values.existing_pl;
1169 this._updateLiState = function(values, state) {
1171 var selected = this.getSelected( (values.which == 'all') );
1172 if(!selected.length) return;
1173 dojo.forEach(selected, function(li) {li.state(state);});
1174 self._updateLiList(null, selected, 0,
1175 // TODO consider inline updates for efficiency
1176 function() { location.href = location.href }
1180 this._updateLiList = function(pl, list, idx, oncomplete) {
1181 if(idx >= list.length) return oncomplete();
1183 if(pl != null) li.picklist(pl);
1184 litGenericProgress.update({maximum: list.length, progress: idx});
1185 new openils.acq.Lineitem({lineitem:li}).update(
1187 self._updateLiList(pl, list, ++idx, oncomplete);
1192 this._loadPLSelect = function() {
1193 if(this._plSelectLoaded) return;
1195 function handleResponse(r) {
1196 plList.push(r.recv().content());
1198 var method = 'open-ils.acq.picklist.user.retrieve';
1199 fieldmapper.standardRequest(
1200 ['open-ils.acq', method],
1202 params: [this.authtoken],
1203 onresponse: handleResponse,
1204 oncomplete: function() {
1205 self._plSelectLoaded = true;
1206 acqLitAddExistingSelect.store =
1207 new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
1208 acqLitAddExistingSelect.setValue();
1214 // grab the li-details for this lineitem, grab the linked copies and volumes, add them to the table
1215 this.showRealCopies = function(li) {
1216 while(this.realCopiesTbody.childNodes[0])
1217 this.realCopiesTbody.removeChild(this.realCopiesTbody.childNodes[0]);
1218 this.show('real-copies');
1220 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1221 this.realCopyList = [];
1223 var tabIndex = 1000;
1226 acqLitSaveRealCopies.onClick = function() {
1227 self.saveRealCopies();
1230 this._fetchLineitem(li.id(),
1232 li = self.liCache[li.id()] = fullLi;
1236 id : li.lineitem_details().map(
1237 function(item) { return item.eg_copy_id() }
1242 onresponse : function(r) {
1243 var copy = openils.Util.readResponse(r);
1244 var volId = copy.call_number();
1245 var volume = self.volCache[volId];
1247 volume = self.volCache[volId] = pcrud.retrieve('acn', volId);
1249 self.addRealCopy(volume, copy, tabIndex++);
1257 this.addRealCopy = function(volume, copy, tabIndex) {
1258 var row = this.realCopiesRow.cloneNode(true);
1259 this.realCopyList.push(copy);
1263 ['owning_lib', 'location', 'circ_modifier', 'label', 'barcode'],
1266 var isvol = (field == 'owning_lib' || field == 'label');
1267 var widget = new openils.widget.AutoFieldWidget({
1269 fmObject : isvol ? volume : copy,
1270 parentNode : nodeByName(field, row),
1271 readOnly : (field != 'barcode'),
1274 var widgetDrawn = null;
1276 if(field == 'barcode') {
1278 widgetDrawn = function(w, ww) {
1279 var node = w.domNode;
1280 node.setAttribute('tabindex', ''+tabIndex);
1282 // on enter, select the next barcode input
1283 dojo.connect(w, 'onKeyDown',
1285 if(e.keyCode == dojo.keys.ENTER) {
1286 var ti = node.getAttribute('tabindex');
1287 var nextNode = dojo.query('[tabindex=' + String(Number(ti) + 1) + ']', self.realCopiesTbody)[0];
1288 if(nextNode) nextNode.select();
1293 dojo.connect(w, 'onChange',
1295 if(!val || val == copy.barcode()) return;
1296 copy.ischanged(true);
1302 if(self.realCopiesTbody.getElementsByTagName('TR').length == 0)
1307 widget.build(widgetDrawn);
1311 this.realCopiesTbody.appendChild(row);
1312 if(selectNode) selectNode.select();
1315 this.saveRealCopies = function() {
1316 var pcrud = new openils.PermaCrud({authtoken : this.authtoken});
1317 progressDialog.show(true);
1318 var list = this.realCopyList.filter(function(copy) { return copy.ischanged(); });
1319 pcrud.update(list, {oncomplete: function() {
1320 progressDialog.hide();