forum previews working

This commit is contained in:
albert
2011-03-12 16:09:11 -05:00
parent 21cc1cbafa
commit bd520f61f7
29 changed files with 1516 additions and 81 deletions

View File

@@ -1,5 +1,5 @@
class DtextController < ApplicationController class DtextController < ApplicationController
def preview 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
end end

View File

@@ -19,6 +19,10 @@ class ForumPostsController < ApplicationController
@forum_posts = @search.paginate(:page => params[:page], :order => "id DESC") @forum_posts = @search.paginate(:page => params[:page], :order => "id DESC")
respond_with(@forum_posts) respond_with(@forum_posts)
end end
def search
@search = ForumPost.search(params[:search])
end
def show def show
@forum_post = ForumPost.find(params[:id]) @forum_post = ForumPost.find(params[:id])

View File

@@ -18,7 +18,7 @@ class ForumTopicsController < ApplicationController
def index def index
@search = ForumTopic.search(params[:search]) @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) respond_with(@forum_topics)
end end

View File

@@ -17,7 +17,7 @@ module ApplicationHelper
instance = instance_variable_get("@#{instance_name}") instance = instance_variable_get("@#{instance_name}")
if instance.errors.any? 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 else
"" ""
end end

View File

@@ -6,6 +6,7 @@ class ForumPost < ActiveRecord::Base
before_validation :initialize_updater before_validation :initialize_updater
after_save :update_topic_updated_at after_save :update_topic_updated_at
validates_presence_of :body, :creator_id validates_presence_of :body, :creator_id
validate :validate_topic_is_unlocked
scope :body_matches, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])} scope :body_matches, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])}
search_method :body_matches search_method :body_matches
@@ -19,6 +20,18 @@ class ForumPost < ActiveRecord::Base
new new
end end
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) def editable_by?(user)
creator_id == user.id || user.is_moderator? creator_id == user.id || user.is_moderator?

View File

@@ -7,6 +7,7 @@ class ForumTopic < ActiveRecord::Base
before_validation :initialize_creator, :on => :create before_validation :initialize_creator, :on => :create
before_validation :initialize_updater before_validation :initialize_updater
validates_presence_of :title, :creator_id validates_presence_of :title, :creator_id
validates_associated :original_post
scope :title_matches, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])} scope :title_matches, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
search_methods :title_matches search_methods :title_matches
accepts_nested_attributes_for :original_post accepts_nested_attributes_for :original_post

View 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>

View File

@@ -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>

View File

@@ -1,10 +1,9 @@
<div id="c-forum-topics"> <div id="c-forum-topics">
<div id="a-edit"> <div id="a-edit">
<h1>Edit Forum Post</h1> <h1>Edit Forum Post</h1>
<%= simple_form_for(@forum_post) do |f| %> <%= render "form" %>
<%= f.input :body %>
<%= f.button :submit, "Submit" %>
<% end %>
</div> </div>
</div> </div>
<%= render "forum_topics/secondary_links" %>

View File

@@ -1,6 +1,4 @@
<%= render "search" %> <table width="100%" class="striped">
<table>
<thead> <thead>
<tr> <tr>
<th>Topic</th> <th>Topic</th>
@@ -12,10 +10,10 @@
<tbody> <tbody>
<% @forum_posts.each do |forum_post| %> <% @forum_posts.each do |forum_post| %>
<tr> <tr>
<td><%= forum_post.topic.title %></td> <td><%= link_to forum_post.topic.title, forum_topic_path(forum_post.topic) %></td>
<td><%= truncate forum_post.body, :length => 50 %></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.creator.name %></td>
<td><%= forum_post.created_at %></td> <td><%= time_ago_in_words forum_post.created_at %> ago</td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
@@ -24,3 +22,5 @@
<div id="paginator"> <div id="paginator">
<%= will_paginate @forum_posts %> <%= will_paginate @forum_posts %>
</div> </div>
<%= render "forum_topics/secondary_links" %>

View File

@@ -1,11 +1,9 @@
<div id="c-forum-topics"> <div id="c-forum-topics">
<div id="a-new"> <div id="a-new">
<h1>New Forum Post</h1> <h1>New Forum Post</h1>
<%= render "form" %>
<%= simple_form_for(@forum_post) do |f| %> <%= error_messages_for "forum_post" %>
<%= f.input :topic_id, :as => :hidden %>
<%= f.input :body %>
<%= f.button :submit, "Submit" %>
<% end %>
</div> </div>
</div> </div>
<%= render "forum_topics/secondary_links" %>

View 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" %>

View 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" %>

View 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>

View File

@@ -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>

View File

@@ -2,6 +2,7 @@
<menu> <menu>
<li><%= link_to "Listing", forum_topics_path %></li> <li><%= link_to "Listing", forum_topics_path %></li>
<li><%= link_to "New", new_forum_topic_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> <li><%= link_to "Help", wiki_pages_path(:title => "help:forum") %></li>
<% if @forum_topic %> <% if @forum_topic %>
<li>|</li> <li>|</li>

View File

@@ -1,19 +1,7 @@
<div id="c-forum-topics"> <div id="c-forum-topics">
<div id="a-edit"> <div id="a-edit">
<h1>Edit Forum Topic</h1> <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" %> <%= render "form" %>
<% end %>
</div> </div>
</div> </div>

View File

@@ -1,8 +1,6 @@
<h1>Forum</h1> <h1>Forum</h1>
<%= render "search" %> <table width="100%" class="striped">
<table width="100%">
<thead> <thead>
<tr> <tr>
<th>Title</th> <th>Title</th>
@@ -14,7 +12,7 @@
<tbody> <tbody>
<% @forum_topics.each do |topic| %> <% @forum_topics.each do |topic| %>
<tr> <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.creator.name %></td>
<td><%= topic.updater.name %></td> <td><%= topic.updater.name %></td>
<td><%= compact_time topic.updated_at %></td> <td><%= compact_time topic.updated_at %></td>

View File

@@ -2,21 +2,7 @@
<div id="a-new"> <div id="a-new">
<h1>New Forum Topic</h1> <h1>New Forum Topic</h1>
<div id="form-content"> <%= render "form" %>
<%= 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>
</div> </div>
</div> </div>

View File

@@ -49,9 +49,9 @@
</header> </header>
<% if flash[:notice] %> <% 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 %> <% 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 %> <% end %>
<div id="page"> <div id="page">

View File

@@ -19,7 +19,11 @@ Danbooru::Application.routes.draw do
resources :dmails resources :dmails
resources :favorites resources :favorites
resources :forum_topics resources :forum_topics
resources :forum_posts resources :forum_posts do
collection do
get :search
end
end
resources :janitor_trials do resources :janitor_trials do
member do member do
put :promote put :promote

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,7 @@ $(document).ready(function() {
// $("#upgrade-account").hide(); // $("#upgrade-account").hide();
// Cookie.put('hide-upgrade-account', '1', 7); // Cookie.put('hide-upgrade-account', '1', 7);
// }); // });
// Table striping // Table striping
$("table.striped tbody tr:even").addClass("even"); $("table.striped tbody tr:even").addClass("even");
$("table.striped tbody tr:odd").addClass("odd"); $("table.striped tbody tr:odd").addClass("odd");

View File

@@ -2,7 +2,7 @@
Danbooru.Comment = {}; Danbooru.Comment = {};
Danbooru.Comment.initialize_all = function() { Danbooru.Comment.initialize_all = function() {
$("#c-comments div.dtext-preview").hide(); $("div.dtext-preview").hide();
this.initialize_response_link(); this.initialize_response_link();
this.initialize_preview_button(); this.initialize_preview_button();
} }

View File

@@ -0,0 +1,35 @@
(function() {
Danbooru.ForumPost = {};
Danbooru.ForumPost.initialize_all = function() {
$("#c-forum-topics #preview").hide();
this.initialize_preview_link();
}
Danbooru.ForumPost.initialize_preview_link = function() {
$("#c-forum-topics #preview a[name=toggle-preview]").click(function() {
$("#preview").toggle();
$("#dtext-help").toggle();
});
$("#c-forum-topics input[value=Preview]").click(function(e) {
e.preventDefault();
$.ajax({
type: "post",
url: "/dtext/preview",
data: {
body: $("#forum_post_body").val()
},
success: function(data) {
$("#dtext-help").hide();
$("#preview").show();
$("#preview .content").html(data);
}
});
});
}
})();
$(document).ready(function() {
Danbooru.ForumPost.initialize_all();
});

View File

@@ -134,14 +134,25 @@ table.striped tbody tr:hover {
table.striped tr.even { table.striped tr.even {
background-color: #EEE; } background-color: #EEE; }
div.error-messages {
margin: 1em 0;
padding: 1em; }
div.error-messages span.ui-icon {
float: left;
margin-right: 0.5em; }
div.error-messages h1 {
font-size: 1em;
color: #A00; }
div#search { div#search {
margin-bottom: 1em; } margin-bottom: 1em; }
div#notice { div#notice {
margin: 1em; margin: 1em 0;
padding: 1em; padding: 1em; }
border: 2px solid #666; div#notice span.ui-icon {
background: #EEE; } float: left;
margin-right: 0.5em; }
div#page aside#sidebar { div#page aside#sidebar {
width: 20%; width: 20%;
@@ -222,6 +233,8 @@ form.simple_form {
margin-right: 2em; } margin-right: 2em; }
/*** DText Preview ***/ /*** DText Preview ***/
div.dtext h1.preview-header {
margin-bottom: 0.25em; }
div.dtext p { div.dtext p {
margin-bottom: 1em; } margin-bottom: 1em; }
div.dtext ul { div.dtext ul {
@@ -455,6 +468,8 @@ div.list-of-forum-posts article {
div.list-of-forum-posts article div.content menu { div.list-of-forum-posts article div.content menu {
margin-top: 0.5em; } margin-top: 0.5em; }
div#c-forum-topics div.single-forum-post {
width: 60em; }
div#c-forum-topics div#a-show h1#forum-topic-title { div#c-forum-topics div#a-show h1#forum-topic-title {
font-size: 2em; } font-size: 2em; }
div#c-forum-topics span.info { div#c-forum-topics span.info {
@@ -465,6 +480,10 @@ div#c-forum-topics textarea {
div#c-forum-topics div#form-content { div#c-forum-topics div#form-content {
float: left; float: left;
width: 500px; } width: 500px; }
div#c-forum-topics div#dtext-help { div#c-forum-topics div#form-aside {
float: left; float: left;
width: 400px; } width: 400px; }
div#c-forum-topics div#form-aside div#preview > p {
margin-top: 0.5em;
padding-top: 0.5em;
border-top: 1px solid #AAA; }

View File

@@ -179,15 +179,33 @@ table.striped {
} }
} }
div.error-messages {
margin: 1em 0;
padding: 1em;
span.ui-icon {
float: left;
margin-right: 0.5em;
}
h1 {
font-size: 1em;
color: #A00;
}
}
div#search { div#search {
margin-bottom: 1em; margin-bottom: 1em;
} }
div#notice { div#notice {
margin: 1em; margin: 1em 0;
padding: 1em; padding: 1em;
border: 2px solid #666;
background: #EEE; span.ui-icon {
float: left;
margin-right: 0.5em;
}
} }
div#page { div#page {
@@ -320,6 +338,10 @@ form.simple_form {
/*** DText Preview ***/ /*** DText Preview ***/
div.dtext { div.dtext {
h1.preview-header {
margin-bottom: 0.25em;
}
p { p {
margin-bottom: 1em; margin-bottom: 1em;
} }
@@ -781,6 +803,10 @@ div.list-of-forum-posts {
} }
div#c-forum-topics { div#c-forum-topics {
div.single-forum-post {
width: 60em;
}
div#a-show { div#a-show {
h1#forum-topic-title { h1#forum-topic-title {
font-size: 2em; font-size: 2em;
@@ -801,8 +827,14 @@ div#c-forum-topics {
width: 500px; width: 500px;
} }
div#dtext-help { div#form-aside {
float: left; float: left;
width: 400px; width: 400px;
div#preview > p {
margin-top: 0.5em;
padding-top: 0.5em;
border-top: 1px solid #AAA;
}
} }
} }

View File

@@ -3,5 +3,5 @@
while true ; do while true ; do
script/custom/compile_javascripts ; script/custom/compile_javascripts ;
sass public/stylesheets/src/default.scss public/stylesheets/compiled/default.css ; sass public/stylesheets/src/default.scss public/stylesheets/compiled/default.css ;
sleep 1 ; sleep 2 ;
done done

View File

@@ -18,3 +18,4 @@ cat public/javascripts/src/app/unapprovals.js >> public/javascripts/compiled/def
cat public/javascripts/src/app/post_moderation.js >> public/javascripts/compiled/default.js cat public/javascripts/src/app/post_moderation.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/pools.js >> public/javascripts/compiled/default.js cat public/javascripts/src/app/pools.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/wiki_pages.js >> public/javascripts/compiled/default.js cat public/javascripts/src/app/wiki_pages.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/forum_posts.js >> public/javascripts/compiled/default.js