mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2026-09-03 02:11:38 -04:00
Adds performance improvements for volunteer_benefits closing #46
* Major changes, will test more, but appears to be working very well.
This commit is contained in:
+120
-89
@@ -88,50 +88,58 @@ $(function(){
|
||||
} );
|
||||
|
||||
|
||||
// could have done this in php, but this separates out the view logic
|
||||
var d = new Date();
|
||||
volunteer_status();
|
||||
|
||||
var membership_ids;
|
||||
var last_index = $("#shop_log tr").length;
|
||||
// could have done this in php, but this separates out the view logic
|
||||
var membership_ids, volunteer_ids;
|
||||
var last_index = $("#shop_log tr[id]").length;
|
||||
if (last_index) {
|
||||
last_index = last_index -1;
|
||||
$.each($("#shop_log tr"), function(index) {
|
||||
last_index = last_index - 1;
|
||||
$.each($("#shop_log tr[id]"), function(index) {
|
||||
|
||||
if (this.id) {
|
||||
if (this.id) {
|
||||
|
||||
var id = this.id;
|
||||
var id = this.id;
|
||||
|
||||
// 2 tr for first created login
|
||||
if (last_index <= 2) {
|
||||
membership_ids = "contact_id=" + id;
|
||||
}
|
||||
else if (!membership_ids) {
|
||||
membership_ids = "(contact_id=" + id + " OR ";
|
||||
} else if ( index === last_index) {
|
||||
membership_ids += "contact_id=" + id + ")";
|
||||
} else {
|
||||
membership_ids += "contact_id=" + id + " OR ";
|
||||
}
|
||||
}
|
||||
if (last_index <= 1) {
|
||||
membership_ids = "contact_id=" + id;
|
||||
}
|
||||
else if (!membership_ids) {
|
||||
membership_ids = "(contact_id=" + id + " OR ";
|
||||
} else if ( index === last_index) {
|
||||
membership_ids += "contact_id=" + id + ")";
|
||||
} else {
|
||||
membership_ids += "contact_id=" + id + " OR ";
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
if (membership_ids) {
|
||||
volunteer_ids = membership_ids.replace(/contact_id/g,"contacts.contact_id");
|
||||
}
|
||||
}
|
||||
|
||||
var d = new Date();
|
||||
volunteer_status(volunteer_ids);
|
||||
membership_status(membership_ids);
|
||||
|
||||
// volunteer status
|
||||
function volunteer_status() {
|
||||
|
||||
$.each($("#shop_log tr"), function() {
|
||||
|
||||
if (this.id) {
|
||||
var id = this.id;
|
||||
function volunteer_status(contacts) {
|
||||
|
||||
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: this.id }, function (data) {
|
||||
|
||||
var all_members_obj; //reuse this object
|
||||
|
||||
if (contacts) {
|
||||
|
||||
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: contacts }, function (data) {
|
||||
|
||||
all_members_obj = $.parseJSON(data);
|
||||
|
||||
$.each(all_members_obj, function() {
|
||||
|
||||
var year = d.getFullYear();
|
||||
var bikes_earned = 0;
|
||||
var volunteer_hours_redeemed = 0;
|
||||
var obj = $.parseJSON(data);
|
||||
var obj = this;
|
||||
|
||||
|
||||
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
|
||||
if (obj.volunteer) {
|
||||
@@ -153,7 +161,7 @@ $(function(){
|
||||
var volunteer_with_redeemed_hours_at_zero = obj.current_year_volunteer_hours - vhr;
|
||||
|
||||
if (obj.contact_id) {
|
||||
|
||||
|
||||
if (obj.volunteer_hours && obj.volunteer_hours !== '0') {
|
||||
|
||||
if (volunteer_with_redeemed_hours_at_zero !== 0) {
|
||||
@@ -178,7 +186,7 @@ $(function(){
|
||||
$('.update_interests a').hover( function(e){ $(this).css("color",e.type === "mouseenter"?"blue":"#1b691e");});
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
title = obj.normal_full_name + "\r\n" +
|
||||
@@ -196,8 +204,8 @@ $(function(){
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
} else {
|
||||
|
||||
var name = $("#" + id + " td a[href*='individual']").text();
|
||||
var name_obj = name.trim().split(", ");
|
||||
name = name_obj[1] + " " + name_obj[0];
|
||||
@@ -214,12 +222,37 @@ $(function(){
|
||||
|
||||
$('.update_interests a').css({color: "#1b691e", textDecoration: "none", cursor: "crosshair"});
|
||||
$('.update_interests a').hover( function(e){ $(this).css("color",e.type === "mouseenter"?"blue":"#1b691e");});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}); // each all_members_obj
|
||||
}); // post volunteer benefits
|
||||
} // if this is a volunteer
|
||||
|
||||
// not a current volunteer within the last 365 days, or never has been a volunteer
|
||||
$(".volunteer_hours:not([title])").prevAll(".existing_shop_user")
|
||||
.children().each( function() {
|
||||
|
||||
var name = $(this).text();
|
||||
var name_obj = name.trim().split(", ");
|
||||
name = name_obj[1] + " " + name_obj[0];
|
||||
|
||||
}); // post volunteer benefits
|
||||
} // if id
|
||||
}); // each tr
|
||||
var id = this.href.split("=")[1];
|
||||
|
||||
var title = name + "\r\n" +
|
||||
"Volunteer Hours for last 365 days: None" + "\r\n";
|
||||
|
||||
$(".volunteer_hours_" + id).
|
||||
html("<span class='update_interests'><a href='./contact_add_edit_select.php?contact_id=" +
|
||||
id +
|
||||
"'>Update Interests</a></span>").
|
||||
parent().css({backgroundColor: "rgb(190, 199, 204)", textAlign: "center", cursor: "cell"}).
|
||||
prop("title",title).css({textAlign: "center"});
|
||||
|
||||
$('.update_interests a').css({color: "#1b691e", textDecoration: "none", cursor: "crosshair"});
|
||||
$('.update_interests a').hover( function(e){ $(this).css("color",e.type === "mouseenter"?"blue":"#1b691e");});
|
||||
|
||||
}); // .each not a current volunteer
|
||||
|
||||
} // function volunteer_status
|
||||
|
||||
@@ -230,58 +263,56 @@ $(function(){
|
||||
var expiration_date;
|
||||
var all_members_obj; //reuse this object
|
||||
var membership_transaction;
|
||||
|
||||
|
||||
|
||||
//$.each($("#shop_log tr"), function() {
|
||||
|
||||
if (contacts) {
|
||||
|
||||
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contacts }, function (data) {
|
||||
|
||||
all_members_obj = $.parseJSON(data);
|
||||
|
||||
$.each(all_members_obj, function() {
|
||||
|
||||
var membership_obj = this;
|
||||
|
||||
var title = membership_obj.normal_full_name + "\r\n" +
|
||||
"expiration: " + membership_obj.expiration_date;
|
||||
|
||||
|
||||
if (membership_obj.expiration_date) {
|
||||
var exp = membership_obj.expiration_date;
|
||||
expiration_date = new Date(exp.split("-").toString());
|
||||
if (d < expiration_date) {
|
||||
membership_transaction = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof membership_obj.expiration_date && membership_obj.expiration_date !== undefined) {
|
||||
if (contacts) {
|
||||
|
||||
var exp = membership_obj.expiration_date;
|
||||
expiration_date = new Date(exp.split("-").toString());
|
||||
|
||||
// expired membership
|
||||
if (d >= expiration_date) {
|
||||
$(".paid_membership_" + membership_obj.contact_id).html("Expired").
|
||||
parent().css({backgroundColor: "red", textAlign: "center", cursor: "cell", textDecoration: "none"}).prop("title",title);
|
||||
|
||||
// paid membership
|
||||
} else if (d < expiration_date) {
|
||||
$(".paid_membership_" + membership_obj.contact_id).html("Current").
|
||||
parent().css({backgroundColor: "green", textAlign: "center", cursor: "cell"}).prop("title",title).css({textAlign: "center"});
|
||||
|
||||
} // paid membership
|
||||
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contacts }, function (data) {
|
||||
|
||||
all_members_obj = $.parseJSON(data);
|
||||
|
||||
$.each(all_members_obj, function() {
|
||||
|
||||
var membership_obj = this;
|
||||
|
||||
var title = membership_obj.normal_full_name + "\r\n" +
|
||||
"expiration: " + membership_obj.expiration_date;
|
||||
|
||||
}
|
||||
|
||||
if (membership_obj.expiration_date) {
|
||||
var exp = membership_obj.expiration_date;
|
||||
expiration_date = new Date(exp.split("-").toString());
|
||||
if (d < expiration_date) {
|
||||
membership_transaction = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof membership_obj.expiration_date && membership_obj.expiration_date !== undefined) {
|
||||
|
||||
var exp = membership_obj.expiration_date;
|
||||
expiration_date = new Date(exp.split("-").toString());
|
||||
|
||||
}); // each all_members_obj
|
||||
}); // end if this a paid member
|
||||
|
||||
// never been a member
|
||||
$(".paid_membership:not([title])").css({cursor: "not-allowed"});
|
||||
|
||||
} // if contacts
|
||||
// expired membership
|
||||
if (d >= expiration_date) {
|
||||
$(".paid_membership_" + membership_obj.contact_id).html("Expired").
|
||||
parent().css({backgroundColor: "red", textAlign: "center", cursor: "cell", textDecoration: "none"}).prop("title",title);
|
||||
|
||||
// paid membership
|
||||
} else if (d < expiration_date) {
|
||||
$(".paid_membership_" + membership_obj.contact_id).html("Current").
|
||||
parent().css({backgroundColor: "green", textAlign: "center", cursor: "cell"}).prop("title",title).css({textAlign: "center"});
|
||||
|
||||
} // paid membership
|
||||
|
||||
}
|
||||
|
||||
}); // each all_members_obj
|
||||
}); // end if this a paid member
|
||||
|
||||
// never been a member
|
||||
$(".paid_membership:not([title])").css({cursor: "not-allowed"});
|
||||
|
||||
} // if contacts
|
||||
} // function membership status
|
||||
|
||||
});
|
||||
+20
-9
@@ -874,6 +874,7 @@ $(function() {
|
||||
|
||||
amount.prop("disabled","");
|
||||
var membership_obj; //reuse this object
|
||||
|
||||
if (this.value !== "no_selection") {
|
||||
var expiration_date;
|
||||
|
||||
@@ -882,12 +883,19 @@ $(function() {
|
||||
var contact_id = "contact_id=" + this.value;
|
||||
$.post("json/transaction.php", { membership_benefits: 1, contact_id: contact_id }, function (data) {
|
||||
|
||||
var membership_objs = $.parseJSON(data);
|
||||
membership_obj = membership_objs[0];
|
||||
var membership_objs = $.parseJSON(data);
|
||||
|
||||
/*
|
||||
Weird hack, before improving performance #46, there was always a property for membership_obj,
|
||||
membership_discount:10, which just allowed the code to work, now it is empty when a patron
|
||||
actually is not a paid member, so this creates that obj & property if that is the case.
|
||||
*/
|
||||
membership_obj = membership_objs[0] || { membership_discount: 10 };
|
||||
|
||||
var title = membership_obj.normal_full_name + "\r\n" +
|
||||
membership_obj.email + "\r\n" +
|
||||
membership_obj.phone + "\r\n" +
|
||||
"expiration: " + membership_obj.expiration_date;
|
||||
membership_obj.email + "\r\n" +
|
||||
membership_obj.phone + "\r\n" +
|
||||
"expiration: " + membership_obj.expiration_date;
|
||||
|
||||
$("#membership_discount").empty();
|
||||
$("#membership_discount_price").empty();
|
||||
@@ -1023,13 +1031,16 @@ $(function() {
|
||||
$("#original_price").text(price);
|
||||
|
||||
// How many hours does this volunteer have?
|
||||
$("#redeemable_hours").val("");
|
||||
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: this.value }, function (data) {
|
||||
$("#redeemable_hours").val("");
|
||||
var contact_id = "contacts.contact_id=" + this.value;
|
||||
$.post("json/transaction.php", { volunteer_benefits: 1, contact_id: contact_id }, function (data) {
|
||||
|
||||
var year = d.getFullYear();
|
||||
var bikes_earned = 0;
|
||||
var volunteer_hours_redeemed = 0;
|
||||
var obj = $.parseJSON(data);
|
||||
var volunteer_hours_redeemed = 0;
|
||||
|
||||
var volunteer_objs = $.parseJSON(data);
|
||||
var obj = volunteer_objs[0];
|
||||
|
||||
var volunteer = "", remaining = 0, vhr = "", max_bikes_earned = 0;
|
||||
if (obj.volunteer) {
|
||||
|
||||
Reference in New Issue
Block a user