Merge pull request #168 from walle/issue_128
Add cancel button to comment editing.
This commit is contained in:
commit
ebdea913bf
|
@ -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));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue