From 93d6a85dabea59c6533e19a88a0ea833eaa4e349 Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 12 Mar 2010 23:46:04 +0000 Subject: [PATCH] Acq: from the lineitem details pane, one can view other LIs of same bib Also included a minor improvement to the use of the "notes" template for that part of the LI interface git-svn-id: svn://svn.open-ils.org/ILS/trunk@15841 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Acq/Lineitem.pm | 54 +++++------ Open-ILS/web/css/skin/default/acq.css | 5 +- .../web/js/ui/default/acq/common/li_table.js | 56 ++++++++--- .../web/js/ui/default/acq/lineitem/related.js | 93 +++++++++++++++++++ .../templates/default/acq/common/detail.tt2 | 27 ++++++ .../templates/default/acq/common/li_table.tt2 | 25 +---- .../templates/default/acq/common/notes.tt2 | 20 ++-- .../default/acq/lineitem/related.tt2 | 17 ++++ .../web/templates/default/acq/po/view.tt2 | 3 +- 9 files changed, 226 insertions(+), 74 deletions(-) create mode 100644 Open-ILS/web/js/ui/default/acq/lineitem/related.js create mode 100644 Open-ILS/web/templates/default/acq/common/detail.tt2 create mode 100644 Open-ILS/web/templates/default/acq/lineitem/related.tt2 diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm index 65b17e531e..d215e8fcc9 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm @@ -104,7 +104,7 @@ sub retrieve_lineitem_impl { 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 = { @@ -113,9 +113,12 @@ sub retrieve_lineitem_impl { }; 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)); @@ -295,6 +298,13 @@ __PACKAGE__->register_method ( / ); +__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); @@ -302,18 +312,17 @@ sub lineitems_related_by_bib { 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 @@ -336,22 +345,15 @@ sub lineitems_related_by_bib { } 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) + ); } } diff --git a/Open-ILS/web/css/skin/default/acq.css b/Open-ILS/web/css/skin/default/acq.css index 10e75d2ca8..f0d436b5f4 100644 --- a/Open-ILS/web/css/skin/default/acq.css +++ b/Open-ILS/web/css/skin/default/acq.css @@ -131,6 +131,7 @@ label[for="attr_search_type_scalar"] { vertical-align: top; } .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;} @@ -148,7 +149,7 @@ label[for="attr_search_type_scalar"] { vertical-align: top; } .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;} @@ -159,3 +160,5 @@ span[name="vendor_public"] {color: #00c;padding-right: 1em;font-weight: bold;} 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; } diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index 1195aca129..d3af1ed0af 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -39,6 +39,7 @@ function AcqLiTable() { this.liCache = {}; this.plCache = {}; this.poCache = {}; + this.relCache = {}; this.realDfaCache = {}; this.virtDfaCounts = {}; this.virtDfaId = -1; @@ -96,6 +97,7 @@ function AcqLiTable() { self.tbody.removeChild(self.tbody.childNodes[0]); self.selectors = []; self.noteAcks = {}; + self.relCache = {}; }; this.setNext = function(handler) { @@ -535,6 +537,28 @@ function AcqLiTable() { } 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() { @@ -588,23 +612,31 @@ function AcqLiTable() { 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]; diff --git a/Open-ILS/web/js/ui/default/acq/lineitem/related.js b/Open-ILS/web/js/ui/default/acq/lineitem/related.js new file mode 100644 index 0000000000..d46cd00dba --- /dev/null +++ b/Open-ILS/web/js/ui/default/acq/lineitem/related.js @@ -0,0 +1,93 @@ +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); diff --git a/Open-ILS/web/templates/default/acq/common/detail.tt2 b/Open-ILS/web/templates/default/acq/common/detail.tt2 new file mode 100644 index 0000000000..60188dbfc7 --- /dev/null +++ b/Open-ILS/web/templates/default/acq/common/detail.tt2 @@ -0,0 +1,27 @@ +[% which_lc = which | lower %] + diff --git a/Open-ILS/web/templates/default/acq/common/li_table.tt2 b/Open-ILS/web/templates/default/acq/common/li_table.tt2 index 927b127011..563f84c660 100644 --- a/Open-ILS/web/templates/default/acq/common/li_table.tt2 +++ b/Open-ILS/web/templates/default/acq/common/li_table.tt2 @@ -107,31 +107,10 @@ - + [% INCLUDE "default/acq/common/detail.tt2" which = "Lit" %] - [% note_table_for = "Lit" %] - [% INCLUDE "default/acq/common/notes.tt2" %] + [% INCLUDE "default/acq/common/notes.tt2" which = "Lit" %]