push(@{$flesh->{flesh_fields}->{jub}}, 'attributes') if $$options{flesh_attrs};
}
- my $li = $e->retrieve_acq_lineitem([$li_id, $flesh]);
+ my $li = $e->retrieve_acq_lineitem([$li_id, $flesh]) or return $e->die_event;
if($$options{flesh_li_details}) {
my $ops = {
};
push(@{$ops->{flesh_fields}->{acqlid}}, 'fund') if $$options{flesh_fund};
push(@{$ops->{flesh_fields}->{acqlid}}, 'fund_debit') if $$options{flesh_fund_debit};
- my $details = $e->search_acq_lineitem_detail([{lineitem => $li_id}, $ops]);
- $li->lineitem_details($details);
- $li->item_count(scalar(@$details));
+ if (my $details = $e->search_acq_lineitem_detail([{lineitem => $li_id}, $ops])) {
+ $li->lineitem_details($details);
+ $li->item_count(scalar(@$details));
+ } else {
+ $li->lineitem_count(0);
+ }
} else {
my $details = $e->search_acq_lineitem_detail({lineitem => $li_id}, {idlist=>1});
$li->item_count(scalar(@$details));
/
);
+__PACKAGE__->register_method (
+ method => 'lineitems_related_by_bib',
+ api_name => 'open-ils.acq.lineitems_for_bib.by_lineitem_id.count',
+ stream => 1,
+ signature => q/See open-ils.acq.lineitems_for_bib.by_lineitem_id. This version returns numbers of lineitems only (XXX may count lineitems we don't actually have permission to retrieve)/
+);
+
sub lineitems_related_by_bib {
my($self, $conn, $auth, $id_value, $options) = @_;
my $e = new_editor(authtoken => $auth);
my $perm_orgs = $U->user_has_work_perm_at($e, 'VIEW_PURCHASE_ORDER', {descendants =>1}, $e->requestor->id);
- my $id_field;
- if ($self->api_name =~ /by_bib_id/) {
- $id_field = 'eg_bib_id';
- } else {
- $id_field = 'id';
+ if ($self->api_name =~ /by_lineitem_id/) {
+ my $orig = retrieve_lineitem($self, $conn, $auth, $id_value) or
+ return $e->die_event;
+ $id_value = $orig->eg_bib_id;
}
my $query = {
"select"=>{"jub"=>["id"]},
"from"=>{"jub"=>"acqpo"},
"where"=>{
- $id_field=>$id_value,
+ "eg_bib_id"=>$id_value,
"+acqpo"=>{
"ordering_agency"=>{
"in"=>$perm_orgs
}
my $results = $e->json_query($query);
- for my $result (@$results) {
- my $lineitem = $e->retrieve_acq_lineitem([
- $result->{id},
- {}
- ]);
- if (! $lineitem) { next; }
-
- my $po = OpenILS::Application::Acq::Financials::retrieve_purchase_order_impl->(
- $e,
- $lineitem->purchase_order(),
- {flesh_lineitem_count=>1,flesh_price_summary=>1}
- );
-
- if ($e->allowed( ['CREATE_PURCHASE_ORDER','VIEW_PURCHASE_ORDER'], $po->ordering_agency() )) {
- $lineitem->purchase_order( $po );
- $conn->respond($lineitem);
+ if ($self->api_name =~ /count$/) {
+ return scalar(@$results);
+ } else {
+ for my $result (@$results) {
+ # retrieve_lineitem takes care of POs and PLs and also handles
+ # options like flesh_notes and permissions checking.
+ $conn->respond(
+ retrieve_lineitem($self, $conn, $auth, $result->{"id"}, $options)
+ );
}
}
.acq-lit-po-heading td span span { padding: 0; }
.acq-lit-po-heading td span a[attr="name"] { font-weight: bold; }
#acq-lit-info-tbody td {padding:5px;}
+#acq-lit-info-related { margin-top: 10px; }
#acq-lit-li-details-table {margin-top:20px;}
#acq-lit-li-details-table td {padding:0px 3px 1px 3px;}
#acq-lit-li-details-table th {padding:0px 3px 1px 3px; font-weight:bold;}
.acq-lit-table-spacer { height:20px; }
.acq-lit-row td[name="selector"] { width:1.5em; font-weight:bold; color:blue; font-size:110%;}
-.acq-notes-menu-bar {width:99%; text-align:left; border:1px solid #aaa; margin:5px 0px 10px 0px;}
+.acq-menu-bar {width:99%; text-align:left; border:1px solid #aaa; margin:5px 0px 10px 0px;}
.acq-notes-note-row { margin: 6px 0; }
#acq-po-notes-tbody li { margin-bottom:10px; border:1px solid #aaa; -moz-border-radius: 5px 5px 5px 5px; }
#acq-po-notes-tbody td {padding: 20px 10px 20px 10px; border-bottom:2px solid #aaa;}
span[name="alert_code"] {color: #c00;padding-right: 1em;font-weight: bold;}
span[name="notes_alert_flag"] {color: #c00;font-weight: bold;font-size: 110%;margin: 0 7px;}
+#acq-related-info-tbody td {padding:5px;}
+#acq-related-mini ul { list-style-type: square; }
this.liCache = {};
this.plCache = {};
this.poCache = {};
+ this.relCache = {};
this.realDfaCache = {};
this.virtDfaCounts = {};
this.virtDfaId = -1;
self.tbody.removeChild(self.tbody.childNodes[0]);
self.selectors = [];
self.noteAcks = {};
+ self.relCache = {};
};
this.setNext = function(handler) {
}
this.drawInfo = function(liId) {
+ if (!this.relCache[liId]) {
+ fieldmapper.standardRequest(
+ [
+ "open-ils.acq",
+ "open-ils.acq.lineitems_for_bib.by_lineitem_id.count"
+ ], {
+ "async": true,
+ "params": [openils.User.authtoken, liId],
+ "onresponse": function(r) {
+ self.relCache[liId] = openils.Util.readResponse(r);
+ nodeByName(
+ "related_number", dojo.byId("acq-lit-info-related")
+ ).innerHTML = self.relCache[liId];
+ }
+ }
+ );
+ } else {
+ nodeByName(
+ "related_number", dojo.byId("acq-lit-info-related")
+ ).innerHTML = this.relCache[liId];
+ }
+
this.show('info');
openils.acq.Lineitem.fetchAttrDefs(
function() {
while(this.infoTbody.childNodes[0])
this.infoTbody.removeChild(this.infoTbody.childNodes[0]);
- for(var i = 0; i < li.attributes().length; i++) {
- var attr = li.attributes()[i];
- var row = this.infoRow.cloneNode(true);
+ if (!this._isRelatedViewer) {
+ for(var i = 0; i < li.attributes().length; i++) {
+ var attr = li.attributes()[i];
+ var row = this.infoRow.cloneNode(true);
- var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
- var name = openils.acq.Lineitem.attrDefs[type].filter(
- function(a) {
- return (a.code() == attr.attr_name());
- }
- ).pop().description();
+ var type = attr.attr_type().replace(/lineitem_(.*)_attr_definition/, '$1');
+ var name = openils.acq.Lineitem.attrDefs[type].filter(
+ function(a) {
+ return (a.code() == attr.attr_name());
+ }
+ ).pop().description();
- dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
- dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
- this.infoTbody.appendChild(row);
+ dojo.query('[name=label]', row)[0].appendChild(document.createTextNode(name));
+ dojo.query('[name=value]', row)[0].appendChild(document.createTextNode(attr.attr_value()));
+ this.infoTbody.appendChild(row);
+ }
+
+ var rel_div = dojo.byId("acq-lit-info-related");
+ nodeByName("rel_link", rel_div).href =
+ "/eg/acq/lineitem/related/" + li.id();
+ openils.Util.show(rel_div);
}
if(li.eg_bib_id()) {
+
openils.Util.show('acq-lit-info-cat-link');
var link = dojo.byId('acq-lit-info-cat-link').getElementsByTagName('a')[0];
--- /dev/null
+dojo.require("openils.acq.Lineitem");
+dojo.require("openils.Util");
+dojo.require("openils.XUL");
+
+var liTable;
+
+function attrDefByName(attr) {
+ return openils.acq.Lineitem.attrDefs[
+ attr.attr_type().replace(/lineitem_(.*)_attr_definition/, "$1")
+ ].filter(
+ function(o) { return (o.code() == attr.attr_name()); }
+ ).pop();
+}
+
+function drawLiInfo(li) {
+ var infoTbody = dojo.byId("acq-related-info-tbody");
+ var infoRow = infoTbody.removeChild(dojo.byId("acq-related-info-row"));
+
+ li.attributes().forEach(
+ function(attr) {
+ var row = dojo.clone(infoRow);
+
+ nodeByName("label", row).innerHTML =
+ attrDefByName(attr).description();
+ nodeByName("value", row).innerHTML = attr.attr_value();
+
+ infoTbody.appendChild(row);
+
+ if (["title", "author"].indexOf(attr.attr_name()) != -1) {
+ nodeByName(
+ attr.attr_name(), dojo.byId("acq-related-mini-display")
+ ).innerHTML = attr.attr_value();
+ }
+ }
+ );
+}
+
+function fetchLi() {
+ fieldmapper.standardRequest(
+ ["open-ils.acq", "open-ils.acq.lineitem.retrieve"], {
+ "async": true,
+ "params": [openils.User.authtoken, liId, {
+ "flesh_attrs": true,
+ "flesh_li_details": true,
+ "flesh_fund_debit": true
+ }],
+ "oncomplete": function(r) {
+ drawLiInfo(openils.Util.readResponse(r));
+ }
+ }
+ );
+}
+
+function hideDetails() {
+ openils.Util.show("acq-related-mini");
+ openils.Util.hide("acq-related-info-div");
+}
+
+function showDetails() {
+ openils.Util.show("acq-related-info-div");
+ openils.Util.hide("acq-related-mini");
+}
+
+function fetchRelated() {
+ fieldmapper.standardRequest(
+ ["open-ils.acq", "open-ils.acq.lineitems_for_bib.by_lineitem_id"], {
+ "async": true,
+ "params": [openils.User.authtoken, liId, {
+ "flesh_attrs": true, "flesh_notes": true
+ }],
+ "onresponse": function(r) {
+ var resp = openils.Util.readResponse(r);
+ if (resp) {
+ liTable.show("list");
+ liTable.addLineitem(resp);
+ }
+ }
+ }
+ );
+}
+function load() {
+ openils.acq.Lineitem.fetchAttrDefs(fetchLi);
+ dojo.byId("acq-related-info-back-button").onclick = hideDetails;
+ dojo.byId("acq-related-info-show-button").onclick = showDetails;
+
+ liTable = new AcqLiTable();
+ liTable.reset();
+ liTable._isRelatedViewer = true;
+
+ fetchRelated();
+}
+
+openils.Util.addOnLoad(load);
--- /dev/null
+[% which_lc = which | lower %]
+ <div id="acq-[% which_lc %]-info-div" class="hidden">
+ <div class="acq-menu-bar">
+ <div dojoType="dijit.form.Button" id="acq-[% which_lc %]-info-back-button">↖ [% IF which == "Lit" %]Return[% ELSE %]Hide[% END %]</div>
+ </div>
+ <table>
+ <tbody id="acq-[% which_lc %]-info-tbody">
+ <tr id="acq-[% which_lc %]-info-row"><td name="label"/><td name="value"/></tr>
+ </tbody>
+ </table>
+ <div style="margin-top:10px;" class="hidden" id="acq-[% which_lc %]-info-cat-link">
+ View in the <a href="/opac/en-US/skin/default/xml/rdetail.xml?r=">Catalog</a>
+ </div>
+[% IF which == "Lit" %]
+ <div class="hidden" id="acq-[% which_lc %]-info-related">
+ Show the <a name="rel_link" href="#"><span name="related_number"></span> other lineitem(s)</a> related to this bibliographic record.
+ </div>
+ <div style="margin-top:40px;">
+ <h3 id="acq-[% which_lc %]-marc-order-record-label">MARC Order Record</h3>
+ <h3 id="acq-[% which_lc %]-marc-real-record-label">MARC ILS Record</h3>
+ <div>
+ <div dojoType="dijit.form.Button" jsId="acq[% which %]EditOrderMarc" class="hidden">Edit MARC Order Record</div>
+ </div>
+ <div id="acq-[% which_lc %]-marc-div" style="margin-top:20px;"> </div>
+ </div>
+[% END %]
+ </div>
</div>
<!-- Bib record / Lineitem details table -->
- <div id='acq-lit-info-div' class='hidden'>
- <div class='acq-lit-li-menu-bar'>
- <div dojoType='dijit.form.Button' id='acq-lit-info-back-button'>↖ Return</div>
- </div>
- <table>
- <tbody id='acq-lit-info-tbody'>
- <tr id='acq-lit-info-row'><td name='label'/><td name='value'/></tr>
- </tbody>
- </table>
- <div style='margin-top:10px;' class='hidden' id='acq-lit-info-cat-link'>
- View in the <a href='/opac/en-US/skin/default/xml/rdetail.xml?r='>Catalog</a>
- </div>
- <div style='margin-top:40px;'>
- <h3 id='acq-lit-marc-order-record-label'>MARC Order Record</h3>
- <h3 id='acq-lit-marc-real-record-label'>MARC ILS Record</h3>
- <div>
- <div dojoType='dijit.form.Button' jsId='acqLitEditOrderMarc' class='hidden'>Edit MARC Order Record</div>
- </div>
- <div id='acq-lit-marc-div' style='margin-top:20px;'> </div>
- </div>
- </div>
+ [% INCLUDE "default/acq/common/detail.tt2" which = "Lit" %]
<!-- Lineitem notes table -->
- [% note_table_for = "Lit" %]
- [% INCLUDE "default/acq/common/notes.tt2" %]
+ [% INCLUDE "default/acq/common/notes.tt2" which = "Lit" %]
<!-- Copies table -->
<div id='acq-lit-li-details' class='hidden'>
-[% note_table_for_lc = note_table_for | lower %]
- <div id="acq-[% note_table_for_lc %]-notes-div" class="hidden">
- <div class="acq-notes-menu-bar">
+[% which_lc = which | lower %]
+ <div id="acq-[% which_lc %]-notes-div" class="hidden">
+ <div class="acq-menu-bar">
<table style="width:100%">
<tr>
<td style="text-align:left;">
- <div dojoType="dijit.form.Button" id="acq-[% note_table_for_lc %]-notes-back-button">↖ Return</div>
+ <div dojoType="dijit.form.Button" id="acq-[% which_lc %]-notes-back-button">↖ Return</div>
</td>
<td style="text-align:right;">
<div dojoType="dijit.form.DropDownButton">
<span>New Note</span>
<div dojoType="dijit.TooltipDialog">
<div class="acq-notes-note-row">
- <div jsId="acq[% note_table_for %]CreateNoteText" dojoType="dijit.form.Textarea" style="height:5em; width:25em;" name="note"></div>
+ <div jsId="acq[% which %]CreateNoteText" dojoType="dijit.form.Textarea" style="height:5em; width:25em;" name="note"></div>
<div style="margin: 8px 0;">
- <div dojoType="dijit.form.CheckBox" jsId="acq[% note_table_for %]CreateNoteVendorPublic" name="vendor_public" id="acq-[% note_table_for_lc %]-create-note-vendor-public"></div><label for="acq-[% note_table_for_lc %]-create-note-vendor-public">Note is vendor-public</label>
+ <div dojoType="dijit.form.CheckBox" jsId="acq[% which %]CreateNoteVendorPublic" name="vendor_public" id="acq-[% which_lc %]-create-note-vendor-public"></div><label for="acq-[% which_lc %]-create-note-vendor-public">Note is vendor-public</label>
</div>
</div>
- <button jsId="acq[% note_table_for %]CreateNoteSubmit" dojoType="dijit.form.Button" type="submit">Create</button>
+ <button jsId="acq[% which %]CreateNoteSubmit" dojoType="dijit.form.Button" type="submit">Create</button>
</div>
</div>
-[% IF note_table_for == "Lit" %]
+[% IF which == "Lit" %]
<div dojoType="dijit.form.DropDownButton">
<span>New Alert</span>
<div dojoType="dijit.TooltipDialog">
</table>
</div>
- <ol id="acq-[% note_table_for_lc %]-notes-tbody">
- <li id="acq-[% note_table_for_lc %]-notes-row">
+ <ol id="acq-[% which_lc %]-notes-tbody">
+ <li id="acq-[% which_lc %]-notes-row">
<table style="width:100%;" class="oils-generic-table">
<tr>
<td width="70%" align="left">
--- /dev/null
+[% WRAPPER "default/base.tt2" %]
+[% ctx.page_title = "Related Lineitems" %]
+<script src="[% ctx.media_prefix %]/js/ui/default/acq/lineitem/related.js"></script>
+<script type="text/javascript">var liId = "[% ctx.page_args.0 %]";</script>
+<h1>Related Lineitems</h1>
+<div id="acq-related-mini">
+ <ul id="acq-related-mini-display">
+ <li name="title"></li>
+ <li name="author"></li>
+ </ul>
+ <div dojoType="dijit.form.Button" id="acq-related-info-show-button">
+ Show details
+ </div>
+</div>
+[% INCLUDE "default/acq/common/detail.tt2" which = "Related" %]
+[% INCLUDE "default/acq/common/li_table.tt2" %]
+[% END %]
</div>
<script type="text/javascript">var poId = '[% ctx.page_args.0 %]';</script>
[% INCLUDE 'default/acq/common/li_table.tt2' %]
- [% note_table_for = "Po" %]
- [% INCLUDE "default/acq/common/notes.tt2" %]
+ [% INCLUDE "default/acq/common/notes.tt2" which = "Po" %]
</div>
[% END %]