aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/refinery/blog
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/refinery/blog')
-rw-r--r--app/controllers/refinery/blog/admin/categories_controller.rb13
-rw-r--r--app/controllers/refinery/blog/admin/comments_controller.rb49
-rw-r--r--app/controllers/refinery/blog/admin/posts_controller.rb92
-rw-r--r--app/controllers/refinery/blog/admin/settings_controller.rb55
4 files changed, 209 insertions, 0 deletions
diff --git a/app/controllers/refinery/blog/admin/categories_controller.rb b/app/controllers/refinery/blog/admin/categories_controller.rb
new file mode 100644
index 0000000..cbde1cc
--- /dev/null
+++ b/app/controllers/refinery/blog/admin/categories_controller.rb
@@ -0,0 +1,13 @@
+module Refinery
+ module Blog
+ module Admin
+ class CategoriesController < ::Refinery::AdminController
+
+ crudify :'refinery/blog/category',
+ :title_attribute => :title,
+ :order => 'title ASC'
+
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/blog/admin/comments_controller.rb b/app/controllers/refinery/blog/admin/comments_controller.rb
new file mode 100644
index 0000000..3128e97
--- /dev/null
+++ b/app/controllers/refinery/blog/admin/comments_controller.rb
@@ -0,0 +1,49 @@
+module Refinery
+ module Blog
+ module Admin
+ class CommentsController < ::Refinery::AdminController
+
+ cache_sweeper Refinery::BlogSweeper
+
+ crudify :'refinery/blog/comment',
+ :title_attribute => :name,
+ :order => 'published_at DESC'
+
+ def index
+ @blog_comments = Refinery::Blog::Comment.unmoderated.page(params[:page])
+
+ render :action => 'index'
+ end
+
+ def approved
+ unless params[:id].present?
+ @blog_comments = Refinery::Blog::Comment.approved.page(params[:page])
+
+ render :action => 'index'
+ else
+ @blog_comment = Refinery::Blog::Comment.find(params[:id])
+ @blog_comment.approve!
+ flash[:notice] = t('approved', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
+
+ redirect_to main_app.url_for(:action => params[:return_to] || 'index')
+ end
+ end
+
+ def rejected
+ unless params[:id].present?
+ @blog_comments = Refinery::Blog::Comment.rejected.page(params[:page])
+
+ render :action => 'index'
+ else
+ @blog_comment = Refinery::Blog::Comment.find(params[:id])
+ @blog_comment.reject!
+ flash[:notice] = t('rejected', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
+
+ redirect_to main_app.url_for(:action => params[:return_to] || 'index')
+ end
+ end
+
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/blog/admin/posts_controller.rb b/app/controllers/refinery/blog/admin/posts_controller.rb
new file mode 100644
index 0000000..04ee663
--- /dev/null
+++ b/app/controllers/refinery/blog/admin/posts_controller.rb
@@ -0,0 +1,92 @@
+module Refinery
+ module Blog
+ module Admin
+ class PostsController < ::Refinery::AdminController
+
+ cache_sweeper Refinery::BlogSweeper
+
+ crudify :'refinery/blog/post',
+ :title_attribute => :title,
+ :order => 'published_at DESC',
+ :redirect_to_url => "main_app.refinery_blog_admin_posts_path"
+
+ before_filter :find_all_categories,
+ :only => [:new, :edit, :create, :update]
+
+ before_filter :check_category_ids, :only => :update
+
+ def uncategorized
+ @blog_posts = Refinery::Blog::Post.uncategorized.page(params[:page])
+ end
+
+ def tags
+ if ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
+ op = '~*'
+ wildcard = '.*'
+ else
+ op = 'LIKE'
+ wildcard = '%'
+ end
+
+ @tags = Refinery::Blog::Post.tag_counts_on(:tags).where(
+ ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
+ ).map { |tag| {:id => tag.id, :value => tag.name}}
+ render :json => @tags.flatten
+ end
+
+ def new
+ @blog_post = ::Refinery::Blog::Post.new(:author => current_refinery_user)
+ end
+
+ def create
+ # if the position field exists, set this object as last object, given the conditions of this class.
+ if Refinery::Blog::Post.column_names.include?("position")
+ params[:blog_post].merge!({
+ :position => ((Refinery::Blog::Post.maximum(:position, :conditions => "")||-1) + 1)
+ })
+ end
+
+ if (@blog_post = Refinery::Blog::Post.create(params[:blog_post])).valid?
+ (request.xhr? ? flash.now : flash).notice = t(
+ 'refinery.crudify.created',
+ :what => "'#{@blog_post.title}'"
+ )
+
+ unless from_dialog?
+ unless params[:continue_editing] =~ /true|on|1/
+ redirect_back_or_default(main_app.refinery_blog_admin_posts_path)
+ else
+ unless request.xhr?
+ redirect_to :back
+ else
+ render :partial => "/shared/message"
+ end
+ end
+ else
+ render :text => "<script>parent.window.location = '#{admin_blog_posts_url}';</script>"
+ end
+ else
+ unless request.xhr?
+ render :action => 'new'
+ else
+ render :partial => "/refinery/admin/error_messages",
+ :locals => {
+ :object => @blog_post,
+ :include_object_name => true
+ }
+ end
+ end
+ end
+
+ protected
+ def find_all_categories
+ @blog_categories = Refinery::Blog::Category.find(:all)
+ end
+
+ def check_category_ids
+ params[:blog_post][:category_ids] ||= []
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/blog/admin/settings_controller.rb b/app/controllers/refinery/blog/admin/settings_controller.rb
new file mode 100644
index 0000000..afa6b2b
--- /dev/null
+++ b/app/controllers/refinery/blog/admin/settings_controller.rb
@@ -0,0 +1,55 @@
+module Refinery
+ module Blog
+ module Admin
+ class SettingsController < ::Refinery::AdminController
+
+ def notification_recipients
+ @recipients = Refinery::Blog::Comment::Notification.recipients
+
+ if request.post?
+ Refinery::Blog::Comment::Notification.recipients = params[:recipients]
+ flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients',
+ :recipients => Refinery::Blog::Comment::Notification.recipients)
+ unless request.xhr? or from_dialog?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :text => "<script type='text/javascript'>parent.window.location = '#{admin_blog_posts_path}';</script>",
+ :layout => false
+ end
+ end
+ end
+
+ def moderation
+ enabled = Refinery::Blog::Comment::Moderation.toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
+
+ def comments
+ enabled = Refinery::Blog::Comment.toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
+
+ def teasers
+ enabled = Refinery::Blog::Post.teaser_enabled_toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
+
+ end
+ end
+ end
+end