From b3a25c1b686d205fc6b8b409a8f90059ae6b934d Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 9 Jan 2012 10:38:26 +1300 Subject: Restructured part of the project to Refinery::Blog::Admin not Refinery::Admin::Blog --- .../refinery/admin/blog/categories_controller.rb | 13 --- .../refinery/admin/blog/comments_controller.rb | 49 ------------ .../refinery/admin/blog/posts_controller.rb | 92 ---------------------- .../refinery/admin/blog/settings_controller.rb | 55 ------------- .../refinery/blog/admin/categories_controller.rb | 13 +++ .../refinery/blog/admin/comments_controller.rb | 49 ++++++++++++ .../refinery/blog/admin/posts_controller.rb | 92 ++++++++++++++++++++++ .../refinery/blog/admin/settings_controller.rb | 55 +++++++++++++ 8 files changed, 209 insertions(+), 209 deletions(-) delete mode 100644 app/controllers/refinery/admin/blog/categories_controller.rb delete mode 100644 app/controllers/refinery/admin/blog/comments_controller.rb delete mode 100644 app/controllers/refinery/admin/blog/posts_controller.rb delete mode 100644 app/controllers/refinery/admin/blog/settings_controller.rb create mode 100644 app/controllers/refinery/blog/admin/categories_controller.rb create mode 100644 app/controllers/refinery/blog/admin/comments_controller.rb create mode 100644 app/controllers/refinery/blog/admin/posts_controller.rb create mode 100644 app/controllers/refinery/blog/admin/settings_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/refinery/admin/blog/categories_controller.rb b/app/controllers/refinery/admin/blog/categories_controller.rb deleted file mode 100644 index 0fe4eec..0000000 --- a/app/controllers/refinery/admin/blog/categories_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Refinery - module Admin - module Blog - class CategoriesController < ::Refinery::AdminController - - crudify :'refinery/blog/category', - :title_attribute => :title, - :order => 'title ASC' - - end - end - end -end diff --git a/app/controllers/refinery/admin/blog/comments_controller.rb b/app/controllers/refinery/admin/blog/comments_controller.rb deleted file mode 100644 index 6c1417e..0000000 --- a/app/controllers/refinery/admin/blog/comments_controller.rb +++ /dev/null @@ -1,49 +0,0 @@ -module Refinery - module Admin - module Blog - 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/admin/blog/posts_controller.rb b/app/controllers/refinery/admin/blog/posts_controller.rb deleted file mode 100644 index 4645f3f..0000000 --- a/app/controllers/refinery/admin/blog/posts_controller.rb +++ /dev/null @@ -1,92 +0,0 @@ -module Refinery - module Admin - module Blog - 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_admin_blog_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_admin_blog_posts_path) - else - unless request.xhr? - redirect_to :back - else - render :partial => "/shared/message" - end - end - else - render :text => "" - 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/admin/blog/settings_controller.rb b/app/controllers/refinery/admin/blog/settings_controller.rb deleted file mode 100644 index ee71393..0000000 --- a/app/controllers/refinery/admin/blog/settings_controller.rb +++ /dev/null @@ -1,55 +0,0 @@ -module Refinery - module Admin - module Blog - 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 => "", - :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 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 => "" + 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 => "", + :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 -- cgit v1.2.3