Implement AJAX deletion in /pages in order to remove redirect in /delete route.

This commit is contained in:
Bart Kamphorst
2018-10-19 21:04:31 +02:00
parent 825f43c429
commit 1a8b6d6823
3 changed files with 17 additions and 2 deletions
-1
View File
@@ -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,
+1 -1
View File
@@ -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