Permalink
Browse files

Merge branch 'master' of git@github.com:joshuaclayton/fuzzy-monster

Conflicts:
	app/views/forums/_recordset.html.erb
  • Loading branch information...
2 parents 98ea668 + b4be1cb commit a1a10b501fce7ae4d87bb8b236d23384c7929c13 Joshua Clayton committed Apr 21, 2009
Showing 402 changed files with 11,242 additions and 60,577 deletions.
@@ -5,6 +5,10 @@ class ForumsController < ApplicationController
ForumsPresenter.new(:current_user => current_user).can_be_created_by_current_user?
end
+ restrict_to :only => [:reorder] do
+ ForumsPresenter.new(:current_user => current_user).can_be_reordered_by_current_user?
+ end
+
restrict_to :only => [:edit, :update] do
object.can_be_edited_by_current_user?
end
@@ -13,9 +17,15 @@ class ForumsController < ApplicationController
object.can_be_deleted_by_current_user?
end
+ index.wants.js
index.wants.xml { render :xml => @forums }
show.wants.xml { render :xml => @forum }
+ def reorder
+ Forum.reorder params['forums-tbody']
+ index
+ end
+
private
def collection
View
@@ -1,14 +1,22 @@
class Forum < ActiveRecord::Base
acts_as_list
+
has_permalink :name, :slug
named_scope :ordered, {:order => "#{Forum.table_name}.position ASC"}
- has_many :topics, :order => "#{Topic.table_name}.sticky DESC, #{Topic.table_name}.last_updated_at DESC", :dependent => :delete_all
+ has_many :topics, :order => "#{Topic.table_name}.sticky DESC, #{Topic.table_name}.last_updated_at DESC", :dependent => :destroy
validates_presence_of :name
def to_param
self.slug
end
+
+ def self.reorder(array_of_ids)
+ array_of_ids.each_with_index do |id, index|
+ forum = self.find(id) rescue nil
+ forum.update_attribute(:position, index + 1) if forum
+ end
+ end
end
View
@@ -1,21 +1,42 @@
+module Posts
+ module Callbacks
+ def self.included(base)
+ base.send :include, Posts::Callbacks::InstanceMethods
+ base.before_validation_on_create :set_forum_from_topic
+ end
+
+ module InstanceMethods
+ protected
+
+ def set_forum_from_topic
+ self.forum = self.topic.forum
+ end
+ end
+ end
+ module Validations
+ def self.included(base)
+ base.send :include, Posts::Validations::InstanceMethods
+ base.validate :topic_is_not_locked, :if => lambda {|post| post.topic && post.topic.posts_count > 0}
+ base.validates_presence_of :author_id, :forum_id, :topic_id, :body
+ end
+
+ module InstanceMethods
+ protected
+
+ def topic_is_not_locked
+ errors.add(:topic_id, "is locked") if self.topic.locked?
+ end
+ end
+ end
+end
+
class Post < ActiveRecord::Base
+ include Posts::Callbacks
+ include Posts::Validations
+
belongs_to :author, :class_name => "User", :foreign_key => :author_id, :counter_cache => true
belongs_to :forum, :counter_cache => true
belongs_to :topic, :counter_cache => true
- before_validation_on_create :set_forum_from_topic
- validate :topic_is_not_locked, :if => lambda {|post| post.topic && post.topic.posts_count > 0}
- validates_presence_of :author_id, :forum_id, :topic_id, :body
-
delegate :name, :to => :forum, :prefix => true
-
- protected
-
- def set_forum_from_topic
- self.forum = self.topic.forum
- end
-
- def topic_is_not_locked
- errors.add(:topic_id, "is locked") if self.topic.locked?
- end
end
View
@@ -1,8 +1,37 @@
+module Topics
+ module Callbacks
+ def self.included(base)
+ base.send :include, Topics::Callbacks::InstanceMethods
+ base.after_create :create_initial_post
+ end
+
+ module InstanceMethods
+ protected
+ def create_initial_post
+ self.posts.create(:author => self.creator, :body => self.body)
+ end
+ end
+ end
+ module Validations
+ def self.included(base)
+ base.validates_presence_of :title, :creator_id, :forum_id
+ base.validates_presence_of :body, :on => :create
+ end
+ end
+ module NamedScopes
+ def self.included(base)
+ base.named_scope :sticky, { :conditions => {:sticky => true} }
+ base.named_scope :not_sticky, { :conditions => {:sticky => false} }
+ end
+ end
+end
+
class Topic < ActiveRecord::Base
- has_permalink :title, :slug, :scope => :forum_id
+ include Topics::Callbacks
+ include Topics::Validations
+ include Topics::NamedScopes
- named_scope :sticky, { :conditions => {:sticky => true} }
- named_scope :not_sticky, { :conditions => {:sticky => false}}
+ has_permalink :title, :slug, :scope => :forum_id
belongs_to :forum, :counter_cache => true
belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
@@ -12,13 +41,7 @@ class Topic < ActiveRecord::Base
belongs_to :last_post, :class_name => "Post", :foreign_key => :last_post_id
belongs_to :last_user, :class_name => "User", :foreign_key => :last_user_id
- validates_presence_of :title, :creator_id, :forum_id
- validates_presence_of :body, :on => :create
-
- after_create :create_initial_post
-
attr_accessible :title, :body, :forum, :creator, :sticky, :locked
-
attr_accessor :body
def view!
@@ -28,10 +51,4 @@ def view!
def to_param
self.slug
end
-
- protected
-
- def create_initial_post
- self.posts.create(:author => self.creator, :body => self.body)
- end
end
@@ -8,11 +8,11 @@ def initialize(options = {})
end
def can_be_edited_by_current_user?
- !!(@current_user && @current_user.has_privilege?(:admin))
+ is_current_user_admin?
end
def can_be_deleted_by_current_user?
- false
+ is_current_user_admin?
end
def can_topic_be_created_by_current_user?
@@ -22,4 +22,10 @@ def can_topic_be_created_by_current_user?
def method_missing(call, *args)
@forum.send call, *args
end
+
+ private
+
+ def is_current_user_admin?
+ !!(@current_user && @current_user.has_privilege?(:admin))
+ end
end
@@ -5,15 +5,26 @@ class ForumsPresenter
def initialize(options = {})
options.assert_valid_keys(:forums, :current_user)
- @forums = options[:forums] || Forum.ordered
@current_user = options[:current_user]
+ @forums = options[:forums] || Forum.ordered
+ @forums = @forums.map {|forum| ForumPresenter.new(:forum => forum, :current_user => @current_user) }
end
def can_be_created_by_current_user?
- !!(@current_user && @current_user.has_privilege?(:admin))
+ is_current_user_admin?
+ end
+
+ def can_be_reordered_by_current_user?
+ is_current_user_admin?
end
def each(&block)
@forums.each(&block)
end
+
+ private
+
+ def is_current_user_admin?
+ !!(@current_user && @current_user.has_privilege?(:admin))
+ end
end
@@ -3,7 +3,9 @@
<% forums.each do |forum| %>
<% zebra_row :id => dom_id(forum), :class => ("grabbable" if forums.can_be_reordered_by_current_user?) do %>
<td>
- <span class="forum-title"><%= link_to forum.name, forum %></span><br/>
+ <span class="forum-title"><%= link_to forum.name, forum %></span>
+ <%= link_to "Delete", forum, :method => :delete, :confirm => "Are you sure?" if forum.can_be_deleted_by_current_user? %>
+ <br/>
<%= textilize forum.description %>
</td>
<td class="number"><%= forum.topics_count %></td>
@@ -1,18 +1,7 @@
<% sub_header do %>Forums<% end %>
<% content do %>
- <% recordset :headers => ["Forum", ["Topics", {:class => "number"}], ["Posts", {:class => "number"}]], :table => {:class => "forums"} do %>
- <tbody>
- <% @forums.each do |forum| %>
- <% zebra_row do %>
- <td>
- <span class="forum-title"><%= link_to forum.name, forum %></span><br/>
- <%= textilize forum.description %>
- </td>
- <td class="number"><%= forum.topics_count %></td>
- <td class="number"><%= forum.posts_count %></td>
- <% end %>
- <% end %>
- </tbody>
+ <% column :full, :id => "forums-recordset" do %>
+ <%= render :partial => "forums/recordset", :locals => {:forums => @forums} %>
<% end %>
<% end %>
<% extra_content do %>
@@ -42,7 +42,7 @@
<% end %>
</div>
<div id="notification" style="display: none;"><%= image_tag("ajax-loader.gif") %> Waiting...</div>
- <%= javascript_include_tag "jquery", "jrails" %>
+ <%= javascript_include_tag "jquery", "jrails", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.2/jquery-ui.min.js" %>
<%= yield :footer %>
</body>
View
@@ -67,7 +67,7 @@ def load_rails_gem
class << self
def rubygems_version
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ Gem::RubyGemsVersion rescue nil
end
def gem_version
@@ -82,7 +82,7 @@ def gem_version
def load_rubygems
require 'rubygems'
- min_version = '1.1.1'
+ min_version = '1.3.1'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
View
@@ -4,11 +4,12 @@
config.frameworks -= [ :active_resource ]
config.action_controller.session = {
- :session_key => '_demo_session',
+ :session_key => '_fuzzy_monster_session',
:secret => '7d335e0169857cce16b2b0bb98acb77730263c9ab4c37add6960974d5a805b2443b5d20974202ca85e576b47447bf8d33b28cae1d0bc32cb8e3585f31bd72021'
}
- config.gem 'gravtastic'
+ config.gem "gravtastic"
+ config.gem "thoughtbot-factory_girl", :lib => "factory_girl"
config.load_paths += %W( #{RAILS_ROOT}/app/observers
#{RAILS_ROOT}/app/mailers
View
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
View
@@ -1,5 +1,5 @@
ActionController::Routing::Routes.draw do |map|
- map.resources :forums do |forums_map|
+ map.resources :forums, :collection => {:reorder => :put} do |forums_map|
forums_map.resources :topics do |topics_map|
topics_map.resources :posts
end
Oops, something went wrong.

0 comments on commit a1a10b5

Please sign in to comment.