Implement AJAX deletion in /pages in order to remove redirect in /delete route.
This commit is contained in:
@@ -294,7 +294,6 @@ module Precious
|
||||
commit[:message] = "Deleted #{filepath}"
|
||||
wiki.delete_file(filepath, commit)
|
||||
end
|
||||
redirect_to('/pages')
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -58,6 +58,22 @@ $(document).ready(function() {
|
||||
e.preventDefault();
|
||||
} );
|
||||
|
||||
$('.delete-file').click( function(e) {
|
||||
var ok = confirm($(this).data('confirm'));
|
||||
if ( ok ) {
|
||||
var element = $(this);
|
||||
$.post('<%=delete_path %>' + $(this).data('file-path'),
|
||||
{},
|
||||
function (result) {
|
||||
// page successfully deleted, stay on page but remove element from DOM
|
||||
element.closest("li").remove();
|
||||
});
|
||||
}
|
||||
// Don't navigate on cancel.
|
||||
e.preventDefault();
|
||||
} );
|
||||
|
||||
|
||||
var nodeSelector = {
|
||||
node1: null,
|
||||
node2: null,
|
||||
|
||||
@@ -31,7 +31,7 @@ module Precious
|
||||
|
||||
|
||||
def delete_file(url)
|
||||
%Q(<form method="POST" action="#{delete_path}#{url}" onsubmit="return confirm('Do you really want to delete the file #{URI.decode(url)}?');"><button type="submit" name="delete" value="true">Delete</button></form>)
|
||||
%Q(<div class="delete-file" data-file-path="#{url}" data-confirm="Are you sure you want to delete #{URI.decode(url)}?"><span><button type="submit" name="delete">Delete</button></span></div>)
|
||||
end
|
||||
|
||||
def files_folders
|
||||
|
||||
Reference in New Issue
Block a user