referral: Show feedback immediately and don't show errors

(imported from commit 3bf6071c4fdeeaa50ea05c60b4bf0244c78ebeb0)
This commit is contained in:
Zev Benjamin 2013-08-07 14:31:52 -04:00
parent c4e168254c
commit 126fcd42d7
3 changed files with 18 additions and 11 deletions

View File

@ -16,7 +16,16 @@ var placeholder_invitees = ['guglielmo@marconi.com',
'hertha@ayrton.com' 'hertha@ayrton.com'
]; ];
var last_granted;
var last_used;
exports.update_state = function (granted, used) { exports.update_state = function (granted, used) {
if (last_granted === granted && last_used === used) {
return;
}
last_granted = granted;
last_used = used;
if (granted <= 0) { if (granted <= 0) {
$("#share-the-love").hide(); $("#share-the-love").hide();
} else { } else {
@ -55,7 +64,7 @@ exports.update_state = function (granted, used) {
function show_and_fade_elem(elem) { function show_and_fade_elem(elem) {
elem.stop(); elem.stop();
elem.css({opacity: 100}); elem.css({opacity: 100});
elem.show().delay(4000).fadeOut(1000); elem.show().delay(4000).fadeOut(1000, ui.resize_page_components);
} }
$(function () { $(function () {
@ -67,14 +76,16 @@ $(function () {
url: "/json/refer_friend", url: "/json/refer_friend",
dataType: "json", dataType: "json",
data: { email: $("#referral-form input").val() }, data: { email: $("#referral-form input").val() },
success: function () {
show_and_fade_elem($("#tell-a-friend-success"));
$("#referral-form input").val('');
},
error: function () { error: function () {
show_and_fade_elem($("#tell-a-friend-error")); // We ignore errors from the server because
// they're unlikely and we'll get an email either
// way
} }
}); });
show_and_fade_elem($("#tell-a-friend-success"));
$("#referral-form input").val('');
exports.update_state(last_granted, last_used + 1);
} }
}); });

View File

@ -2288,6 +2288,6 @@ div.edit_bot {
margin-bottom: 0; margin-bottom: 0;
} }
#tell-a-friend-success, #tell-a-friend-error { #tell-a-friend-success {
display: none; display: none;
} }

View File

@ -35,10 +35,6 @@
<p>Our engineers will artisanally handcraft <p>Our engineers will artisanally handcraft
and send them an invitation.</p> and send them an invitation.</p>
</div> </div>
<div id="tell-a-friend-error" class="alert alert-error">
Oops. Something went wrong. Don't worry,
we won't charge you an invite for our mistake.
</div>
<div class="still-have-invites"> <div class="still-have-invites">
{# Many of these values are set by the initialization code in referral.js #} {# Many of these values are set by the initialization code in referral.js #}
<form id="referral-form"> <form id="referral-form">