</a>
</span>
</td>
+ <td style='white-space:nowrap;'>
+ <a id='acq-inline-copies-toggle'
+ href='javascript:;'>✓</a>[% l('Expand') %]
+ </td>
<td>[% l('Items') %]</td>
<td>[% l('Notes') %]</td>
<td>[% l('Actions') %]</td>
</tbody>
</table>
</td>
+ <td>
+ <a name='expand_inline_copies'
+ href='javascript:;'>[% l('Expand') %]</a>
+ </td>
<td><a title='FOOOBAR' name='copieslink' href='javascript:void(0);'>[% l('Copies([_1])', '<span name="count">0</span>') %]</a></td>
<td>
<a name='noteslink' href='javascript:void(0);'>[% l('Notes([_1])', '<span name="notes_count">0</span>') %]</a><span name="notes_alert_flag"></span>
<td><span name='li_state'></span></td>
<td><input type='text' size='8' name='price'/></td>
</tr>
+ <tr id='acq-inline-copies-row' class='acq-inline-copies-row'>
+ <td colspan='0'>
+ <table class='acq-li-inline-copies-table'>
+ <thead>
+ <tr>
+ <th>[% l('Branch') %]</th>
+ <th>[% l('Barcode') %]</th>
+ <th>[% l('Callnumber') %]</th>
+ <th>[% l('Fund') %]</th>
+ <th>[% l('Copy Location') %]</th>
+ <th>[% l('Circ Modifier') %]</th>
+ <th>[% l('Collection Code') %]</th>
+ <th>[% l('Note') %]</th>
+ </tr>
+ </thead>
+ <tbody name='acq-li-inline-copies-tbody'>
+ <tr name='acq-li-inline-copies-template'>
+ <td><div name='owning_lib'></div></td>
+ <td><div name='barcode'></div></td>
+ <td><div name='cn_label'></div></td>
+ <td><div name='fund'></div></td>
+ <td><div name='location'></div></td>
+ <td><div name='circ_modifier'></div></td>
+ <td><div name='collection_code'></div></td>
+ <td><div name='note'></div></td>
+ </tr>
+ <tr name='acq-li-inline-copies-none'>
+ <td colspan='0'>[% l('No Copies') %]</td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
</tbody>
</table>
</div>
this.focusLineitem = new openils.CGI().param('focus_li');
+ // capture the inline copy display wrapper and row template
+ this.inlineCopyContainer =
+ this.tbody.removeChild(dojo.byId('acq-inline-copies-row'));
+ var tb = dojo.query(
+ '[name=acq-li-inline-copies-tbody]', this.inlineCopyContainer)[0];
+ this.inlineCopyTemplate = tb.removeChild(
+ dojo.query('[name=acq-li-inline-copies-template]', tb)[0]);
+ this.inlineNoCopies = tb.removeChild(
+ dojo.query('[name=acq-li-inline-copies-none]', tb)[0]);
+
+ // list of LI IDs that should be refreshed at next display time
+ this.inlineCopiesNeedingRefresh = [];
+
dojo.byId("acq-lit-li-actions-selector").onchange = function() {
self.applySelectedLiAction(this.options[this.selectedIndex].value);
this.selectedIndex = 0;
dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
+ dojo.byId('acq-inline-copies-toggle').onclick = function(){self.toggleInlineCopies()};
dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
case 'list':
openils.Util.show('acq-lit-table-div');
this.focusLi();
+ this.refreshInlineCopies();
break;
case 'info':
openils.Util.show('acq-lit-info-div');
dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
+ dojo.query('[name=expand_inline_copies]', row)[0].onclick =
+ function() {self.drawInlineCopies(li.id())};
this.drawOrderIdentSelector(li, row);
);
};
+ this.toggleInlineCopies = function() {
+ // if any inline copies are not displayed,
+ // display them all otherwise, hide them all.
+
+ var displayAll = false;
+
+ for (var liId in this.liCache) {
+ if (!this.inlineCopiesVisible(liId)) {
+ displayAll = true;
+ break;
+ }
+ }
+
+ for (var liId in this.liCache) {
+ var row = dojo.byId('acq-inline-copies-row-' + liId);
+ if (displayAll) {
+ if (!row || row._hidden) {
+ this.drawInlineCopies(liId);
+ }
+ } else { // hide all
+ if (row) {
+ // drawInlineCopies() on a visible row will hide it.
+ this.drawInlineCopies(liId);
+ }
+ }
+ }
+
+ };
+
+ this.inlineCopiesVisible = function(liId) {
+ var row = dojo.byId('acq-inline-copies-row-' + liId);
+ return (row && !row._hidden);
+ }
+
+ this.refreshInlineCopies = function(all, reFetch) {
+ var self = this;
+ var liIds = this.inlineCopiesNeedingRefresh;
+ if (all) liIds = openils.Util.objectProperties(liCache);
+ liIds.forEach(function(liId) {
+ if (self.inlineCopiesVisible(liId)) {
+ self.drawInlineCopies(liId, reFetch); // hide
+ self.drawInlineCopies(liId, reFetch); // re-draw
+ }
+ });
+ };
+
+ // draw inline copy table. if the table is
+ // already visible, hide the table as-is
+ // reFetch forces a retrieval of the lineitem and
+ // copies from the server. otherwise the locally
+ // cached version of each is used.
+ this.drawInlineCopies = function(liId, reFetch) {
+ var self = this;
+
+ // find or create the row where the inline copies table will live
+ var containerRow = dojo.byId('acq-inline-copies-row-' + liId);
+ var liRow = dojo.query('[li=' + liId + ']')[0];
+
+ if (!containerRow) {
+
+ // build the inline copies container row and add it to
+ // the DOM directly after the primary lineitem row
+
+ containerRow = self.inlineCopyContainer.cloneNode(true);
+ containerRow.id = 'acq-inline-copies-row-' + liId;
+
+ if (liRow.nextSibling) {
+ self.tbody.insertBefore(containerRow, liRow.nextSibling);
+ } else {
+ self.tbody.appendChild(containerRow);
+ }
+
+ } else {
+
+ // toggle the visible state
+ containerRow._hidden = !containerRow._hidden;
+ openils.Util.toggle(containerRow, 'table-row');
+
+ if (containerRow._hidden) return; // hide only
+ }
+
+ var handler = function(li) {
+
+ var tbody = dojo.query(
+ '[name=acq-li-inline-copies-tbody]',
+ containerRow)[0];
+
+ // reset the table before adding copy rows
+ while (tbody.childNodes[0])
+ tbody.removeChild(tbody.childNodes[0]);
+
+ if(li.lineitem_details().length == 0) {
+ tbody.appendChild(
+ self.inlineNoCopies.cloneNode(true));
+ return; // no copies to show
+ }
+
+ // add a row to the inline copy table for each copy
+ dojo.forEach(li.lineitem_details(),
+ function(copy) {
+ var row = self.inlineCopyTemplate.cloneNode(true);
+ tbody.appendChild(row);
+ self.addInlineCopy(li, copy, row);
+ }
+ );
+ };
+
+ this._fetchLineitem(liId, handler, reFetch);
+ };
+
+ /** Draw read-only copy widgets for inline copies */
+ this.addInlineCopy = function(li, copy, row) {
+
+ var self = this;
+ dojo.forEach(liDetailFields,
+ function(field) {
+
+ var widget = new openils.widget.AutoFieldWidget({
+ fmObject : copy,
+ fmField : field,
+ labelFormat : (field == 'fund') ? fundLabelFormat : null,
+ searchFormat : (field == 'fund') ? fundSearchFormat : null,
+ dijitArgs: {"labelType": (field == 'fund') ? "html" : null},
+ fmClass : 'acqlid',
+ parentNode : dojo.query('[name=' + field + ']', row)[0],
+ readOnly : true,
+ });
+
+ widget.build();
+ }
+ );
+ };
+
/* For a given list of lineitem ids, build a list of full lineitems
* re-using the fetching logic that is otherwise typical to use in this
* module.
);
this.virtDfaCounts = {};
}
- }
+
+ if (this.inlineCopiesNeedingRefresh.indexOf(liId) < 0)
+ this.inlineCopiesNeedingRefresh.push(liId);
+ };
this._updateCreatePoPrepayCheckbox = function(prepay) {
var prepay = openils.Util.isTrue(prepay);