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
|
||||
|
||||
@@ -20,6 +20,10 @@ class ForumPostsController < ApplicationController
|
||||
respond_with(@forum_posts)
|
||||
end
|
||||
|
||||
def search
|
||||
@search = ForumPost.search(params[:search])
|
||||
end
|
||||
|
||||
def show
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
respond_with(@forum_post)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -20,6 +21,18 @@ class ForumPost < ActiveRecord::Base
|
||||
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?
|
||||
end
|
||||
|
||||
@@ -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>
|
||||
@@ -2,9 +2,8 @@
|
||||
<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>
|
||||
<%= render "form" %>
|
||||
<%= error_messages_for "forum_post" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<%= f.input :topic_id, :as => :hidden %>
|
||||
<%= f.input :body %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</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>
|
||||
|
||||
@@ -2,18 +2,6 @@
|
||||
<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">
|
||||
|
||||
@@ -19,7 +19,11 @@ Danbooru::Application.routes.draw do
|
||||
resources :dmails
|
||||
resources :favorites
|
||||
resources :forum_topics
|
||||
resources :forum_posts
|
||||
resources :forum_posts do
|
||||
collection do
|
||||
get :search
|
||||
end
|
||||
end
|
||||
resources :janitor_trials do
|
||||
member do
|
||||
put :promote
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
||||
Danbooru.Comment = {};
|
||||
|
||||
Danbooru.Comment.initialize_all = function() {
|
||||
$("#c-comments div.dtext-preview").hide();
|
||||
$("div.dtext-preview").hide();
|
||||
this.initialize_response_link();
|
||||
this.initialize_preview_button();
|
||||
}
|
||||
|
||||
35
public/javascripts/src/app/forum_posts.js
Normal file
35
public/javascripts/src/app/forum_posts.js
Normal 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();
|
||||
});
|
||||
@@ -134,14 +134,25 @@ table.striped tbody tr:hover {
|
||||
table.striped tr.even {
|
||||
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 {
|
||||
margin-bottom: 1em; }
|
||||
|
||||
div#notice {
|
||||
margin: 1em;
|
||||
padding: 1em;
|
||||
border: 2px solid #666;
|
||||
background: #EEE; }
|
||||
margin: 1em 0;
|
||||
padding: 1em; }
|
||||
div#notice span.ui-icon {
|
||||
float: left;
|
||||
margin-right: 0.5em; }
|
||||
|
||||
div#page aside#sidebar {
|
||||
width: 20%;
|
||||
@@ -222,6 +233,8 @@ form.simple_form {
|
||||
margin-right: 2em; }
|
||||
|
||||
/*** DText Preview ***/
|
||||
div.dtext h1.preview-header {
|
||||
margin-bottom: 0.25em; }
|
||||
div.dtext p {
|
||||
margin-bottom: 1em; }
|
||||
div.dtext ul {
|
||||
@@ -455,6 +468,8 @@ div.list-of-forum-posts article {
|
||||
div.list-of-forum-posts article div.content menu {
|
||||
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 {
|
||||
font-size: 2em; }
|
||||
div#c-forum-topics span.info {
|
||||
@@ -465,6 +480,10 @@ div#c-forum-topics textarea {
|
||||
div#c-forum-topics div#form-content {
|
||||
float: left;
|
||||
width: 500px; }
|
||||
div#c-forum-topics div#dtext-help {
|
||||
div#c-forum-topics div#form-aside {
|
||||
float: left;
|
||||
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; }
|
||||
|
||||
@@ -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 {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
div#notice {
|
||||
margin: 1em;
|
||||
margin: 1em 0;
|
||||
padding: 1em;
|
||||
border: 2px solid #666;
|
||||
background: #EEE;
|
||||
|
||||
span.ui-icon {
|
||||
float: left;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
}
|
||||
|
||||
div#page {
|
||||
@@ -320,6 +338,10 @@ form.simple_form {
|
||||
/*** DText Preview ***/
|
||||
|
||||
div.dtext {
|
||||
h1.preview-header {
|
||||
margin-bottom: 0.25em;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
@@ -781,6 +803,10 @@ div.list-of-forum-posts {
|
||||
}
|
||||
|
||||
div#c-forum-topics {
|
||||
div.single-forum-post {
|
||||
width: 60em;
|
||||
}
|
||||
|
||||
div#a-show {
|
||||
h1#forum-topic-title {
|
||||
font-size: 2em;
|
||||
@@ -801,8 +827,14 @@ div#c-forum-topics {
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
div#dtext-help {
|
||||
div#form-aside {
|
||||
float: left;
|
||||
width: 400px;
|
||||
|
||||
div#preview > p {
|
||||
margin-top: 0.5em;
|
||||
padding-top: 0.5em;
|
||||
border-top: 1px solid #AAA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
while true ; do
|
||||
script/custom/compile_javascripts ;
|
||||
sass public/stylesheets/src/default.scss public/stylesheets/compiled/default.css ;
|
||||
sleep 1 ;
|
||||
sleep 2 ;
|
||||
done
|
||||
|
||||
@@ -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/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/forum_posts.js >> public/javascripts/compiled/default.js
|
||||
|
||||
Reference in New Issue
Block a user