From d0e88bac58e31b8ff4cc55c30fa8be8a37e1e621 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Thu, 3 Aug 2017 00:15:38 +0000 Subject: [PATCH] Turns off/on spinner for membership based on choices in functions. --- Connections/database_functions.php | 12 ++++++------ js/transaction.js | 28 +++++++++++++++++++++++++--- json/transaction.php | 13 ++++++++++++- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Connections/database_functions.php b/Connections/database_functions.php index 8f7b4a6..f2f7ec2 100644 --- a/Connections/database_functions.php +++ b/Connections/database_functions.php @@ -72,24 +72,24 @@ May add capability to adjust limits based on status, but that can get complex if define("SWEAT_EQUITY_LIMIT",100); define("MAX_BIKE_EARNED",1); define("VOLUNTEER_HOUR_VALUE",8); +define("STAND_TIME_VALUE",10); define("VOLUNTEER_DISCOUNT",25); define("SPECIAL_VOLUNTEER_HOURS_QUALIFICATION",100); define("SPECIAL_VOLUNTEER_DISCOUNT",50); -define("STAND_TIME_VALUE",10); // Determines the behaviour of Bicycles (transaction_type_id) for volunteer to earn-a-bike purchases define("EARN_A_BIKE_LIMIT",1); // Map transaction_type_id for transaction to benefits; // Bicycles and Stand Time are special transaction types for volunteers, but they should still be mapped if benefits are desired. -$transactions_with_volunteer_benefits = array( "Bicycles", - "Stand Time", - "Used Parts" +$transactions_with_volunteer_benefits = array( "Bicycles" => true, + "Stand Time" => true, + "Used Parts" => true ); // Volunteer benefits take priority over membership benefits if patron qualifies for both -$transactions_with_membership_benefits = array( "Used Parts", - "New Parts" +$transactions_with_membership_benefits = array( "Used Parts" => true, + "New Parts" => true ); /******* diff --git a/js/transaction.js b/js/transaction.js index 295171d..2519063 100644 --- a/js/transaction.js +++ b/js/transaction.js @@ -918,13 +918,35 @@ $(function() { $("#redeemable_hours").hide(); $(".ui-spinner").hide(); } - } + } + + // Determine membership benefits of current transaction + $.post("json/transaction.php", { transaction_benefits: 1 }, function (data) { + var obj = $.parseJSON(data); + + // Volunteer benefits + if ( obj.transactions_with_volunteer_benefits[$("#trans_type_info").text()] === true ) { + if ($("#redeemable_hours").data("ui-spinner")) + $("#redeemable_hours").spinner("enable"); + } else { + if ($("#redeemable_hours").data("ui-spinner")) + $("#redeemable_hours").spinner("disable"); + } + + // Membership benefits + for (var n in obj.transactions_with_membership_benefits) { + //console.log(obj.transactions_with_volunteer_benefits[n]); + } + + }); + // control spinner behavior of transaction_type "Stand Time" if ($("#trans_type_info").text() === "Stand Time" && $("#stand_time_total").is(":empty")) { $("#redeemable_hours").spinner("disable"); } else if ($("#trans_type_info").text() === "Stand Time") { - $("#redeemable_hours").spinner("enable"); - } + if ($("#redeemable_hours").data("ui-spinner")) + $("#redeemable_hours").spinner("enable"); + } }); // volunteers post diff --git a/json/transaction.php b/json/transaction.php index a8bc975..47ee6fd 100644 --- a/json/transaction.php +++ b/json/transaction.php @@ -158,7 +158,18 @@ $stand_time_value = STAND_TIME_VALUE; $result = (object)array_merge((array)$result, (array)$result2, (array)$result3); echo json_encode($result); - } // Volunteer Benefits + } // end Volunteer Benefits + + // Volunteer Benefits + if (isset($_POST['transaction_benefits'])) { + + $result = ["transactions_with_volunteer_benefits" => $transactions_with_volunteer_benefits, + "transactions_with_membership_benefits" => $transactions_with_membership_benefits + ]; + echo json_encode($result); + + + } // end transaction_benefits // Stand Time if (isset($_POST['stand_time'])) {