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() {
var comment = $(this).closest(".comment[data-shortid]");
if (comment.length) {
$.get("/comments/" + comment.attr("data-shortid"),
function(data) {
comment.html($.parseHTML(data));
var comment = $(this).closest(".comment");
var comment_id = comment.attr("data-shortid");
if (comment_id != null && comment_id !== '') {
$.get("/comments/" + comment_id, function(data) {
comment.replaceWith($.parseHTML(data));
});
} else {
$(this).closest(".comment").remove();
comment.remove();
}
});

View file

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

View file

@ -1,5 +1,5 @@
<a name="c_<%= comment.short_id %>"></a>
<div id="comment_<%= comment.short_id %>" data-shortid="<%= comment.short_id %>"
<div id="comment_<%= comment.short_id %>"
data-shortid="<%= comment.short_id if comment.persisted? %>"
class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
"upvoted" : "downvoted") : "" %>
<%= comment.highlighted ? "highlighted" : "" %>
@ -24,6 +24,8 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<% end %>
<div class="details">
<div class="byline">
<a name="c_<%= comment.short_id %>"></a>
<% if defined?(was_merged) && was_merged %>
<span class="merge"></span>
<% 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,
:html => { :id => "edit_comment_#{comment.short_id}" } do |f| %>
<% if comment.errors.any? %>
@ -37,7 +38,7 @@
&nbsp;
<%= button_tag "Preview", :class => "comment-preview",
:type => "button", :disabled => !@user %>
<% if local_assigns[:cancellable] %>
<% if comment.persisted? || comment.parent_comment_id %>
&nbsp;
<%= button_tag "Cancel", :class => "comment-cancel",
:type => "button" %>