diff --git a/static/js/reconcile_pledge.js b/static/js/reconcile_pledge.js index 9291d82e..e1df29f3 100644 --- a/static/js/reconcile_pledge.js +++ b/static/js/reconcile_pledge.js @@ -9,43 +9,59 @@ $j(function() { // when they fix it, revert to original styling and reactivate button $j().ready(function() { + // cache these to speed things up var inputbox = $j('#id_preapproval_amount'); var submitbutton = $j('#pledgesubmit'); + var canonicalize = function(amt) { + // takes an input button from the premiums list + // finds the premium amount its associated the span class + // converts to usable integer form and returns + amt = amt.siblings('span.menu-item-price').html(); + amt = amt.split('$')[1]; + amt = parseInt(amt); + return amt; + } + + var mayday = function() { + // highlights pledge box and submit button in alert color + // disables submit button and overwrites with help text + inputbox.css({'border-color': '#e35351', 'background-color': '#e35351', 'color': 'white'}); + submitbutton.css({'background-color': '#e35351', 'cursor': 'default', 'font-weight': 'normal', 'font-size': '15px'}); + submitbutton.val("You must pledge at least $"+amount+" for that premium"); + submitbutton.attr('disabled', 'disabled'); + } + + var allclear = function() { + // returns pledge box and submit button to conventional colors + // enables submit button and rewrites with original text + inputbox.css({'border-color': '#8dc63f', 'background-color': 'white', 'color': '#3d4e53'}); + submitbutton.css({'background-color': '#8dc63f', 'cursor': 'pointer', 'font-weight': 'bold', 'font-size': '17px'}); + submitbutton.val("Modify Pledge"); + submitbutton.removeAttr('disabled'); + } + $j('#premiums_list input').on("click", function() { - amount = $j(this).siblings('span.menu-item-price').html(); - amount = amount.split('$')[1]; - amount = parseInt(amount); + // when user clicks a premium, ensure it is compatible with the pledge box amount + amount = canonicalize($j(this)); current = inputbox.val(); if (current