From ff68644a2ea04581846018ed481f9750cbe4d1b8 Mon Sep 17 00:00:00 2001 From: albert Date: Sun, 17 Feb 2013 14:12:31 -0500 Subject: [PATCH] add inline forum editing --- app/helpers/application_helper.rb | 2 +- app/models/forum_post.rb | 6 +++++- app/views/forum_posts/_form.html.erb | 2 +- app/views/forum_posts/_forum_post.html.erb | 2 +- app/views/forum_posts/edit.html.erb | 2 +- app/views/forum_posts/new.html.erb | 2 +- app/views/forum_posts/new.js.erb | 6 ++++++ app/views/forum_topics/show.html.erb | 4 ++++ app/views/uploads/index.html.erb | 2 +- 9 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 app/views/forum_posts/new.js.erb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bd34b2a15..a4587b8c2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,7 +48,7 @@ module ApplicationHelper def error_messages_for(instance_name) instance = instance_variable_get("@#{instance_name}") - if instance.errors.any? + if instance && instance.errors.any? %{
Error: #{instance.__send__(:errors).full_messages.join(", ")}
}.html_safe else "" diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index d33c916e2..a7b3880f6 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -104,9 +104,13 @@ class ForumPost < ActiveRecord::Base self.is_deleted = false if is_deleted.nil? end + def quoted_response + "[quote]\n#{body}\n[/quote]\n\n" + end + def build_response dup.tap do |x| - x.body = "[quote]\n#{x.body}\n[/quote]\n\n" + x.body = x.quoted_response end end end diff --git a/app/views/forum_posts/_form.html.erb b/app/views/forum_posts/_form.html.erb index f33d31649..dcede6314 100644 --- a/app/views/forum_posts/_form.html.erb +++ b/app/views/forum_posts/_form.html.erb @@ -1,6 +1,6 @@ <%= error_messages_for("forum_post") %> -<%= simple_form_for(@forum_post) do |f| %> +<%= simple_form_for(forum_post) do |f| %> <%= f.input :topic_id, :as => :hidden %> <%= dtext_field "forum_post", "body" %> diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index 7ca48ea8e..baf0d032d 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -15,7 +15,7 @@ <%= format_text(forum_post.body) %> -
  • <%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id) %>
  • +
  • <%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %>
  • <% if CurrentUser.user.is_janitor? || CurrentUser.user.id == forum_post.creator_id %> <% if forum_post.is_deleted %>
  • <%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %>
  • diff --git a/app/views/forum_posts/edit.html.erb b/app/views/forum_posts/edit.html.erb index 1c4a60b1f..2299616e3 100644 --- a/app/views/forum_posts/edit.html.erb +++ b/app/views/forum_posts/edit.html.erb @@ -2,7 +2,7 @@

    Edit Forum Post

    - <%= render "form" %> + <%= render "form", :forum_post => @forum_post %>
    diff --git a/app/views/forum_posts/new.html.erb b/app/views/forum_posts/new.html.erb index cd68124d1..c9bcd3407 100644 --- a/app/views/forum_posts/new.html.erb +++ b/app/views/forum_posts/new.html.erb @@ -6,7 +6,7 @@

    New Forum Post

    <% end %> - <%= render "form" %> + <%= render "form", :forum_post => @forum_post %> <%= error_messages_for "forum_post" %> diff --git a/app/views/forum_posts/new.js.erb b/app/views/forum_posts/new.js.erb new file mode 100644 index 000000000..0c3226073 --- /dev/null +++ b/app/views/forum_posts/new.js.erb @@ -0,0 +1,6 @@ +$("#forum_post_body").val("<%= escape_javascript @forum_post.body %>"); +$("#new-topic-response").show(); + +$('html, body').animate({ + scrollTop: $("#forum_post_body").offset().top - 100 +}, 500); diff --git a/app/views/forum_topics/show.html.erb b/app/views/forum_topics/show.html.erb index b72637303..17c016284 100644 --- a/app/views/forum_topics/show.html.erb +++ b/app/views/forum_topics/show.html.erb @@ -17,6 +17,10 @@

    <%= link_to "Reply »".html_safe, new_forum_post_path(:topic_id => @forum_topic.id) %>

    +
    + <%= render "forum_posts/form", :forum_post => ForumPost.new(:topic_id => @forum_topic.id) %> +
    + <%= numbered_paginator(@forum_posts) %> diff --git a/app/views/uploads/index.html.erb b/app/views/uploads/index.html.erb index 7a1c58a10..debb2bca9 100644 --- a/app/views/uploads/index.html.erb +++ b/app/views/uploads/index.html.erb @@ -16,7 +16,7 @@ <%= link_to upload.id, upload_path(upload) %> <%= link_to upload.uploader.name, user_path(upload.uploader) %> <%= upload.presenter.status(self) %> - <%= upload.created_at %> + <%= time_ago_in_words_tagged upload.created_at %> <%= upload.tag_string %> <% end %>