From 93d6a85dabea59c6533e19a88a0ea833eaa4e349 Mon Sep 17 00:00:00 2001 From: senator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4> 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 --- .../perlmods/OpenILS/Application/Acq/Lineitem.pm | 54 +++++++------ Open-ILS/web/css/skin/default/acq.css | 5 +- Open-ILS/web/js/ui/default/acq/common/li_table.js | 56 ++++++++++--- Open-ILS/web/js/ui/default/acq/lineitem/related.js | 93 ++++++++++++++++++++++ .../web/templates/default/acq/common/detail.tt2 | 27 +++++++ .../web/templates/default/acq/common/li_table.tt2 | 25 +----- .../web/templates/default/acq/common/notes.tt2 | 20 ++--- .../web/templates/default/acq/lineitem/related.tt2 | 17 ++++ Open-ILS/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 %] + <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> 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 @@ </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'> diff --git a/Open-ILS/web/templates/default/acq/common/notes.tt2 b/Open-ILS/web/templates/default/acq/common/notes.tt2 index 399e7d3522..609cf6c812 100644 --- a/Open-ILS/web/templates/default/acq/common/notes.tt2 +++ b/Open-ILS/web/templates/default/acq/common/notes.tt2 @@ -1,25 +1,25 @@ -[% 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"> @@ -40,8 +40,8 @@ </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"> diff --git a/Open-ILS/web/templates/default/acq/lineitem/related.tt2 b/Open-ILS/web/templates/default/acq/lineitem/related.tt2 new file mode 100644 index 0000000000..587f9bcef5 --- /dev/null +++ b/Open-ILS/web/templates/default/acq/lineitem/related.tt2 @@ -0,0 +1,17 @@ +[% 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 %] diff --git a/Open-ILS/web/templates/default/acq/po/view.tt2 b/Open-ILS/web/templates/default/acq/po/view.tt2 index b301002f03..540c0ff3c2 100644 --- a/Open-ILS/web/templates/default/acq/po/view.tt2 +++ b/Open-ILS/web/templates/default/acq/po/view.tt2 @@ -27,7 +27,6 @@ </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 %] -- 2.11.0