Add cancel button to comment editing.

This should fix issue #128.
This commit is contained in:
Fredrik Wallgren 2014-08-16 18:37:25 +02:00
parent bdbfedfb23
commit ee8b50f9c0
2 changed files with 22 additions and 3 deletions

View file

@ -300,14 +300,22 @@ $(document).ready(function() {
});
$(document).on("click", "button.comment-cancel", function() {
$(this).closest(".comment").remove();
var comment = $(this).closest(".comment[data-shortid]");
if (comment.length) {
$.get("/comments/" + comment.attr("data-shortid"),
function(data) {
comment.replaceWith($.parseHTML(data));
});
} else {
$(this).closest(".comment").remove();
}
});
$(document).on("click", "a.comment_editor", function() {
var comment = $(this).closest(".comment");
$.get("/comments/" + comment.attr("data-shortid") + "/edit",
function(data) {
comment.replaceWith($.parseHTML(data));
comment.html($.parseHTML(data));
});
});

View file

@ -53,13 +53,24 @@ class CommentsController < ApplicationController
end
end
def show
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :text => "can't find comment", :status => 400
end
render :partial => "comment", :layout => false,
:content_type => "text/html", :locals => { :comment => comment,
:cancellable => true }
end
def edit
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :text => "can't find comment", :status => 400
end
render :partial => "commentbox", :layout => false,
:content_type => "text/html", :locals => { :comment => comment }
:content_type => "text/html", :locals => { :comment => comment,
:cancellable => true }
end
def reply