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

Commit

Permalink
bug 1260197 - handle save&keep editing edits without errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dchukhin committed Aug 22, 2016
1 parent 19d4328 commit 889e145
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
29 changes: 17 additions & 12 deletions kuma/static/js/wiki-edit.js
Expand Up @@ -494,8 +494,7 @@
// get form data
var formData = $form.serialize();
var formURL = window.location.href; // submits to self
//console.log(formData);
//console.log(formURL);
console.log('posting this data: ', formData)

// ajax submit
$.ajax({
Expand All @@ -505,30 +504,34 @@
dataType : 'html',
success: function(data, textStatus, jqXHR) {
// server came back 200
console.log(data, data);
console.log('data is: ', data);
// console.log(textStatus);
// console.log(jqXHR);
// was there an error?
var $parsedData = $($.parseHTML(data));
//console.log('parsedData:');
//console.log($parsedData);
var $responseErrors = $parsedData.filter('.errorlist');
var $responseErrors = $parsedData.find('.errorlist');
console.log('$responseErrors: ', $responseErrors);
// If there are errors, saveNotification() for each of them
if($responseErrors.length) {
console.log('error found');
saveNotification.error('uh-oh');
var liErrors = $responseErrors.find('li')
for (var i = 0; i < liErrors.length; i++) {
saveNotification.error(liErrors[i])
}
//$form.submit();
}
else {
console.log('no errors - sucess!');
console.log('no errors - sucesss!');
// 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.
var responseRevision = $parsedData.filter('#id_current_rev').val();
console.log(responseRevision);
$('#id_current_rev').val(responseRevision);
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
$('#id_comment').val('');
Expand All @@ -546,8 +549,10 @@
// console.log(jqXHR.status);
// console.log(textStatus);
// console.log(errorThrown);
var msg = "Publishing failed. Please copy and paste your changes into a safe place and try submitting the form using the 'Publish' button.";

saveNotification.error('uh-oh', {closable: true, duration: 0});
saveNotification.error(msg);
// saveNotification.error(msg, {closable: true, duration: 0});

// save draft
}
Expand Down
12 changes: 5 additions & 7 deletions kuma/wiki/views/edit.py
Expand Up @@ -152,7 +152,7 @@ def edit(request, document_slug, document_locale, revision_id=None):

# Comparing against localized names for the Save button bothers me, so
# I embedded a hidden input:
which_form = request.POST.get('form')
which_form = request.POST.get('form-type')

if which_form == 'doc':
if doc.allows_editing_by(request.user):
Expand All @@ -173,10 +173,9 @@ def edit(request, document_slug, document_locale, revision_id=None):
if is_async_submit:
data = {
"error" : False,
"new_revision_id" : 13 #TODO: get next revision number
"new_revision_id" : rev.document.revisions.order_by('-id').first().id # This is the most recent revision id
}
json_data = json.dumps(data)
return JsonResponse(json_data)
return JsonResponse(data)

return redirect(urlparams(doc.get_edit_url(),
opendescription=1))
Expand Down Expand Up @@ -221,10 +220,9 @@ def edit(request, document_slug, document_locale, revision_id=None):
if is_async_submit:
data = {
"error" : False,
"new_revision_id" : 13 #TODO: get next revision number
"new_revision_id" : rev.document.revisions.order_by('-id').first().id # This is the most recent revision id
}
json_data = json.dumps(data)
return JsonResponse(json_data)
return JsonResponse(data)

if (is_raw and orig_rev is not None and
curr_rev.id != orig_rev.id):
Expand Down

0 comments on commit 889e145

Please sign in to comment.