From f221da62cde073059424eddaa1f7a52ed67de848 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 21 Feb 2011 13:16:42 +1300 Subject: Added settings click-button functionality for toggling comments being enabled, with translations. --- app/controllers/admin/blog/settings_controller.rb | 16 ++++++++++++++-- app/models/blog_comment.rb | 9 ++++++++- app/views/admin/blog/_submenu.html.erb | 4 ++++ 3 files changed, 26 insertions(+), 3 deletions(-) (limited to 'app') 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 => "" + render :text => "", + :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 @@ -72,6 +72,10 @@ <%= link_to t('.settings.title'), admin_blog_settings_path, :class => 'settings_icon' %> +
  • + <%= link_to t('.settings.comments'), comments_admin_blog_settings_url, + :class => "#{BlogPost.comments_allowed? ? 'success' : 'failure'}_icon" %> +
  • <%= link_to t('.settings.moderation'), moderation_admin_blog_settings_url, :class => "#{BlogComment::Moderation.enabled? ? 'success' : 'failure'}_icon" %> -- cgit v1.2.3