From cf5615f2fb035fd1f98d50b09d3862be4cc67352 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Thu, 28 Apr 2016 20:52:40 -0400
Subject: [PATCH] [PASSED QA] Bug 16386 - Replace the use of "onclick" from
 patron card creator templates

This patch removes the use of "onclick" from several patron card creator
templates. Events are defined instead in JavaScript.

Also changed:

- Patron search pop-up window is now slightly larger because I found it
  never quite large enough to prevent horizontal scrolling.
- Replaced "Borrower" with "Patron" in a couple of places.
- "Add" link in patron search pop-up is now styled as a Bootstrap
  button.
- Removed Bootstrap styles from some submit buttons.
- Some Font Awesome icons were made using the invalid element
  <icon></icon> instead of <i></i>. These are corrected.
- Fixed some other HTML validation errors.

To test, apply the patch and go to Tools -> Patron card creator.

- Choose New -> Card batch.
  - Click "Add patrons" and perform a search for patrons in the pop-up
    window.
  - Click the "Add" button. The corresponding borrowernumber should be
    added to the textarea in the parent window, and a message should
    appear at the top of the pop-up window confirming that the patron
    has been added. (Note: This patch fixes a version of Bug 13041 which
    prevented the "add" button from working on patrons whose name
    include an apostrophe).
  - In the parent page, in the list of patrons you added to the batch,
    confirm that clicking the "Delete" link triggers a confirmation
    dialog. Test both confirming and canceling.
  - Confirm that clicking the "Export" button next to an individual
    patron triggers a modal window.
    - In the export window, confirm that the "Cancel" link works to
      close the modal.
    - Click the "Export" button again and then the "Export" button in
      the modal.
      - Test that the "Done" button works to close the modal.
- Choose Manage -> Card batches.
  - Test the "Delete" and "Export" buttons as described above.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
All works, no errors.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 .../prog/en/modules/common/patron_search.tt        | 13 +++++++---
 .../prog/en/modules/patroncards/edit-batch.tt      | 28 ++++++++++++++--------
 .../prog/en/modules/patroncards/image-manage.tt    |  2 +-
 .../prog/en/modules/patroncards/manage.tt          | 19 ++++++++++-----
 .../prog/en/modules/patroncards/print.tt           | 12 +++++++---
 .../modules/patroncards/tables/members_results.tt  |  2 +-
 6 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
index c1ce712..41c83d8 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
@@ -100,6 +100,13 @@ $(document).ready(function(){
         e.preventDefault();
         filterByFirstLetterSurname($(this).text());
     });
+    $("body").on("click",".add_user",function(e){
+        e.preventDefault();
+        var borrowernumber = $(this).data("borrowernumber");
+        var firstname = $(this).data("firstname");
+        var surname = $(this).data("surname");
+        add_user( borrowernumber, firstname + " " + surname );
+    });
 });
 
 function filter() {
@@ -133,10 +140,10 @@ function filterByFirstLetterSurname(letter) {
                     $("#info").hide();
                     $("#error").hide();
                     if ( p.add_user(borrowernumber, borrowername) < 0 ) {
-                        $("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
+                        $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
                         $("#error").show();
                     } else {
-                        $("#info").html(_("Borrower '%s' added.").format(borrowername));
+                        $("#info").html(_("Patron '%s' added.").format(borrowername));
                         $("#info").show();
                     }
                 }
@@ -189,7 +196,7 @@ function filterByFirstLetterSurname(letter) {
                     </li>
                 </ol>
                 <fieldset class="action">
-                    <input class="btn btn-default" type="submit" value="Search" />
+                    <input type="submit" value="Search" />
                 </fieldset>
             </fieldset>
         <form>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt
index 6652836..9131ee4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt
@@ -6,7 +6,6 @@
     [% INCLUDE 'datatables.inc' %]
     <script type="text/javascript">
         //<![CDATA[
-           var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this patron from the card batch?");
            function DeleteConfirm() {
                 var msg = _("Are you sure you want to delete batch %s?").format("[% batch_id %]");
                 var answer = confirm(msg);
@@ -52,7 +51,7 @@
                 if (bor_nums.value == '') {
                     window.open("/cgi-bin/koha/patroncards/add_user_search.pl",
                    'PatronPopup',
-                   'width=740,height=450,location=yes,toolbar=no,'
+                   'width=840,height=500,location=yes,toolbar=no,'
                    + 'scrollbars=yes,resize=yes');
                 }
                 else {
@@ -148,6 +147,15 @@
                 Xport('batch');
                 return false;
             });
+            $(".delete").on("click", function(){
+                return confirmDelete( _("Are you sure you want to delete this patron from the card batch?") );
+            });
+            $(".export").on("click", function(e){
+                e.preventDefault();
+                var label_id = $(this).data("label-id");
+                var batch_id = $(this).data("batch-id");
+                GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id+'&label_id='+label_id, 400, 800);
+            });
          });
         //]]>
     </script>
@@ -201,12 +209,12 @@
                                 </div>
                             </form>
                             <div id="batch-manage" class="action">
-                                <a class="btn btn-small" id="additems" href="#"><icon class="fa fa-plus"></icon> Add patron(s)</a>[% IF ( table_loop ) %]
-                                <a class="btn btn-small" id="removeitems" href="#"><icon class="fa fa-trash"></icon> Remove selected patrons</a>
-                                <a class="btn btn-small" id="deletebatch" href="#"><icon class="fa fa-minus-square"></icon> Delete batch</a>
-                                <a class="btn btn-small" id="deduplicate" href="#"><icon class="fa fa-minus"></icon> Remove duplicates</a>
-                                <a class="btn btn-small" id="exportitems" href="#"><icon class="fa fa-share-square-o"></icon> Export selected card(s)</a>
-                                <a class="btn btn-small" id="exportbatch" href="#"><icon class="fa fa-share-square-o"></icon> Export card batch</a>[% END %]
+                                <a class="btn btn-small" id="additems" href="#"><i class="fa fa-plus"></i> Add patron(s)</a>[% IF ( table_loop ) %]
+                                <a class="btn btn-small" id="removeitems" href="#"><i class="fa fa-trash"></i> Remove selected patrons</a>
+                                <a class="btn btn-small" id="deletebatch" href="#"><i class="fa fa-minus-square"></i> Delete batch</a>
+                                <a class="btn btn-small" id="deduplicate" href="#"><i class="fa fa-minus"></i> Remove duplicates</a>
+                                <a class="btn btn-small" id="exportitems" href="#"><i class="fa fa-share-square-o"></i> Export selected card(s)</a>
+                                <a class="btn btn-small" id="exportbatch" href="#"><i class="fa fa-share-square-o"></i> Export card batch</a>[% END %]
                             </div>
                             [% IF ( table_loop ) %]
                             <form name="items" class="checkboxed">
@@ -238,8 +246,8 @@
                                                 [% FOREACH text_field IN table_loo.text_fields %]
                                                     [% IF ( text_field.select_field ) %]
                                                         <td>
-                                                            <a class="btn btn-mini" onclick="return confirm(MSG_CONFIRM_DELETE);" href="/cgi-bin/koha/patroncards/edit-batch.pl?op=remove&amp;batch_id=[% batch_id %]&amp;label_id=[% text_field.field_value %]"><icon class="fa fa-trash"></icon> Delete</a>
-                                                            <a class="btn btn-mini" href="#" onclick="GB_showCenter('Export single card','/cgi-bin/koha/patroncards/print.pl?batch_id=[% batch_id %]&label_id=[% text_field.field_value %]')"><icon class="fa fa-share-square-o"></icon> Export</a>
+                                                            <a class="btn btn-mini delete" href="/cgi-bin/koha/patroncards/edit-batch.pl?op=remove&amp;batch_id=[% batch_id %]&amp;label_id=[% text_field.field_value %]"><i class="fa fa-trash"></i> Delete</a>
+                                                            <a class="btn btn-mini export" href="#" data-batch-id="[% batch_id %]" data-label-id="[% text_field.field_value %]"><i class="fa fa-share-square-o"></i> Export</a>
                                                         </td>
                                                         <td><input type="checkbox" name="action" value="[% text_field.field_value %]" /></td>
                                                     [% ELSE %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/image-manage.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/image-manage.tt
index 84b58eb..17387bd 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/image-manage.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/image-manage.tt
@@ -135,7 +135,7 @@
                                     [% FOREACH text_field IN TABL.text_fields %]
                                     [% IF ( text_field.select_field ) %]
                                         <td>
-                                            <a class="delete_image btn btn-mini" href="/cgi-bin/koha/patroncards/image-manage.pl?op=delete&image_id=[% text_field.field_value %]"><icon class="fa fa-trash"></icon> Delete</a>
+                                            <a class="delete_image btn btn-mini" href="/cgi-bin/koha/patroncards/image-manage.pl?op=delete&image_id=[% text_field.field_value %]"><i class="fa fa-trash"></i> Delete</a>
                                         </td>
                                         <td align="center"><input type="checkbox" name="action" value="[% text_field.field_value %]" /></td>
                                     [% ELSIF ( text_field.field_value ) %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt
index 331eede..a75a924 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt
@@ -26,7 +26,6 @@
     [% INCLUDE 'greybox.inc' %]
     <script type="text/javascript">
         //<![CDATA[
-            var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this?");
             function DeleteConfirm() {
                 var element_ids = selected_layouts("delete");
 
@@ -157,6 +156,14 @@
                 XportPatronlist();
                 return false;
             });
+            $(".delete").on("click", function(){
+                return confirmDelete( _("Are you sure you want to delete this?") );
+            });
+            $(".export").on("click", function(e){
+                e.preventDefault();
+                var batch_id = $(this).data("batch-id");
+                GB_showCenter( _("Export single batch"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id, 400, 800);
+            });
          });
 //]]>
 </script>
@@ -200,11 +207,11 @@
                                 [% FOREACH text_field IN table_loo.text_fields %]
                                 [% IF ( text_field.select_field ) %]
                                     <td>
-                                      <a class="btn btn-mini" href="/cgi-bin/koha/patroncards/edit-[% card_element %].pl?op=edit&element_id=[% text_field.field_value %]"><icon class="fa fa-edit"></icon> Edit</a>
-                                      [% IF ( print ) %]<a class="btn btn-mini" href="#" onclick="GB_showCenter('Export single batch','/cgi-bin/koha/patroncards/print.pl?batch_id=[% text_field.field_value |url %]', 400, 800)"><icon class="fa fa-share-square-o"></icon> Export</a>[% END %]
-                                      <a class="btn btn-mini" onclick="return confirm(MSG_CONFIRM_DELETE);" href="/cgi-bin/koha/patroncards/manage.pl?op=delete&card_element=[% card_element %]&element_id=[% text_field.field_value %]"><icon class="fa fa-trash"></icon> Delete</a>
+                                      <a class="btn btn-mini" href="/cgi-bin/koha/patroncards/edit-[% card_element %].pl?op=edit&element_id=[% text_field.field_value %]"><i class="fa fa-edit"></i> Edit</a>
+                                      [% IF ( print ) %]<a class="btn btn-mini export" data-batch-id="[% text_field.field_value |url %]" href="/cgi-bin/koha/patroncards/print.pl?batch_id=[% text_field.field_value |url %]"><i class="fa fa-share-square-o"></i> Export</a>[% END %]
+                                      <a class="btn btn-mini delete" href="/cgi-bin/koha/patroncards/manage.pl?op=delete&card_element=[% card_element %]&element_id=[% text_field.field_value %]"><i class="fa fa-trash"></i> Delete</a>
                                     </td>
-                                    [% IF ( print ) %]<td align="center"><input type="checkbox" name="action" value="[% text_field.field_value %]" /></td>[% END %]
+                                    [% IF ( print ) %]<td><input type="checkbox" name="action" value="[% text_field.field_value %]" /></td>[% END %]
                                 [% ELSIF ( text_field.field_value ) %]
                                     <td>[% text_field.field_value %]</td>
                                 [% ELSE %]
@@ -216,7 +223,7 @@
                                 [% END %]
                             </table>
                             <fieldset class="action">
-                                [% IF ( print ) %]<input class="btn btn-sm" type="button" id="print" value="Export selected batches" />[% END %]
+                                [% IF ( print ) %]<input type="button" id="print" value="Export selected batches" />[% END %]
                             </fieldset>
                             [% IF patron_lists %]
                             <fieldset class="rows">
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt
index bf22842..c6619ab 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt
@@ -6,6 +6,11 @@
             function Done() {
                 window.location = "[% referer %]";
             };
+            $(document).ready(function(){
+                $(".gb-close").on("click",function(){
+                    parent.parent.GB_hide();
+                });
+            })
         //]]>
     </script>
     <style type="text/css">#custom-doc {width:47.23em; *width:46.04em; min-width:610px; margin:auto; margin-top:0.4em;}</style>
@@ -38,7 +43,7 @@
                     </fieldset>
 
                 <fieldset class="action">
-                    <input type="button" class="btn btn-default submit" id="done" onclick="parent.parent.GB_hide();" value="Done" />
+                    <input type="button" class="gb-close" value="Done" />
                 </fieldset>
             </form>
             [% ELSIF ( patronlist_id && template_id && layout_id ) %]
@@ -95,10 +100,11 @@
                     </ol>
                 </fieldset>
                 <fieldset class="action">
-                    <input type="submit" class="btn btn-default submit" value="Export" />
-                    <a href="#" class="cancel" id="done" onclick="parent.parent.GB_hide();">Cancel</a>
+                    <input type="submit" value="Export" />
+                    <a href="#" class="cancel gb-close">Cancel</a>
                 </fieldset>
             </form>
             [% END %]
         </div>
+    </div>
     [% INCLUDE 'popup-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt
index 087aa8c..e3455be 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt
@@ -19,7 +19,7 @@
                 "dt_borrowernotes":
                     "[% data.borrowernotes.replace('\\\\' , '\\\\') |html |html_line_break |collapse %]",
                 "dt_action":
-                    "<a href=\"#\" onclick='add_user(\"[% data.borrowernumber %]\", \"[% data.firstname %] [% data.surname %]\"); return false;'>Add</a>"
+                    "<a href=\"#\" data-borrowernumber=\"[% data.borrowernumber %]\" data-firstname=\"[% data.firstname %]\" data-surname=\"[% data.surname %]\" class=\"btn btn-mini add_user\"><i class=\"fa fa-plus\"></i> Add</a>"
             }[% UNLESS loop.last %],[% END %]
         [% END %]
     ]
-- 
1.9.1