diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/blog/settings_controller.rb | 16 | ||||
-rw-r--r-- | app/models/blog_comment.rb | 9 | ||||
-rw-r--r-- | app/views/admin/blog/_submenu.html.erb | 4 |
3 files changed, 26 insertions, 3 deletions
diff --git a/app/controllers/admin/blog/settings_controller.rb b/app/controllers/admin/blog/settings_controller.rb index cc9261b..a805d9c 100644 --- a/app/controllers/admin/blog/settings_controller.rb +++ b/app/controllers/admin/blog/settings_controller.rb @@ -10,7 +10,8 @@ class Admin::Blog::SettingsController < Admin::BaseController 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>" + render :text => "<script type='text/javascript'>parent.window.location = '#{admin_blog_posts_path}';</script>", + :layout => false end end end @@ -20,7 +21,18 @@ class Admin::Blog::SettingsController < Admin::BaseController unless request.xhr? redirect_back_or_default(admin_blog_posts_path) else - render :json => {:enabled => enabled} + render :json => {:enabled => enabled}, + :layout => false + end + end + + def comments + enabled = BlogComment.toggle! + unless request.xhr? + redirect_back_or_default(admin_blog_posts_path) + else + render :json => {:enabled => enabled}, + :layout => false end end diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 015b96d..13aceb1 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -13,7 +13,7 @@ class BlogComment < ActiveRecord::Base alias_attribute :message, :body validates :name, :message, :presence => true - validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } + validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } scope :unmoderated, :conditions => {:state => nil} scope :approved, :conditions => {:state => 'approved'} @@ -39,6 +39,13 @@ class BlogComment < ActiveRecord::Base self.state.nil? end + def self.toggle! + currently = RefinerySetting.find_or_set(:comments_allowed, true, { + :scoping => 'blog' + }) + RefinerySetting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'}) + end + before_create do |comment| unless BlogComment::Moderation.enabled? comment.state = comment.ham? ? 'approved' : 'rejected' diff --git a/app/views/admin/blog/_submenu.html.erb b/app/views/admin/blog/_submenu.html.erb index f6f1c55..b93e30d 100644 --- a/app/views/admin/blog/_submenu.html.erb +++ b/app/views/admin/blog/_submenu.html.erb @@ -73,6 +73,10 @@ :class => 'settings_icon' %> </li> <li> + <%= link_to t('.settings.comments'), comments_admin_blog_settings_url, + :class => "#{BlogPost.comments_allowed? ? 'success' : 'failure'}_icon" %> + </li> + <li> <%= link_to t('.settings.moderation'), moderation_admin_blog_settings_url, :class => "#{BlogComment::Moderation.enabled? ? 'success' : 'failure'}_icon" %> </li> |