Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
bug 1260197 - remove logging from wiki-edit.js and disable form on aj…
Browse files Browse the repository at this point in the history
…ax submits
  • Loading branch information
dchukhin committed Aug 22, 2016
1 parent 821c173 commit bef39a6
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions kuma/static/js/wiki-edit.js
Expand Up @@ -475,8 +475,8 @@

// save and edit attempts ajax submit
$('.btn-save-and-edit').on('click', function(event) {
// TODO: disable form
console.log('save and edit triggered');
// disable form
$('#wiki-page-edit').attr('disabled', true);

// give user feedback
var saveNotification = mdn.Notifier.growl('Saving changes…', { duration: 0 });
Expand All @@ -498,7 +498,6 @@
// get form data
var formData = $form.serialize();
var formURL = window.location.href; // submits to self
console.log('posting this data: ', formData)

$.ajax({
url : formURL + '?async',
Expand All @@ -507,38 +506,32 @@
dataType : 'html',
success: function(data, textStatus, jqXHR) {
// server came back 200
console.log('data is: ', data);
// console.log(textStatus);
// console.log(jqXHR);
// was there an error?
// was there an error, or did the session expire?
var $parsedData = $($.parseHTML(data));
var $responseErrors = $parsedData.find('.errorlist');
console.log('$responseErrors: ', $responseErrors);
var $responseLoginRequired = $parsedData.find('#login');
// If there are errors, saveNotification() for each of them
if($responseErrors.length) {
console.log('error found');
if ($responseErrors.length) {
var liErrors = $responseErrors.find('li')
for (var i = 0; i < liErrors.length; i++) {
saveNotification.error(liErrors[i])
}
//$form.submit();
}
else {
console.log('no errors - sucesss!');
// Check if the session has timed out
} else if ($responseLoginRequired.length) {
saveNotification.error('Publishing failed. You are not currently signed in. Please use a new tab to sign in and try publishing again.')
} else {
// assume it went well
saveNotification.success(gettext('Changes saved.'), 2000);

// We also need to update the form's current_rev to
// avoid triggering a conflict, since we just saved in
// the background.
console.log('data is: ', data)
var responseData = JSON.parse(data)
if (responseData['error'] == true) {
saveNotification.error(responseData['error_message'])
} else {
var responseRevision = JSON.parse(data)['new_revision_id'];
console.log('responseRevision: ', responseRevision);
// TODO: why are there multiple <input id="id_current_rev">s?
$("input[id=id_current_rev]").val(responseRevision)

// Clear the review comment
Expand All @@ -548,25 +541,20 @@
$form.trigger('mdn:save-success');
}

// Re-enable the form; it gets disabled to prevent double-POSTs
$form.data('disabled', false).removeClass('disabled');
}
// Re-enable the form; it gets disabled to prevent double-POSTs
$form.attr('disabled', false);
},
error: function(jqXHR, textStatus, errorThrown) {
//if fails
// console.log(jqXHR);
// console.log(jqXHR.status);
// console.log(textStatus);
// console.log(errorThrown);
// Try to display the error that comes back from the server
try {
var errorMessage = JSON.parse(jqXHR['responseText'])['error_message']
} catch (err) {
errorMessage = "Publishing failed. Please copy and paste your changes into a safe place and try submitting the form using the 'Publish' button.";
}
saveNotification.error(errorMessage);
// saveNotification.error(msg, {closable: true, duration: 0});

// Re-enable the form; it gets disabled to prevent double-POSTs
$form.attr('disabled', false);
// save draft
}
});
Expand Down

0 comments on commit bef39a6

Please sign in to comment.