forum previews working
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class DtextController < ApplicationController
|
||||
def preview
|
||||
render :inline => "<h1>Preview</h1><%= format_text(params[:body]) %>"
|
||||
render :inline => "<h1 class=\"preview-header\">Preview</h1><%= format_text(params[:body]) %>"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,6 +19,10 @@ class ForumPostsController < ApplicationController
|
||||
@forum_posts = @search.paginate(:page => params[:page], :order => "id DESC")
|
||||
respond_with(@forum_posts)
|
||||
end
|
||||
|
||||
def search
|
||||
@search = ForumPost.search(params[:search])
|
||||
end
|
||||
|
||||
def show
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
|
||||
@@ -18,7 +18,7 @@ class ForumTopicsController < ApplicationController
|
||||
|
||||
def index
|
||||
@search = ForumTopic.search(params[:search])
|
||||
@forum_topics = @search.paginate(:page => params[:page], :order => "updated_at DESC")
|
||||
@forum_topics = @search.paginate(:page => params[:page], :order => "is_sticky DESC, updated_at DESC")
|
||||
respond_with(@forum_topics)
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ module ApplicationHelper
|
||||
instance = instance_variable_get("@#{instance_name}")
|
||||
|
||||
if instance.errors.any?
|
||||
%{<div class="error-messages"><h1>There were errors</h1><p>#{instance.__send__(:errors).full_messages.join(", ")}</div>}.html_safe
|
||||
%{<div class="error-messages ui-state-error ui-corner-all"><span class="ui-icon ui-icon-alert"></span> <strong>Error</strong>: #{instance.__send__(:errors).full_messages.join(", ")}</div>}.html_safe
|
||||
else
|
||||
""
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ class ForumPost < ActiveRecord::Base
|
||||
before_validation :initialize_updater
|
||||
after_save :update_topic_updated_at
|
||||
validates_presence_of :body, :creator_id
|
||||
validate :validate_topic_is_unlocked
|
||||
scope :body_matches, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])}
|
||||
search_method :body_matches
|
||||
|
||||
@@ -19,6 +20,18 @@ class ForumPost < ActiveRecord::Base
|
||||
new
|
||||
end
|
||||
end
|
||||
|
||||
def validate_topic_is_unlocked
|
||||
return if CurrentUser.is_moderator?
|
||||
return if topic.nil?
|
||||
|
||||
if topic.is_locked?
|
||||
errors.add(:topic, "is locked")
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
creator_id == user.id || user.is_moderator?
|
||||
|
||||
@@ -7,6 +7,7 @@ class ForumTopic < ActiveRecord::Base
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
validates_presence_of :title, :creator_id
|
||||
validates_associated :original_post
|
||||
scope :title_matches, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
|
||||
search_methods :title_matches
|
||||
accepts_nested_attributes_for :original_post
|
||||
|
||||
25
app/views/forum_posts/_form.html.erb
Normal file
25
app/views/forum_posts/_form.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<div id="form-content">
|
||||
<%= error_messages_for("forum_post") %>
|
||||
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<% unless @forum_post.new_record? %>
|
||||
<%= f.input :topic_id, :as => :hidden %>
|
||||
<% end %>
|
||||
<%= f.input :body %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= f.button :submit, "Preview" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="form-aside">
|
||||
<div id="preview">
|
||||
<div class="content dtext">
|
||||
|
||||
</div>
|
||||
<p><a href="#" name="toggle-preview">Hide</a></p>
|
||||
</div>
|
||||
<div id="dtext-help">
|
||||
<%= render "dtext/help" %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,7 +0,0 @@
|
||||
<div>
|
||||
<%= simple_form_for @search do |f| %>
|
||||
<%= f.input :body_matches %>
|
||||
<%= f.input :creator_name_equals %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,10 +1,9 @@
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-edit">
|
||||
<h1>Edit Forum Post</h1>
|
||||
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<%= f.input :body %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "forum_topics/secondary_links" %>
|
||||
@@ -1,6 +1,4 @@
|
||||
<%= render "search" %>
|
||||
|
||||
<table>
|
||||
<table width="100%" class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Topic</th>
|
||||
@@ -12,10 +10,10 @@
|
||||
<tbody>
|
||||
<% @forum_posts.each do |forum_post| %>
|
||||
<tr>
|
||||
<td><%= forum_post.topic.title %></td>
|
||||
<td><%= truncate forum_post.body, :length => 50 %></td>
|
||||
<td><%= link_to forum_post.topic.title, forum_topic_path(forum_post.topic) %></td>
|
||||
<td><%= link_to truncate(forum_post.body, :length => 50), forum_post_path(forum_post) %></td>
|
||||
<td><%= forum_post.creator.name %></td>
|
||||
<td><%= forum_post.created_at %></td>
|
||||
<td><%= time_ago_in_words forum_post.created_at %> ago</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
@@ -24,3 +22,5 @@
|
||||
<div id="paginator">
|
||||
<%= will_paginate @forum_posts %>
|
||||
</div>
|
||||
|
||||
<%= render "forum_topics/secondary_links" %>
|
||||
@@ -1,11 +1,9 @@
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-new">
|
||||
<h1>New Forum Post</h1>
|
||||
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<%= f.input :topic_id, :as => :hidden %>
|
||||
<%= f.input :body %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
<%= render "form" %>
|
||||
<%= error_messages_for "forum_post" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "forum_topics/secondary_links" %>
|
||||
12
app/views/forum_posts/search.html.erb
Normal file
12
app/views/forum_posts/search.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-search">
|
||||
<h1>Search Forum Posts</h1>
|
||||
<%= simple_form_for @search do |f| %>
|
||||
<%= f.input :topic_title_matches, :label => "Title" %>
|
||||
<%= f.input :body_matches, :label => "Body" %>
|
||||
<%= f.button :submit, "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "forum_topics/secondary_links" %>
|
||||
7
app/views/forum_posts/show.html.erb
Normal file
7
app/views/forum_posts/show.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-show" class="single-forum-post list-of-forum-posts">
|
||||
<%= render :partial => "forum_post", :locals => {:forum_post => @forum_post} %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "forum_topics/secondary_links" %>
|
||||
34
app/views/forum_topics/_form.html.erb
Normal file
34
app/views/forum_topics/_form.html.erb
Normal file
@@ -0,0 +1,34 @@
|
||||
<div id="form-content">
|
||||
<%= error_messages_for("forum_topic") %>
|
||||
|
||||
<%= simple_form_for(@forum_topic) do |f| %>
|
||||
<%= f.input :title %>
|
||||
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<% unless @forum_topic.new_record? %>
|
||||
<%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
|
||||
<% end %>
|
||||
<%= pf.input :body, :input_html => {:id => "forum_post_body"} %>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<%= f.input :is_sticky %>
|
||||
<%= f.input :is_locked %>
|
||||
<% end %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= f.button :submit, "Preview" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="form-aside">
|
||||
<div id="preview">
|
||||
<div class="content dtext">
|
||||
|
||||
</div>
|
||||
<p><a href="#" name="toggle-preview">Hide</a></p>
|
||||
</div>
|
||||
<div id="dtext-help">
|
||||
<%= render "dtext/help" %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,6 +0,0 @@
|
||||
<div id="search">
|
||||
<%= form_tag(forum_posts_path, :method => :get) do %>
|
||||
<%= text_field_tag "title_matches" %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -2,6 +2,7 @@
|
||||
<menu>
|
||||
<li><%= link_to "Listing", forum_topics_path %></li>
|
||||
<li><%= link_to "New", new_forum_topic_path %></li>
|
||||
<li><%= link_to "Search", search_forum_posts_path %></li>
|
||||
<li><%= link_to "Help", wiki_pages_path(:title => "help:forum") %></li>
|
||||
<% if @forum_topic %>
|
||||
<li>|</li>
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-edit">
|
||||
<h1>Edit Forum Topic</h1>
|
||||
|
||||
<%= simple_form_for(@forum_topic) do |f| %>
|
||||
<%= f.input :title %>
|
||||
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
|
||||
<%= pf.input :body %>
|
||||
<% end %>
|
||||
|
||||
<%= f.input :is_sticky %>
|
||||
<%= f.input :is_locked %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,8 +1,6 @@
|
||||
<h1>Forum</h1>
|
||||
|
||||
<%= render "search" %>
|
||||
|
||||
<table width="100%">
|
||||
<table width="100%" class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
@@ -14,7 +12,7 @@
|
||||
<tbody>
|
||||
<% @forum_topics.each do |topic| %>
|
||||
<tr>
|
||||
<td><%= topic.title %></td>
|
||||
<td><% if topic.is_sticky? %><span class="sticky">Sticky:</span> <% end %><%= link_to topic.title, forum_topic_path(topic) %></td>
|
||||
<td><%= topic.creator.name %></td>
|
||||
<td><%= topic.updater.name %></td>
|
||||
<td><%= compact_time topic.updated_at %></td>
|
||||
|
||||
@@ -2,21 +2,7 @@
|
||||
<div id="a-new">
|
||||
<h1>New Forum Topic</h1>
|
||||
|
||||
<div id="form-content">
|
||||
<%= simple_form_for(@forum_topic) do |f| %>
|
||||
<%= f.input :title %>
|
||||
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<%= pf.input :body %>
|
||||
<% end %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="dtext-help">
|
||||
<%= render "dtext/help" %>
|
||||
</div>
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@
|
||||
</header>
|
||||
|
||||
<% if flash[:notice] %>
|
||||
<div id="notice"><%= flash[:notice] %></div>
|
||||
<div class="ui-corner-all ui-state-highlight" id="notice"><span class="ui-icon ui-icon-info"></span> <%= flash[:notice] %></div>
|
||||
<% else %>
|
||||
<div id="notice" style="display: none;"></div>
|
||||
<div class="ui-corner-all ui-state-highlight" id="notice" style="display: none;"><span class="ui-icon ui-icon-info"></span> </div>
|
||||
<% end %>
|
||||
|
||||
<div id="page">
|
||||
|
||||
Reference in New Issue
Block a user