fix cancel button in comment forms

This commit is contained in:
Serge Paquet 2014-12-14 01:24:18 -05:00
parent ddb9215aa0
commit a1f5052f99
4 changed files with 16 additions and 16 deletions

View file

@ -313,14 +313,14 @@ $(document).ready(function() {
}); });
$(document).on("click", "button.comment-cancel", function() { $(document).on("click", "button.comment-cancel", function() {
var comment = $(this).closest(".comment[data-shortid]"); var comment = $(this).closest(".comment");
if (comment.length) { var comment_id = comment.attr("data-shortid");
$.get("/comments/" + comment.attr("data-shortid"), if (comment_id != null && comment_id !== '') {
function(data) { $.get("/comments/" + comment_id, function(data) {
comment.html($.parseHTML(data)); comment.replaceWith($.parseHTML(data));
}); });
} else { } else {
$(this).closest(".comment").remove(); comment.remove();
} }
}); });

View file

@ -63,8 +63,7 @@ class CommentsController < ApplicationController
end end
render :partial => "comment", :layout => false, render :partial => "comment", :layout => false,
:content_type => "text/html", :locals => { :comment => comment, :content_type => "text/html", :locals => { :comment => comment }
:cancellable => true }
end end
def edit def edit
@ -73,8 +72,7 @@ class CommentsController < ApplicationController
end end
render :partial => "commentbox", :layout => false, render :partial => "commentbox", :layout => false,
:content_type => "text/html", :locals => { :comment => comment, :content_type => "text/html", :locals => { :comment => comment }
:cancellable => true }
end end
def reply def reply
@ -87,8 +85,7 @@ class CommentsController < ApplicationController
comment.parent_comment = parent_comment comment.parent_comment = parent_comment
render :partial => "commentbox", :layout => false, render :partial => "commentbox", :layout => false,
:content_type => "text/html", :locals => { :comment => comment, :content_type => "text/html", :locals => { :comment => comment }
:cancellable => true }
end end
def delete def delete

View file

@ -1,5 +1,5 @@
<a name="c_<%= comment.short_id %>"></a> <div id="comment_<%= comment.short_id %>"
<div id="comment_<%= comment.short_id %>" data-shortid="<%= comment.short_id %>" data-shortid="<%= comment.short_id if comment.persisted? %>"
class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
"upvoted" : "downvoted") : "" %> "upvoted" : "downvoted") : "" %>
<%= comment.highlighted ? "highlighted" : "" %> <%= comment.highlighted ? "highlighted" : "" %>
@ -24,6 +24,8 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<% end %> <% end %>
<div class="details"> <div class="details">
<div class="byline"> <div class="byline">
<a name="c_<%= comment.short_id %>"></a>
<% if defined?(was_merged) && was_merged %> <% if defined?(was_merged) && was_merged %>
<span class="merge"></span> <span class="merge"></span>
<% end %> <% end %>

View file

@ -1,4 +1,5 @@
<div class="comment comment_form_container"> <div class="comment comment_form_container"
data-shortid="<%= comment.short_id if comment.persisted? %>">
<%= form_for comment, <%= form_for comment,
:html => { :id => "edit_comment_#{comment.short_id}" } do |f| %> :html => { :id => "edit_comment_#{comment.short_id}" } do |f| %>
<% if comment.errors.any? %> <% if comment.errors.any? %>
@ -37,7 +38,7 @@
&nbsp; &nbsp;
<%= button_tag "Preview", :class => "comment-preview", <%= button_tag "Preview", :class => "comment-preview",
:type => "button", :disabled => !@user %> :type => "button", :disabled => !@user %>
<% if local_assigns[:cancellable] %> <% if comment.persisted? || comment.parent_comment_id %>
&nbsp; &nbsp;
<%= button_tag "Cancel", :class => "comment-cancel", <%= button_tag "Cancel", :class => "comment-cancel",
:type => "button" %> :type => "button" %>