Subject: [PATCH] [Signed off] Bug 9943 - Pay fines page "Pay selected" button give invalid amount when nothing is selected

From: Owen Leonard <[email-masked]>
Date: Fri, 9 Aug 2013 13:43:21 -0400

If you select no fines but click the "pay selected" button the resulting
screen offers to let you pay against all fines, which is confusing. To
simplify things this patch disables the "pay selected" button if no
lines are selected.

To test, apply the patch and find a patron with outstanding fines. From
the "pay fines" page (members/pay.pl) try selecting and deselecting
checkboxes and using the "select all" and "clear all" links. When no
item is selected the "Pay selected" button should become disabled.
Confirm that the form submits correctly when one or more fines is
selected.

Signed-off-by: Melia Meggs <[email-masked]>
---
 .../intranet-tmpl/prog/en/modules/members/pay.tt   |   31 ++++++++++++++++---
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
index 9b50924..91f1609 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
@@ -4,6 +4,15 @@
 <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
 <script type= "text/javascript">
 //<![CDATA[
+function enableCheckboxActions(){
+    // Enable/disable controls if checkboxes are checked
+    var checkedBoxes = $("input.cb:checked");
+    if ($(checkedBoxes).size()) {
+      $("#payselected").prop("disabled",false);
+    } else {
+      $("#payselected").prop("disabled",true);
+    }
+}
     $(document).ready(function(){
  $('#pay-fines-form').preventDoubleFormSubmit();
         $("#woall").click(function(event){
@@ -12,8 +21,20 @@
                     event.preventDefault();
                 }
         });
-        $('#CheckAll').click(function(){ $("#finest").checkCheckboxes(); return false;});
-        $('#CheckNone').click(function(){ $("#finest").unCheckCheckboxes(); return false;});
+        $('#CheckAll').click(function(){
+            $("#finest").checkCheckboxes();
+            enableCheckboxActions();
+            return false;
+        });
+        $('#CheckNone').click(function(){
+            $("#finest").unCheckCheckboxes();
+            enableCheckboxActions();
+            return false;
+        });
+        $(".cb").change(function(){
+            enableCheckboxActions();
+        });
+        enableCheckboxActions();
     });
 //]]>
 </script>
@@ -71,7 +92,7 @@
 <tr>
     <td>
     [% IF ( line.amountoutstanding > 0 ) %]
-        <input type="checkbox" checked="checked" name="incl_par_[% line.accountno %]" />
+        <input class="cb" type="checkbox" checked="checked" name="incl_par_[% line.accountno %]" />
     [% END %]
     </td>
     <td>
@@ -111,9 +132,9 @@
 </tbody>
 </table>
 <fieldset class="action">
-<input type="submit" name="paycollect"  value="Pay amount" class="submit" />
+<input type="submit" id="paycollect" name="paycollect"  value="Pay amount" class="submit" />
 <input type="submit" name="woall"  id="woall" value="Write off all" class="submit" />
-<input type="submit" name="payselected"  value="Pay selected" class="submit" />
+<input type="submit" id="payselected" name="payselected"  value="Pay selected" class="submit" />
 <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
 </fieldset>
 </form>
-- 
1.7.2.5