From 760140b2b5fe9762213f307ad3718185c6900144 Mon Sep 17 00:00:00 2001
From: Dan Wells <dbw2@calvin.edu>
Date: Tue, 20 Feb 2018 11:05:49 -0500
Subject: [PATCH] LP#1749992 Disable payment button during payment

Since the display is not refreshed until the payment finishes, it
is possible to fire off a second payment by double-clicking.

This commit is a simple way to disable the button while a payment is
in process, then enable it again after the display refreshes.

Since the 'sendPayment()' function is wrapped, we may need to move
this logic up, but this being a single promise is simpler, and it
solved the problem in testing.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Jason Stephenson <jason@sigio.com>
---
 Open-ILS/src/templates/staff/circ/patron/t_bills.tt2  | 2 +-
 Open-ILS/web/js/ui/default/staff/circ/patron/bills.js | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
index c3fda5c688..835e1bf629 100644
--- a/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
+++ b/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
@@ -87,7 +87,7 @@
             <button
                 type="submit"
                 class="btn btn-default"
-                ng-disabled="invalid_check_number() || !gridControls.selectedItems().length"
+                ng-disabled="invalid_check_number() || !gridControls.selectedItems().length || applyingPayment"
             >[% l('Apply Payment') %]</button>
           </div>
         </div>
diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js b/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js
index ea21a3c194..d9e1bf79c9 100644
--- a/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js
+++ b/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js
@@ -325,6 +325,7 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
     // generates payments, collects user note if needed, and sends payment
     // to server.
     function sendPayment(note, cc_args) {
+        $scope.applyingPayment = true;
         var make_payments = generatePayments();
         billSvc.applyPayment($scope.payment_type, 
             make_payments, note, $scope.check_number, cc_args)
@@ -342,6 +343,7 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
                 console.error('Payment was rejected: ' + msg);
             }
         )
+        .finally(function() { $scope.applyingPayment = false; })
     }
 
     $scope.onReceiptOnPayChanged = function(){
-- 
2.11.0