Bug 623793, l10n error bonanza

This commit is contained in:
Matt Claypotch 2011-01-10 22:04:58 -08:00
Родитель d4ab0bfcd5
Коммит 9bb6f25591
4 изменённых файлов: 118 добавлений и 81 удалений

Просмотреть файл

@ -32,8 +32,10 @@
Would you like to save your changes before switching locales?
{% endtrans %}
</p>
<div class="modal-actions">
<button id="l10n-save-changes" class="button">{{ _('Save Changes') }}</button>
<button id="l10n-discard-changes" class="button">{{ _('Discard Changes') }}</button>
{{ _('or') }} <a id="l10n-cancel-changes" href="#">{{ _('Cancel') }}</a>
</div>
</div>
</div>

Просмотреть файл

@ -3122,6 +3122,12 @@ input.ui-autocomplete-loading {
background-position: center center;
}
.modal-actions.ajax-loading {
background-image: url(../../img/zamboni/loading-white.gif);
background-repeat: no-repeat;
background-position: right center;
}
#popup-staging .popup {
display: none;
}
@ -3236,6 +3242,12 @@ input.ui-autocomplete-loading {
cursor: help;
}
.errorlist .l10n {
cursor: pointer;
}
.errorlist .l10n:hover {
text-decoration: underline;
}
/**
* Firefox 4 Beta promo styles
* TODO remove these when promo is pulled

Просмотреть файл

@ -218,6 +218,7 @@ function addonFormSubmit() {
document.location = baseurl();
}
truncateFields();
annotateLocalizedErrors(parent_div);
if (!parent_div.find(".errorlist").length) {
var e = $(format('<b class="save-badge">{0}</b>',
[gettext('Changes Saved')]))

Просмотреть файл

@ -15,6 +15,7 @@ $(document).ready(function () {
currentLocale = dl,
unsavedModalMsg = $('#modal-l10n-unsaved .msg').html(),
unsavedModal = $('#modal-l10n-unsaved').modal(),
modalActions = $(".modal-actions", unsavedModal),
translations = {}; //hold the initial values of the fields to check for changes
$(".primary").delegate(".trans input, .trans textarea", "change keyup paste blur", checkTranslation);
@ -81,12 +82,6 @@ $(document).ready(function () {
}
}
var localePopup = $("#locale-popup").popup("#change-locale", {
pointTo: "#change-locale",
width: 200,
callback: function() {
showExistingLocales();
$("#locale-popup").delegate('a.remove', 'click', function (e) {
e.preventDefault();
e.stopPropagation();
@ -100,10 +95,13 @@ $(document).ready(function () {
}
showExistingLocales();
});
$("#locale-popup").delegate('a:not(.remove)', 'click', function (e) {
$(".primary").delegate(".errorlist .l10n", "click", switchLocale);
function switchLocale(e) {
e.preventDefault();
$tgt = $(this);
var new_locale = $tgt.attr("href").substring(1);
var new_locale = $tgt.attr("data-lang") ||$tgt.attr("href").substring(1);
var unsaved = $("form .trans .unsaved");
if (unsaved.length) {
unsavedModal.children(".msg")
@ -113,25 +111,31 @@ $(document).ready(function () {
var unsavedForms = $('form:has(.trans .unsaved)');
var numFormsLeft = unsavedForms.length;
var erroredForms = 0;
modalActions.addClass("ajax-loading");
modalActions.find("button").addClass("disabled");
unsavedForms.each(function() {
var $form = $(this);
$.post($form.attr('action'), $form.serialize(), function(d) {
$.ajax({
url: $form.attr('action'),
type: "post",
data: $form.serialize(),
error: function() {
modalActions.removeClass("ajax-loading");
},
success: function(d) {
var $resp = $(d);
if ($form.attr('id') && $resp.find('#' + $form.attr('id'))) {
if ($form.attr('id') && $resp.find('#' + $form.attr('id')).length) {
$resp = $resp.find('#' + $form.attr('id'));
}
// Add locale names to error messages
$resp.find(".errorlist li[data-lang]:not(.l10n)").each(function() {
var err = $(this),
t = err.text(),
l = $(format("#locale-popup [href$={0}]", [err.attr('data-lang')])).first().text();
err.text(format("{0}: ",[l])+t).addClass("l10n");
});
annotateLocalizedErrors($resp);
numFormsLeft--;
if ($resp.find(".errorlist").length) { //display errors if they occur
$form.html($resp.html());
updateLocale();
if ($resp.find(format(".errorlist li[data-lang={0}]", currentLocale)).length) {
erroredForms++;
}
} else { //clean up the errors we inserted
popuplateTranslations($form);
$form.find(".unsaved").removeClass("unsaved");
@ -146,9 +150,12 @@ $(document).ready(function () {
updateLocale(new_locale);
}
}
});
});
modalActions.removeClass("ajax-loading");
modalActions.find("button").removeClass("disabled");
unsavedModal.hideMe();
}
});
});
});
$("#l10n-discard-changes").click(function () {
$('.trans .unsaved').remove();
@ -162,8 +169,14 @@ $(document).ready(function () {
updateLocale(new_locale);
}
localePopup.hideMe();
});
}
var localePopup = $("#locale-popup").popup("#change-locale", {
pointTo: "#change-locale",
width: 200,
callback: function() {
showExistingLocales();
$("#locale-popup").delegate('a:not(.remove)', 'click', switchLocale);
return true;
}
});
@ -227,3 +240,12 @@ $(document).ready(function () {
};
updateLocale();
});
function annotateLocalizedErrors($el) {
$el.find(".errorlist li[data-lang]:not(.l10n)").each(function() {
var err = $(this),
t = err.text(),
l = $(format("#locale-popup [href$={0}]", [err.attr('data-lang')])).first().text();
err.text(format("{0}: ",[l])+t).addClass("l10n");
});
}