Bug 7626: Delete multiple tags in OPAC at once
authorAleisha Amohia <aleishaamohia@hotmail.com>
Wed, 15 Feb 2017 00:03:28 +0000 (00:03 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 17 Feb 2017 17:11:35 +0000 (17:11 +0000)
This patch removes the individual 'Delete' buttons for every tag as
suggested in Comment 0. It adds a checkbox to every tag, with a 'Delete
selected tags' button at the bottom of the table. This patch also adds a
function to check if any checkboxes have been checked before submitting
the form (only works with JS enabled).

To test:
1) Find a record in the OPAC and add some tags to it
2) Go to your tags and notice the checkboxes, no more delete buttons for
each tag
3) Click 'Delete selected tags' button without selecting any tags
4) Confirm alert shows up. Click OK
5) Select one or more tags and click 'Delete selected tags' button
6) Confirm delete is successful and correct number of deleted tags shows
up

Sponsored-by: Catalyst IT
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/opac-tmpl/bootstrap/en/modules/opac-tags.tt

index 052acd6..4d6a428 100644 (file)
                         [% END # / TAGLOOP%]
                         [% IF ( add_op ) %]
                             [% IF ( added_count ) %]
-                                <div class="dialog message">[% added_count %] [% IF ( added_count ==1 ) %] tag[% ELSE %]tags[% END %] successfully added.</div>
+                                <div class="dialog message">[% added_count %] [% IF ( added_count == 1 ) %]tag[% ELSE %]tags[% END %] successfully added.</div>
                             [% END %]
                             [% IF ( deleted_count ) %]
-                            <div class="dialog message">[% deleted_count %][% IF ( deleted_count ==1 ) %] tag[% ELSE %]tags[% END %] successfully deleted.</div>
+                            <div class="dialog message">[% deleted_count %] [% IF ( deleted_count == 1 ) %]tag[% ELSE %]tags[% END %] successfully deleted.</div>
                             [% END %]
                         [% END # /add_op %]
 
                         [% IF ( MY_TAGS ) %]
-                        <form method="post" action="opac-tags.pl">
+                        <form id="deletetags" method="post" action="opac-tags.pl">
                             <h2>Your tags</h2>
                             <table id="mytagst" class="table table-bordered table-striped">
-                                <thead><tr><th>Term</th><th>Title</th><th>Date added</th><th>Delete</th></tr></thead>
+                                <thead><tr><th>&nbsp;</th><th>Term</th><th>Title</th><th>Date added</th></tr></thead>
                                 <tbody>
                                     [% FOREACH MY_TAG IN MY_TAGS %]
                                         <tr>
+                                            <td>
+                                                <input type="checkbox" name="del[% MY_TAG.tag_id %]" value="del[% MY_TAG.tag_id %]">
+                                            </td>
                                             <td class="tagterm">
                                                 <span class="tdlabel">Tag:</span>
                                                 [% IF MY_TAG.approved == 1 %]
                                                     [% MY_TAG.term |html %] (not approved)
                                                 [% END %]
                                             </td>
-
                                             <td>
                                                 [% IF ( MY_TAG.XSLTBloc ) %]
                                                     [% MY_TAG.XSLTBloc %]
                                                     [% MY_TAG.date_created | $KohaDates %]
                                                 </span>
                                             </td>
-                                            <td><input type="submit" name="del[% MY_TAG.tag_id %]" value="Delete" class="btn btn-danger btn-mini delete" /></td>
                                         </tr>
                                     [% END %]
                                 </tbody>
                             </table>
+                            <input type="submit" value="Delete selected tags" class="btn btn-danger btn-sm delete">
                         </form>
                         [% END # /MY_TAGS %]
                     </div> <!-- / .usertags -->
 [% INCLUDE 'datatables.inc' %]
 <script type="text/javascript">
 //<![CDATA[
+    function checkboxesChecked() {
+        if ($("#deletetags input:checkbox:checked").length > 0) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
 
     $(document).ready(function(){
-        var MSG_DELETE_TAG = _("Are you sure you want to delete this tag?");
-        $(".delete").on("click", function(){
-            return confirmDelete(MSG_DELETE_TAG);
+        var MSG_DELETE_TAG = _("Are you sure you want to delete the selected tag(s)?");
+        $(".delete").on("click", function(e){
+            if ( checkboxesChecked() == 1 ) {
+                return confirmDelete(MSG_DELETE_TAG);
+            } else {
+                alert(_("Please select a tag to delete."));
+                e.preventDefault();
+            }
         });
 
         $("#mytagst").dataTable($.extend(true, {}, dataTablesDefaults, {
             "aaSorting": [[ 2, "asc" ]],
             "aoColumnDefs": [
-              { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }
+              { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false }
             ],
             "aoColumns": [
                 null,