Bug 16262 - Remove the use of "onclick" from acquisitions basket template
authorOwen Leonard <oleonard@myacpl.org>
Thu, 14 Apr 2016 17:40:17 +0000 (13:40 -0400)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 29 Apr 2016 14:46:38 +0000 (14:46 +0000)
In order to bring the acquisitions basket template into compliance with
coding guideline JS9, this patch changes with way some JavaScript events
are handled by moving JS handling out of the HTML markup.

Also changed: Replaced the use of [% script_name %] (which is
undefined), with the actual script path.

To test, apply the patch and locate an open basket in Acquisitions which
has more than one order in it.

- Test the "Managed by: Add user" button and verify that it triggers a
  popup where you can search for patrons.
  - Select two or more patrons to be managers for the basket.
  - Close the search windows and confirm that your choices appear on the
    basket page.
  - Click "Delete user" next to one of the patrons. The patron should be
    removed.
  - Click "Save changes" and verify that your choices are correctly
    saved.
  - Click "Delete user" next to one of the remaining patrons. The patron
    should be removed.
  - Click "Save changes" and verify that the patron stays deleted.
- In the list of orders, click the "Transfer" link and confirm that the
  correct pop-up window is triggered.
- Test the "Delete this basket" button in the toolbar. A modal window
  should be triggered.
  - In a basket with orders:
    - The "Delete basket and orders" button should do what it says,
      leaving associated bibliographic records intact.
    - The "Delete basket, orders, and records" button should do what it
      says, deleting any bibliographic records associated with orders.
  - In a basket with no orders:
    - The "Delete basket" button should work correctly.
- Test the "Create edifact order" button.
  - Click "Send EDI order" on the resulting page.
  - In the resulting dialog, "Are you sure you want to generate an
    edifact order," verify that both the "Yes" and "No" options work
    correctly.

Followed test plan, works as expected.
Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt

index a00df03..2660a17 100644 (file)
                $(this).find(".modal-body").html($(".acqui_basket_add")[0].outerHTML);
             });
         [% END %]
+
+        $("body").on("click", ".del_user", function(e){
+            e.preventDefault();
+            del_user( $(this).data("borrowernumber") );
+        });
+
+        $("#add_user").on("click",function(e){
+            e.preventDefault();
+            UserSearchPopup();
+        });
+
+        $(".transfer_order").on("click",function(e){
+            e.preventDefault();
+            transfer_order_popup( $(this).data("ordernumber"));
+        });
     });
 //]]>
 </script>
 <script type="text/javascript">
 //<![CDATA[
 
-            function delete_basket(basketno,booksellerid,delbiblio) {
-                window.location = "[% script_name %]?op=delete_confirm&delbiblio="+delbiblio+"&basketno="+basketno+"&booksellerid="+booksellerid;
-            }
-
             function transfer_order_popup(ordernumber) {
                 var url = "/cgi-bin/koha/acqui/transferorder.pl?"
                     + "ordernumber=" + ordernumber
@@ -56,7 +67,7 @@
             function confirm_ediorder() {
                 var is_confirmed = confirm(_("Are you sure you want to close this basket and generate an Edifact order?"));
                 if (is_confirmed) {
-                    window.location = "[% script_name %]?op=edi_confirm&basketno=[% basketno %]";
+                    window.location = "/cgi-bin/koha/acqui/basket.pl?op=edi_confirm&basketno=[% basketno %]";
                 }
             }
 
@@ -81,7 +92,7 @@
                 var skip = [% IF ( skip_confirm_reopen ) %] 1 [% ELSE %] 0 [% END %];
                 var is_confirmed = skip || confirm(_("Are you sure you want to reopen this basket?"));
                 if (is_confirmed) {
-                    window.location = "[% script_name %]?op=reopen&basketno=[% basketno %]";
+                    window.location = "/cgi-bin/koha/acqui/basket.pl?op=reopen&basketno=[% basketno %]";
                 }
             }
 //]]>
             ids.push(borrowernumber);
             $("#users_ids").val(ids.join(':'));
             var li = '<li id="user_'+borrowernumber+'">'+borrowername
-                + ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
-                + _("Delete user") + '</a>]</li>';
+            + ' <a href="#" data-borrowernumber="'+borrowernumber+'" class="del_user"><i class="fa fa-trash"></i> '
+                + _("Delete user") + '</a></li>';
             $("#users_names").append(li);
             return 0;
         }
                     [% END %]
                     <div class="btn-group"><a href="basketheader.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]&amp;op=add_form" class="btn btn-small" id="basketheadbutton"><i class="fa fa-pencil"></i> Edit basket</a></div>
                     [%# FIXME This action should not be available for everyone %]
-                    <div class="btn-group"><a href="#deleteBasketModal" role="button" class="btn btn-small" data-toggle="modal" id="delbasketbutton"><i class="fa fa-remove"></i> Delete this basket</a></div>
+                    <div class="btn-group"><a href="#deleteBasketModal" role="button" class="btn btn-small" data-toggle="modal" id="delbasketbutton"><i class="fa fa-trash"></i> Delete this basket</a></div>
                    [% IF ( unclosable ) %]
                     [% ELSIF ( uncertainprices ) %]
                         <div class="btn-group"><a href="/cgi-bin/koha/acqui/uncertainprice.pl?booksellerid=[% booksellerid %]&amp;owner=1" class="btn btn-small" id="uncertpricesbutton">Uncertain prices</a></div>
                     [% ELSE %]
                         <div class="btn-group">
-                            <a href="[% script_name %]?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="closebutton"><i class="fa fa-times-circle"></i> Close this basket</a>
+                            <a href="/cgi-bin/koha/acqui/basket.pl?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="closebutton"><i class="fa fa-times-circle"></i> Close this basket</a>
                         </div>
                     [% END %]
-                        <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
+                        <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
                         [% IF ediaccount %]
                         <div class="btn-group"><a href="/cgi-bin/koha/acqui/edi_ean.pl?op=ediorder&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="ediorderbutton"><i class="fa fa-download"></i> Create edifact order</a></div>
                         [% END %]
                         </div>
                         <div class="modal-footer">
                             <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
-                            <button type="submit" class="btn btn-default" onclick="delete_basket([% basketno %],[% booksellerid %],0); return false;" >Delete basket</button>
+                            <form action="/cgi-bin/koha/acqui/basket.pl" method="get">
+                                <input type="hidden" name="op" value="delete_confirm" />
+                                <input type="hidden" name="basketno" value="[% basketno %]" />
+                                <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
+                                <input type="hidden" name="delbiblio" value="0" />
+                                <button type="submit" class="btn btn-default">Delete basket</button>
+                            </form>
                         </div>
                     [% ELSE %]
                         <div class="modal-body">
                         </div>
                         <div class="modal-footer">
                             <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
-                            <button type="submit" class="btn btn-default" onclick="delete_basket([% basketno %],[% booksellerid %],0); return false;">Delete basket and orders</button>
-                            <button type="submit" class="btn btn-default" onclick="delete_basket([% basketno %],[% booksellerid %],1); return false;">Delete basket, orders and bibs</button>
+                            <form action="/cgi-bin/koha/acqui/basket.pl" method="get">
+                                <input type="hidden" name="op" value="delete_confirm" />
+                                <input type="hidden" name="basketno" value="[% basketno %]" />
+                                <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
+                                <input type="hidden" name="delbiblio" value="0" />
+                                <button type="submit" class="btn btn-default">Delete basket and orders</button>
+                            </form>
+
+                            <form action="/cgi-bin/koha/acqui/basket.pl" method="get">
+                                <input type="hidden" name="op" value="delete_confirm" />
+                                <input type="hidden" name="basketno" value="[% basketno %]" />
+                                <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
+                                <input type="hidden" name="delbiblio" value="1" />
+                                <button type="submit" class="btn btn-default">Delete basket, orders, and records</button>
+                            </form>
+
                         </div>
                     [% END %]
                 </div>
                 [% UNLESS ( grouped ) %]
                 <div id="toolbar" class="btn-toolbar">
                     <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
-                    <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
+                    <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
                 </div>
                 [% END %]
             [% END %]
     <h2>Vendor not found</h2>
     [% ELSE %]
         [% IF ( delete_confirmed ) %]
-            <h3>Basket deleted</h3>
+            <div class="dialog message">
+                <h3>Basket deleted</h3>
+            </div>
             [% IF (cannotdelbiblios) %]
                 <div class="dialog alert">
                     <p><strong>Warning:</strong></p>
                               [% FOREACH user IN users %]
                                 <li id="user_[% user.borrowernumber %]">
                                     [% user.firstname %] [% user.surname %]
-                                    [<a onclick="del_user([% user.borrowernumber %]);" style="cursor:pointer">Delete user</a>]
+                                    <a href="#" data-borrowernumber="[% user.borrowernumber %]" class="del_user"><i class="fa fa-trash"></i> Delete user</a>
                                 </li>
                               [% END %]
                             </ul>
                             <input type="hidden" id="basketno" name="basketno" value="[% basketno %]" />
                             <input type="hidden" id="users_ids" name="users_ids" value="[% users_ids %]" />
                             <input type="hidden" id="op" name="op" value="mod_users" />
-                            <input type="button" id="add_user" onclick="UserSearchPopup();" value="Add user" />
+                            <input type="button" id="add_user" value="Add user" />
                             <input type="submit" value="Save changes" />
                         </div>
                     </form>
                                 <a href="neworderempty.pl?ordernumber=[% books_loo.ordernumber %]&amp;booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">Modify</a>
                                 [% UNLESS (books_loo.order_received) %]
                                     <br />
-                                    <a href="#" onclick="transfer_order_popup([% books_loo.ordernumber %]); return false;">Transfer</a>
+                                    <a href="#" class="transfer_order" data-ordernumber="[% books_loo.ordernumber %]">Transfer</a>
                                 [% END %]
                             </td>
                             <td>
 [% IF edi_confirm %]
         <div id="closebasket_needsconfirmation" class="dialog alert">
 
-        <form action="/cgi-bin/koha/acqui/basket.pl" class="confirm">
+        <form action="/cgi-bin/koha/acqui/basket.pl">
             <h1>Are you sure you want to generate an edifact order and close basket [% basketname|html %]?</h1>
             [% IF CAN_user_acquisition_group_manage %]
             <p>
             <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
             <input type="hidden" name="confirm" value="1" />
             <input type="hidden" name="basketgroupname" value="[% basketgroupname %]" />
-            <input type="submit" class="approve" value="Yes, close (Y)" accesskey="y" />
-            <input type="submit" class="deny" value="No, don't close (N)" accesskey="n" onclick="javascript:window.location='/cgi-bin/koha/acqui/basket.pl?basketno=[% basketno %]';return false;" />
+            <button type="submit" class="approve" accesskey="Y"><i class="fa fa-fw fa-check"></i> Yes, close (Y)</button>
+        </form>
+        <form action="/cgi-bin/koha/acqui/basket.pl" method="get">
+            <input type="hidden" name="basketno" value="[% basketno %]" />
+            <button type="submit" class="deny" accesskey="N"><i class="fa fa-fw fa-remove"></i> No, don't close (N)</button>
         </form>
         </div>
     [% END %]