Implement infrastructure for detecting and handling of simultaneous edits.

This commit is contained in:
Bart Kamphorst
2018-11-16 14:24:21 +01:00
parent f251e0f556
commit d4a9da0db5
4 changed files with 41 additions and 3 deletions
@@ -367,6 +367,34 @@ $(document).ready(function() {
window.onbeforeunload = function(){ return "Leaving will discard all edits!" };
});
$.GollumEditor();
$("#gollum-editor-submit").click( function(e) {
e.preventDefault();
// Prevent button from being clicked again
$(this).attr('disabled', true);
var formData = new FormData($('#gollum-editor-form').get(0));
var endpoint = $('#gollum-editor-form').attr("action");
$.ajax({
url: endpoint,
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data) {
window.location = window.location.href.replace(/gollum\/edit\//, '')
},
error: function(data, textStatus, errorThrown) {
if (data.status == 412) {
$('#gollum-editor-submit').attr('disabled', false)
alert('Someone else has modified this page while you were editing it. Please store your version on disk outside of the browser, reload this page and reapply your modifications.');
} else {
alert('Error updating page: ' + textStatus + ' ' + errorThrown);
}
}
});
});
}
if( $("#last-edit").length ) {