From 739da4c4b9041d88d122ee3ec6c6c5087436982b Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 14 Jun 2013 12:23:10 -0400 Subject: [PATCH 1/5] fixes #1424 for comments --- app/assets/javascripts/comments.js | 11 +++++++++++ app/views/comments/_edit.html.erb | 5 +++++ app/views/comments/partials/show/_comment.html.erb | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/views/comments/_edit.html.erb diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 4ebd8e369..933faa522 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -6,6 +6,7 @@ this.initialize_response_link(); this.initialize_reply_links(); this.initialize_expand_links(); + this.initialize_edit_links(); } if ($("#c-posts").length && $("#a-show").length) { @@ -63,6 +64,16 @@ $("div.new-comment form").hide(); } + Danbooru.Comment.initialize_edit_links = function() { + $(".edit_comment").hide(); + $(".edit_comment_link").click(function(e) { + var link_id = $(this).attr("id"); + var comment_id = link_id.match(/^edit_comment_link_(\d+)$/)[1]; + $("#edit_comment_" + comment_id).toggle(); + e.preventDefault(); + }); + } + Danbooru.Comment.highlight_threshold_comments = function(post_id) { var threshold = parseInt(Danbooru.meta("user-comment-threshold")); var articles = $("article.comment[data-post-id=" + post_id + "]"); diff --git a/app/views/comments/_edit.html.erb b/app/views/comments/_edit.html.erb new file mode 100644 index 000000000..47b6e8698 --- /dev/null +++ b/app/views/comments/_edit.html.erb @@ -0,0 +1,5 @@ +<%= simple_form_for(comment) do |f| %> + <%= dtext_field "comment", "body", :value => comment.body, :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> + <%= f.button :submit, "Submit" %> + <%= dtext_preview_button "comment", "body", :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> +<% end %> diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 208dd5b0e..c6a90ec1a 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -20,12 +20,15 @@
  • <%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %>
  • <% if comment.editable_by?(CurrentUser.user) %>
  • <%= link_to "Delete", comment_path(comment.id), :confirm => "Are you sure you want to delete this comment?", :method => :delete, :remote => true %>
  • -
  • <%= link_to "Edit", edit_comment_path(comment.id) %>
  • +
  • <%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %>
  • <% end %> <% end %> + <% if comment.editable_by?(CurrentUser.user) %> + <%= render "comments/edit", :comment => comment %> + <% end %> <% end %>
    From 029c05024336da8024ee5c455211553e24a6e6a7 Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 14 Jun 2013 12:23:29 -0400 Subject: [PATCH 2/5] fixes #1424 for forum posts and topics --- app/assets/javascripts/forum_posts.js | 31 ++++++++++++++++++++++ app/views/forum_posts/_form.html.erb | 4 +-- app/views/forum_posts/_forum_post.html.erb | 11 ++++++-- app/views/forum_topics/_form.html.erb | 10 +++---- app/views/forum_topics/edit.html.erb | 2 +- 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/forum_posts.js diff --git a/app/assets/javascripts/forum_posts.js b/app/assets/javascripts/forum_posts.js new file mode 100644 index 000000000..2b367818c --- /dev/null +++ b/app/assets/javascripts/forum_posts.js @@ -0,0 +1,31 @@ +(function() { + Danbooru.ForumPost = {}; + + Danbooru.ForumPost.initialize_all = function() { + if ($("#c-forum-topics").length && $("#a-show").length) {; + this.initialize_edit_links(); + } + } + + Danbooru.ForumPost.initialize_edit_links = function() { + $(".edit_forum_post, .edit_forum_topic").hide(); + + $(".edit_forum_post_link").click(function(e) { + var link_id = $(this).attr("id"); + var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1]; + $("#edit_forum_post_" + forum_post_id).toggle(); + e.preventDefault(); + }); + + $(".edit_forum_topic_link").click(function(e) { + var link_id = $(this).attr("id"); + var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1]; + $("#edit_forum_topic_" + forum_topic_id).toggle(); + e.preventDefault(); + }); + } +})(); + +$(document).ready(function() { + Danbooru.ForumPost.initialize_all(); +}); diff --git a/app/views/forum_posts/_form.html.erb b/app/views/forum_posts/_form.html.erb index dcede6314..a42f0e8fd 100644 --- a/app/views/forum_posts/_form.html.erb +++ b/app/views/forum_posts/_form.html.erb @@ -2,8 +2,8 @@ <%= simple_form_for(forum_post) do |f| %> <%= f.input :topic_id, :as => :hidden %> - <%= dtext_field "forum_post", "body" %> + <%= dtext_field "forum_post", "body", :value => forum_post.body, :input_id => "forum_post_body_for_#{forum_post.id}", :preview_id => "dtext-preview-for-#{forum_post.id}" %> <%= f.button :submit, "Submit" %> - <%= dtext_preview_button "forum_post", "body" %> + <%= dtext_preview_button "forum_post", "body", :input_id => "forum_post_body_for_#{forum_post.id}", :preview_id => "dtext-preview-for-#{forum_post.id}" %> <% end %> diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index 5aa59276d..0a4726fba 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -32,9 +32,9 @@ <% end %> <% if forum_post.editable_by?(CurrentUser.user) %> <% if forum_post.is_original_post? %> -
  • <%= link_to "Edit", edit_forum_topic_path(forum_post.topic) %>
  • +
  • <%= link_to "Edit", edit_forum_topic_path(forum_post.topic), :id => "edit_forum_topic_link_#{forum_post.topic.id}", :class => "edit_forum_topic_link" %>
  • <% else %> -
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id) %>
  • +
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id), :id => "edit_forum_post_link_#{forum_post.id}", :class => "edit_forum_post_link" %>
  • <% end %> <% end %> <% if params[:controller] == "forum_posts" %> @@ -42,6 +42,13 @@ <% else %>
  • <%= link_to "Permalink", forum_post_path(forum_post) %>
  • <% end %> + <% if forum_post.editable_by?(CurrentUser.user) %> + <% if forum_post.is_original_post? %> + <%= render "forum_topics/form", :forum_topic => forum_post.topic %> + <% else %> + <%= render "forum_posts/form", :forum_post => forum_post %> + <% end %> + <% end %>
    diff --git a/app/views/forum_topics/_form.html.erb b/app/views/forum_topics/_form.html.erb index cf05d22c0..df4aa267b 100644 --- a/app/views/forum_topics/_form.html.erb +++ b/app/views/forum_topics/_form.html.erb @@ -1,13 +1,13 @@
    - <%= simple_form_for(@forum_topic) do |f| %> + <%= simple_form_for(forum_topic) do |f| %> <%= f.input :title %> <%= f.simple_fields_for :original_post do |pf| %> - <% if !@forum_topic.new_record? %> - <%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %> + <% if !forum_topic.new_record? %> + <%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", forum_topic.id %> <% end %> - <%= dtext_field "forum_post", "body", :input_name => "forum_topic[original_post_attributes][body]", :value => @forum_topic.original_post.body %> + <%= dtext_field "forum_post", "body", :input_name => "forum_topic[original_post_attributes][body]", :value => forum_topic.original_post.body, :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %> <% end %> <% if CurrentUser.is_janitor? %> @@ -16,6 +16,6 @@ <% end %> <%= f.button :submit, "Submit" %> - <%= dtext_preview_button "forum_post", "body" %> + <%= dtext_preview_button "forum_post", "body", :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %> <% end %>
    diff --git a/app/views/forum_topics/edit.html.erb b/app/views/forum_topics/edit.html.erb index 0436006c3..cbb67c4a1 100644 --- a/app/views/forum_topics/edit.html.erb +++ b/app/views/forum_topics/edit.html.erb @@ -2,7 +2,7 @@

    Edit Forum Topic

    - <%= render "form" %> + <%= render "form", :forum_topic => @forum_topic %>
    From 4fd3901017a48cb7313ab3829110c6d00bf088fa Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 14 Jun 2013 12:30:19 -0400 Subject: [PATCH 3/5] fix old comment edit page (#1424) --- app/assets/javascripts/comments.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 933faa522..291a3e106 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -6,7 +6,10 @@ this.initialize_response_link(); this.initialize_reply_links(); this.initialize_expand_links(); - this.initialize_edit_links(); + + if (!$("#a-edit").length) { + this.initialize_edit_links(); + } } if ($("#c-posts").length && $("#a-show").length) { From 4765ce11b6700f5525758c315e8a2a56fc8d41ba Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 14 Jun 2013 12:32:25 -0400 Subject: [PATCH 4/5] name consistency (#1424) --- app/views/comments/{_edit.html.erb => _form.html.erb} | 0 app/views/comments/partials/show/_comment.html.erb | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename app/views/comments/{_edit.html.erb => _form.html.erb} (100%) diff --git a/app/views/comments/_edit.html.erb b/app/views/comments/_form.html.erb similarity index 100% rename from app/views/comments/_edit.html.erb rename to app/views/comments/_form.html.erb diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index c6a90ec1a..3662a7a98 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -27,7 +27,7 @@ <% end %> <% if comment.editable_by?(CurrentUser.user) %> - <%= render "comments/edit", :comment => comment %> + <%= render "comments/form", :comment => comment %> <% end %> <% end %> From f644ef69ff9383d6b8afa1378103d8118d1d1f5e Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 14 Jun 2013 12:34:32 -0400 Subject: [PATCH 5/5] non-instantaneous edit form toggling (#1424) --- app/assets/javascripts/comments.js | 2 +- app/assets/javascripts/forum_posts.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 291a3e106..fe56fde15 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -72,7 +72,7 @@ $(".edit_comment_link").click(function(e) { var link_id = $(this).attr("id"); var comment_id = link_id.match(/^edit_comment_link_(\d+)$/)[1]; - $("#edit_comment_" + comment_id).toggle(); + $("#edit_comment_" + comment_id).fadeToggle("fast"); e.preventDefault(); }); } diff --git a/app/assets/javascripts/forum_posts.js b/app/assets/javascripts/forum_posts.js index 2b367818c..480852f42 100644 --- a/app/assets/javascripts/forum_posts.js +++ b/app/assets/javascripts/forum_posts.js @@ -13,14 +13,14 @@ $(".edit_forum_post_link").click(function(e) { var link_id = $(this).attr("id"); var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1]; - $("#edit_forum_post_" + forum_post_id).toggle(); + $("#edit_forum_post_" + forum_post_id).fadeToggle("fast"); e.preventDefault(); }); $(".edit_forum_topic_link").click(function(e) { var link_id = $(this).attr("id"); var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1]; - $("#edit_forum_topic_" + forum_topic_id).toggle(); + $("#edit_forum_topic_" + forum_topic_id).fadeToggle("fast"); e.preventDefault(); }); }