settings: Update name and gravatar without a reload.

(imported from commit 961c9f64d7c39b4345ece036062854e8d474d2c0)
This commit is contained in:
Jessica McKellar 2012-11-05 17:51:27 -05:00
parent 7dcd8a5a3c
commit 4cad5f6e96
4 changed files with 47 additions and 7 deletions

View File

@ -84,9 +84,9 @@ var people_list = [
<div class="row"> <div class="row">
<div class="span3 sidebar-nav affix"> <div class="span3 sidebar-nav affix">
<span> <span>
<img class="img-rounded hidden-phone" <img class="img-rounded hidden-phone gravatar-profile"
src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=60" /> src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=60" />
<img class="img-rounded visible-phone" <img class="img-rounded visible-phone gravatar-profile"
src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=30" /> src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=30" />
</span> </span>
<span class="my_fullname">{{ user_profile.full_name }}</span> <span class="my_fullname">{{ user_profile.full_name }}</span>

View File

@ -25,8 +25,8 @@
</div> </div>
<div id="Photo"> <div id="Photo">
<label>Photo</label> <label>Photo</label>
<img class="img-rounded" src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=80"/> <img class="img-rounded gravatar-profile" src="https://secure.gravatar.com/avatar/{{ email_hash }}?d=identicon&s=80"/>
<a href="https://en.gravatar.com/emails" target="_blank">(change at Gravatar.com)</a> <a href="https://en.gravatar.com/emails" target="_blank" onclick="wait_for_gravatar();">(change at Gravatar.com)</a>
<br /> <br />
</div> </div>
<br /><br /> <br /><br />

View File

@ -42,7 +42,7 @@ var globals =
// ui.js // ui.js
+ ' register_onclick hide_email show_email' + ' register_onclick hide_email show_email'
+ ' report_error report_success report_message clicking mouse_moved' + ' report_error report_success report_message clicking mouse_moved'
+ ' userinfo_currently_popped' + ' userinfo_currently_popped update_gravatars'
// zephyr.js // zephyr.js
+ ' message_array message_dict get_updates_params' + ' message_array message_dict get_updates_params'

View File

@ -384,9 +384,12 @@ $(function () {
success: function (resp, statusText, xhr, form) { success: function (resp, statusText, xhr, form) {
var message = "Updated settings!"; var message = "Updated settings!";
var result = $.parseJSON(xhr.responseText); var result = $.parseJSON(xhr.responseText);
if ((result.full_name !== undefined) || (result.short_name !== undefined)) {
message = "Updated settings! You will need to reload the page for your changes to take effect."; if (result.full_name !== undefined) {
$(".my_fullname").text(result.full_name);
} }
update_gravatars();
settings_status.removeClass(status_classes) settings_status.removeClass(status_classes)
.addClass('alert-success') .addClass('alert-success')
.text(message).stop(true).fadeTo(0,1); .text(message).stop(true).fadeTo(0,1);
@ -455,3 +458,40 @@ $(function () {
} }
}); });
}); });
function update_gravatars() {
$.each($(".gravatar-profile"), function(index, profile) {
$(this).attr('src', $(this).attr('src') + '?' + $.now());
});
}
function poll_for_gravatar_update(start_time, url) {
var updated = false;
$.ajax({
type: "HEAD",
url: url,
async: false,
cache: false,
success: function (resp, statusText, xhr) {
if (new Date(xhr.getResponseHeader('Last-Modified')) > start_time) {
update_gravatars();
updated = true;
}
}
});
// Give users 5 minutes to update their picture on gravatar.com,
// during which we try to auto-update their image on our site. If
// they take longer than that, we'll update when they press the
// save button.
if (!updated && (($.now() - start_time) < 1000 * 60 * 5)) {
setTimeout(function() {
poll_for_gravatar_update(start_time, url);
}, 1500);
}
}
function wait_for_gravatar() {
poll_for_gravatar_update($.now(), $(".gravatar-profile").attr("src"));
}