Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
slow down the polling and time nicer with the edit change message (bu…
Browse files Browse the repository at this point in the history
…g 614746)

add a cache buster to the url when it cleans
stop it polling on clicking edit
  • Loading branch information
Andy McKay committed Jan 13, 2011
1 parent e7a5c4c commit 1ab930e
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions media/js/zamboni/devhub.js
Expand Up @@ -220,12 +220,6 @@ function addonFormSubmit() {
parent_div.find(".item").removeClass("loaded").addClass("loading");
var scrollBottom = $(document).height() - $(document).scrollTop();

if(parent_div.is('#edit-addon-media')) {
if($('input[name=icon_type]:checked').val().match(/^image\//)) {
setTimeout(checkImageStatus, 1000);
}
}

$.post(parent_div.find('form').attr('action'),
$(this).serialize(), function(d) {
parent_div.html(d).each(addonFormSubmit);
Expand All @@ -235,19 +229,20 @@ function addonFormSubmit() {
$(document).scrollTop($(document).height() - scrollBottom);
truncateFields();
annotateLocalizedErrors(parent_div);
if(parent_div.is('#edit-addon-media')) {
imageStatus.poller = setTimeout(imageStatus.check, 2500);
hideSameSizedIcons();
}

if (!parent_div.find(".errorlist").length) {
var e = $(format('<b class="save-badge">{0}</b>',
[gettext('Changes Saved')]))
.appendTo(parent_div.find('h3').first());
setTimeout(function(){
e.css('opacity', 0);
setTimeout(function(){ e.remove(); }, 1500);
setTimeout(function(){ e.remove(); }, 200);
}, 2000);
}

if(parent_div.is('#edit-addon-media')) {
hideSameSizedIcons();
}
});
});
z.refreshL10n();
Expand Down Expand Up @@ -276,6 +271,9 @@ function initEditAddon() {
}
$(this).each(addonFormSubmit);
});
if(parent_div.is('#edit-addon-media')) {
imageStatus.stop();
}
})(parent_div, a);

return false;
Expand Down Expand Up @@ -1128,25 +1126,37 @@ function initCompatibility() {
});
}

function checkImageStatus() {
$.getJSON($('#edit-addon-media').attr('data-checkurl'),
function(json) {
var node = $('#edit-addon-media');
if (json['overall']) {
node.find('b.save-badge').remove();
node.find('img').each(function() {
$(this).attr('src', $(this).attr('src'));
})
} else {
if (!node.find('b.save-badge').length) {
$(format('<b class="save-badge">{0}</b>',
[gettext('Image changes being processed.')]))
.appendTo(node.find('h3').first());
var imageStatus = {
poller: null,
node: $('#edit-addon-media'),
stop: function () {
window.clearTimeout(this.poller);
imageStatus.node.find('b.save-badge').remove();
imageStatus.node.find('img').each(function() {
var buster = $(this).attr('src');
if (buster.indexOf('?') > -1) {
buster = buster + '&' + new Date().getTime();
}
$(this).attr('src', buster);
})
},
check: function() {
var self = imageStatus;
$.getJSON(self.node.attr('data-checkurl'),
function(json) {
if (json['overall']) {
self.stop();
} else {
if (!self.node.find('b.image-message').length) {
$(format('<b class="save-badge image-message">{0}</b>',
[gettext('Image changes being processed')]))
.appendTo(self.node.find('h3').first());
}
self.poller = window.setTimeout(self.check, 2500);
}
setTimeout(checkImageStatus, 1000);
}
}
);
);
}
}

function multipartUpload(form, onreadystatechange) {
Expand Down

0 comments on commit 1ab930e

Please sign in to comment.