Only use ajax for file upload. Prepare for handling of duplicate error.
This commit is contained in:
+3
-7
@@ -180,14 +180,11 @@ module Precious
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# AJAX calls only
|
||||||
post '/upload_file' do
|
post '/upload_file' do
|
||||||
wiki = wiki_new
|
wiki = wiki_new
|
||||||
|
|
||||||
unless wiki.allow_uploads
|
halt 405 unless wiki.allow_uploads
|
||||||
@message = "File uploads are disabled"
|
|
||||||
mustache :error
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if params[:file]
|
if params[:file]
|
||||||
fullname = params[:file][:filename]
|
fullname = params[:file][:filename]
|
||||||
@@ -224,8 +221,7 @@ module Precious
|
|||||||
committer.commit
|
committer.commit
|
||||||
redirect to(request.referer)
|
redirect to(request.referer)
|
||||||
rescue Gollum::DuplicatePageError => e
|
rescue Gollum::DuplicatePageError => e
|
||||||
@message = "Duplicate page: #{e.message}"
|
halt 409 # Signal conflict
|
||||||
mustache :error
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -228,8 +228,8 @@
|
|||||||
}
|
}
|
||||||
window.ace_editor.insert(text);
|
window.ace_editor.insert(text);
|
||||||
},
|
},
|
||||||
error: function(r, textStatus) {
|
error: function(r, textStatus, errorThrown) {
|
||||||
alert('Error uploading file: ' + textStatus);
|
alert('Error uploading file: ' + textStatus + ' ' + errorThrown);
|
||||||
$editorBody.removeClass('uploading');
|
$editorBody.removeClass('uploading');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ua detection
|
// ua detection
|
||||||
if ($.browser.mozilla) {
|
if ($.browser.mozilla) {
|
||||||
$('body').addClass('ff');
|
$('body').addClass('ff');
|
||||||
@@ -187,7 +188,26 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
OK: function( res ) {
|
OK: function( res ) {
|
||||||
$('#upload').submit();
|
var formData = new FormData($('#upload').get(0));
|
||||||
|
var endpoint = $('#upload').attr("action");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: endpoint,
|
||||||
|
type: 'POST',
|
||||||
|
data: formData,
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
success: function(data) {
|
||||||
|
// File successfully uploaded
|
||||||
|
},
|
||||||
|
error: function(data, textStatus, errorThrown) {
|
||||||
|
if (data.status == 409) {
|
||||||
|
alert('This file already exists.');
|
||||||
|
} else {
|
||||||
|
alert('Error uploading file: ' + textStatus + ' ' + errorThrown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user