Bug 10737: Add "Add to basket" link on vendor search results page
authorOwen Leonard <oleonard@myacpl.org>
Thu, 15 Aug 2013 16:09:33 +0000 (12:09 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 5 Sep 2013 15:28:31 +0000 (15:28 +0000)
This patch adds an "add to basket" link to the vendor search results
page for each open basket associated with each vendor. Clicking it
triggers a modal window with the "add to basket" choices for that vendor
and basket.

Other changes in this patch:

- The add-to-basket include has been modified in order to make it more
  useful in this context.
- booksellers.pl has been modified to check for an existing budget so
  that the add-to-basket include can properly display a warning if there
  are none.
- "New basket" and "Receive shipment" buttons associated with each
  vendor search result have been converted to Bootstrap-styled buttons.
- Basket closed date has been moved into its own column so that the
  table can be sorted by that value.
- Table columns containing dates now use the "title-string" sort option,
  eliminating the need for a special date sorting algorithm.
- Converted some &'s to &amp;'s

To test, apply the patch and search for a vendor. For each vendor in
your search results baskets which are open should include an "add to
basket" link. Clicking it should open a modal dialog with the same "add
to basket" options offered on the basket page. The correct vendor ID and
basket number should be associated with each link.

The newly-styled "new basket" and "receive shipment" buttons should work
correctly. Table sorting should work correctly, including the new
"closed" column.

Since the add-to-basket include file was modified, the "add to basket"
button on the basket view page should also be tested (acqui/basket.pl).

Signed-off-by: Campbell Reid-Tait <campbellreidtait@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
acqui/booksellers.pl
koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/booksellers.tt

index 6db0bad..bb65dbc 100755 (executable)
@@ -53,6 +53,7 @@ use strict;
 use warnings;
 use C4::Auth;
 use C4::Biblio;
+use C4::Budgets;
 use C4::Output;
 use CGI;
 
@@ -62,7 +63,7 @@ use C4::Members qw/GetMember/;
 use C4::Context;
 
 my $query = CGI->new;
-my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
     {   template_name   => 'acqui/booksellers.tmpl',
         query           => $query,
         type            => 'intranet',
@@ -103,6 +104,18 @@ my $viewbaskets = C4::Context->preference('AcqViewBaskets');
 
 my $userbranch = $userenv->{branch};
 
+my $budgets = GetBudgetHierarchy;
+my $has_budgets = 0;
+foreach my $r (@{$budgets}) {
+    if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) {
+        next;
+    }
+    next unless (CanUserUseBudget($loggedinuser, $r, $userflags));
+
+    $has_budgets = 1;
+    last;
+}
+
 #build result page
 my $loop_suppliers = [];
 
@@ -150,6 +163,7 @@ $template->param(
     loop_suppliers => $loop_suppliers,
     supplier       => ( $booksellerid || $supplier ),
     count          => $supplier_count,
+    has_budgets          => $has_budgets,
 );
 $template->{VARS}->{'allbaskets'} = $allbaskets;
 
index 01ecec9..46f8400 100644 (file)
@@ -1,13 +1,14 @@
-<fieldset id="acqui_basket_add">
+<fieldset class="acqui_basket_add">
     <legend>Add order to basket</legend>
     [% IF has_budgets %]
       <ul>
         <li>
-          <label for="q">From an existing record: </label>
           <form action="/cgi-bin/koha/acqui/neworderbiblio.pl" method="post">
+            <label>From an existing record:
+                <input type="text"  size="25" name="q" />
+            </label>
             <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
             <input type="hidden" name="basketno" value="[% basketno %]" />
-            <input id="q" type="text"  size="25" name="q" />
             <input type="submit" class="submit" value="Search" />
           </form>
         </li>
@@ -18,6 +19,8 @@
         <li><a href="/cgi-bin/koha/acqui/addorderiso2709.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]"> From a staged file</a></li>
       </ul>
     [% ELSE %]
-        You can't create any orders unless you first <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">define a budget and a fund</a>.
+        <div class="dialog alert">
+          <p>You can't create any orders unless you first <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">define a budget and a fund</a>.</p>
+        </div>
     [% END %]
 </fieldset>
index 8cbc46e..5da0b29 100644 (file)
@@ -30,7 +30,7 @@
         updateColumnsVisibility(false);
         [% UNLESS ( closedate ) %]
             $('#addtoBasket').on('show', function () {
-               $(this).find(".modal-body").html($("#acqui_basket_add")[0].outerHTML);
+               $(this).find(".modal-body").html($(".acqui_basket_add")[0].outerHTML);
             });
         [% END %]
     });
index 525ea66..782bed1 100644 (file)
 <script type="text/javascript">
 //<![CDATA[
 $(document).ready(function() {
-    [% IF (dateformat == 'metric') %]
-        dt_add_type_uk_date();
-    [% END %]
     $("table.baskets").dataTable($.extend(true, {}, dataTablesDefaults, {
         'sDom': 't',
         'bPaginate': false,
         'bFilter': false,
         'bInfo': false,
         "aaSorting": [[ 1, "asc" ]],
+        "aoColumns": [
+            null,null,null,null,null,null,{ "sType": "title-string" },{ "sType": "title-string" },null
+        ],
         'aoColumnDefs': [
-            { 'aTargets': [-1], 'bSortable': false }
+            { 'aTargets': [-1,-2], 'bSortable': false }
         ]
     }));
     $("#supplierlist").change(function() {
         var id = $(this).find("option:selected").val();
         window.location.href = "#" + id;
     });
+    $(".modal").on("show", function(){
+        var basket = $(this).data("basketno");
+        var legend = _("Add order to basket") + " " + basket;
+        $(this).find("legend").html(legend);
+    });
 });
 //]]>
 </script>
@@ -63,9 +68,9 @@ $(document).ready(function() {
         </p>
     [% END %]
     [% IF ( allbaskets ) %]
-        <p><a href="/cgi-bin/koha/acqui/booksellers.pl?supplier=[% supplier %]&booksellerid=[% booksellerid %]">Show active baskets only</a></p>
+        <p><a href="/cgi-bin/koha/acqui/booksellers.pl?supplier=[% supplier %]&amp;booksellerid=[% booksellerid %]">Show active baskets only</a></p>
     [% ELSE %]
-        <p><a href="/cgi-bin/koha/acqui/booksellers.pl?supplier=[% supplier %]&booksellerid=[% booksellerid %]&allbaskets=1">Show all baskets</a></p>
+        <p><a href="/cgi-bin/koha/acqui/booksellers.pl?supplier=[% supplier %]&amp;booksellerid=[% booksellerid %]&amp;allbaskets=1">Show all baskets</a></p>
     [% END %]
     <div id="acqui_order_supplierlist">
         [% FOREACH supplier IN loop_suppliers %]
@@ -80,12 +85,12 @@ $(document).ready(function() {
                 <span class="action">
                     [% IF ( CAN_user_acquisition_order_manage ) %]
                         [% IF ( supplier.active ) %]
-                            <input type="button" value="New basket" onclick="window.location.href='/cgi-bin/koha/acqui/basketheader.pl?booksellerid=[% supplier.booksellerid %]&amp;op=add_form'" />
+                            <a class="btn btn-small" href="/cgi-bin/koha/acqui/basketheader.pl?booksellerid=[% supplier.booksellerid %]&amp;op=add_form"><i class="icon-plus"></i> New basket</a>
                         [% ELSE %]
                             (inactive)
                         [% END %]
                     [% END %]
-                    <input type="button" value="Receive shipment" onclick="window.location.href='/cgi-bin/koha/acqui/parcels.pl?booksellerid=[% supplier.booksellerid %]'" />
+                    <a class="btn btn-small" href="/cgi-bin/koha/acqui/parcels.pl?booksellerid=[% supplier.booksellerid %]"><i class="icon-inbox"></i> Receive shipment</a>
                 </span>
                 <div class="baskets">
                     [% IF ( supplier.loop_basket.size ) %]
@@ -99,6 +104,7 @@ $(document).ready(function() {
                                     <th>Items expected</th>
                                     <th>Created by</th>
                                     <th>Date</th>
+                                    <th>Closed</th>
                                     <th>&nbsp;</th>
                                 </tr>
                             </thead>
@@ -118,23 +124,35 @@ $(document).ready(function() {
                                             [% basket.authorisedby_firstname %]
                                             [% basket.authorisedby_surname %]
                                         </td>
-                                        <td>[% basket.creationdate | $KohaDates %]</td>
+                                        <td><span title="[% basket.creationdate %]">[% basket.creationdate | $KohaDates %]</span></td>
                                         <td>
                                             [% IF ( basket.closedate ) %]
-                                                closed on [% basket.closedate | $KohaDates %]
-                                                <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno %]">View</a>
+                                                <span title="[% basket.closedate %]">[% basket.closedate | $KohaDates %]</span>
                                             [% ELSE %]
-                                                [% IF ( basket.active ) %]
-                                                    <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno %]">Modify</a>
-                                                [% ELSE %]
-                                                    <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno %]">View</a>
-                                                [% END %]
+                                                <span title="9999-99-99"></span>
+                                            [% END %]
+                                        </td>
+                                        <td>
+                                            <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno %]">View</a>
+
+                                            [% UNLESS ( basket.closedate ) %]
+                                               | <a id="addtoBasketLabel[% basket.basketno %]" href="#addtoBasket[% basket.basketno %]" role="button" data-toggle="modal">Add to basket</a>
+                                                <!-- Modal -->
+                                                <div id="addtoBasket[% basket.basketno %]" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="addtoBasketLabel[% basket.basketno %]" aria-hidden="true" data-basketno="[% basket.basketname %]">
+                                                    <div class="modal-body">
+                                                        [% INCLUDE 'acquisitions-add-to-basket.inc' booksellerid=supplier.booksellerid basketno=basket.basketno %]
+                                                    </div>
+                                                    <div class="modal-footer">
+                                                        <a href="#" class="cancel" data-dismiss="modal" aria-hidden="true">Cancel</a>
+                                                    </div>
+                                                </div>
                                             [% END %]
                                         </td>
                                     </tr>
                                 [% END %][%# FOREACH basket IN supplier.loop_basket %]
                             </tbody>
                         </table>
+
                     [% ELSE %]
                         <p>No pending baskets</p>
                     [% END %][%# IF ( supplier.loop_basket.size ) %]