Bug 17183: Check if any checkboxes have been checked for 'Delete Selected' button...
authorAleisha Amohia <aleishaamohia@hotmail.com>
Wed, 24 Aug 2016 03:43:22 +0000 (03:43 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 9 Sep 2016 14:02:58 +0000 (14:02 +0000)
To test:
1) Go to Tools -> Koha News
2) Click 'Delete selected' button without selecting anything
3) Notice you are asked to confirm if you would like to delete ... but
you didn't choose anything to delete
4) Apply patch and refresh page
5) Click 'Delete selected' button without selecting anything
6) Should see alert.
7) Select one or more news items to delete and click 'Delete selected'
button
8) Should be asked to confirm
9) Confirm that the delete works as expected

Sponsored-by: Catalyst IT
Signed-off-by: Claire Gravely <claire_gravely@hotmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt

index 1cf4313..074f875 100644 (file)
         $(".delete_news").on("click", function(){
             return confirmDelete( _("Are you sure you want to delete this news item? This cannot be undone.") );
         });
+
+        function Checkbox(){
+            var form = document.getElementById('del_form');
+            var inputs = form.getElementsByTagName('input');
+            var checked = false;
+            for (var i=0; i<inputs.length; i++) {
+                if (inputs[i].type == 'checkbox' && inputs[i].name == 'ids') {
+                    checked = inputs[i].checked;
+                    if (checked) return true;
+                }
+            }
+        }
+
         $("#del_form").on("submit",function(){
-            return confirmDelete( _("Are you sure you want to delete the selected news?") );
+            if ( Checkbox() ) {
+                return confirmDelete( _("Are you sure you want to delete the selected news?") );
+            } else {
+                alert(_("Please select a news item to delete."));
+                return false;
+            }
         });
     });
     //]]>