Skip to content

Commit

Permalink
Merge branch 'preconfiguration'
Browse files Browse the repository at this point in the history
Conflicts:
	config/locales/en.yml
	lib/generators/extension/extension_generator.rb
	vendor/extensions/archive
	vendor/extensions/site_templates/Rakefile
  • Loading branch information
will-r committed Nov 14, 2010
2 parents 9b1dfa6 + 95f38dd commit 65da7fb
Show file tree
Hide file tree
Showing 40 changed files with 1,074 additions and 88 deletions.
44 changes: 44 additions & 0 deletions app/controllers/admin/configuration_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Admin::ConfigurationController < ApplicationController
before_filter :initialize_config

only_allow_access_to :show, :edit, :update,
:when => [:admin],
:denied_url => { :controller => 'admin/configuration', :action => 'show' },
:denied_message => 'You must have admin privileges to edit site configuration.'

def show
@user = current_user
render
end

def edit
render
end

def update
if params[:config]
begin
Radiant.config.transaction do
params["config"].each_pair do |key, value|
@config[key] = Radiant::Config.find_or_create_by_key(key)
@config[key].value = value # validation sets errors on @config['key'] that the helper methods will pick up
end
redirect_to :action => :show
end
rescue ActiveRecord::RecordInvalid => e
flash[:error] = "Configuration error: please check the form"
render :action => :edit
rescue Radiant::Config::ConfigError => e
flash[:error] = "Configuration error: #{e}"
render :action => :edit
end
end
end

protected

def initialize_config
@config = {}
end

end
2 changes: 1 addition & 1 deletion app/controllers/admin/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def edit
def update
if valid_params?
if @user.update_attributes(params[:user])
redirect_to :action => 'show'
redirect_to admin_configuration_path
else
flash[:error] = t('preferences_controller.error_updating')
render :edit
Expand Down
80 changes: 80 additions & 0 deletions app/helpers/admin/configuration_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module Admin::ConfigurationHelper
# Defines helper methods for use in the admin interface when displaying or editing configuration.

# Renders the setting as label and value:
#
# show_config("admin.title")
# => <label for="admin_title">Admin title<label><span id="admin_title">Radiant CMS</span>
#
def show_config(key, options={})
setting = setting_for(key)
setting.valid?
domkey = key.gsub(/\W/, '_')
html = ""
html << content_tag(:label, t("config.#{key}").titlecase, :for => domkey)
if setting.boolean?
value = setting.checked? ? t('yes') : t('no')
html << content_tag(:span, value, :id => domkey, :class => "#{value} #{options[:class]}")
else
value = setting.selected_value || setting.value
html << content_tag(:span, value, :id => domkey, :class => options[:class])
end
html << content_tag(:span, " #{t("units.#{setting.units}")}", :class => 'units') if setting.units
html << content_tag(:span, [setting.errors.on(:value)].flatten.first, :class => 'warning') if setting.errors.any?
html
end

# Renders the setting as label and appropriate input field:
#
# edit_setting("admin.title")
# => <label for="admin_title">Admin title<label><input type="text" name="config['admin.title']" id="admin_title" value="Radiant CMS" />
#
# edit_config("defaults.page.status")
# =>
# <label for="defaults_page_status">Default page status<label>
# <select type="text" name="config['defaults.page.status']" id="defaults_page_status">
# <option value="Draft">Draft</option>
# ...
# </select>
#
# edit_setting("user.allow_password_reset?")
# => <label for="user_allow_password_reset_">Admin title<label><input type="checkbox" name="config['user.allow_password_reset?']" id="user_allow_password_reset_" value="1" checked="checked" />
#
def edit_config(key, options={})
setting = setting_for(key)
domkey = key.gsub(/\W/, '_')
name = "config[#{key}]"
title = t("config.#{key}").titlecase
title << content_tag(:span, " (#{t("units.#{setting.units}")})", :class => 'units') if setting.units
value = params[key.to_sym].nil? ? setting.value : params[key.to_sym]
html = ""
if setting.boolean?
html << hidden_field_tag(name, 0)
html << check_box_tag(name, 1, value, :class => 'setting', :id => domkey)
html << content_tag(:label, title, :class => 'checkbox', :for => domkey)
elsif setting.selector?
html << content_tag(:label, title, :for => domkey)
html << select_tag(name, options_for_select(setting.definition.selection, value), :class => 'setting', :id => domkey)
else
html << content_tag(:label, title, :for => domkey)
html << text_field_tag(name, value, :class => 'textbox', :id => domkey)
end
if setting.errors.any?
html << content_tag(:span, [setting.errors.on(:value)].flatten.first, :class => 'error') if setting.errors.any?
html = content_tag(:span, html, :class => "error-with-field")
end
html
end

def setting_for(key)
@config ||= {} # normally initialized in Admin::ConfigurationController
@config[key] ||= Radiant.config.find_or_create_by_key(key)
end

def definition_for(key)
if setting = setting_for(key)
setting.definition
end
end

end
3 changes: 1 addition & 2 deletions app/helpers/admin/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def homepage

def status_to_display
@page.status_id = 100 if @page.status_id == 90
@display_status = []
Status.find_all.each { |s| @display_status << [t(s.name.downcase), s.id] unless s.name == 'Scheduled' }
@display_status = Status.selectable_options
return @display_status
end

Expand Down
1 change: 1 addition & 0 deletions app/helpers/admin/preferences_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
module Admin::PreferencesHelper

end
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def pagination_for(list, options={})
depagination_limit = options.delete(:max_per_page) # supply :max_per_page => false to include the 'show all' link no matter how large the collection
html = will_paginate(list, will_paginate_options.merge(options))
if depaginate && list.total_pages > 1 && (!depagination_limit.blank? || list.total_entries <= depagination_limit.to_i)
html.insert(html.index("</div>"), content_tag(:span, link_to("show all", :pp => list.total_entries), :class => 'toggle'))
html << content_tag(:div, link_to(t('show_all'), :pp => 'all'), :class => 'depaginate')
elsif list.total_entries > depagination_limit.to_i
html = content_tag(:div, link_to("paginate", :p => 1), :class => 'pagination')
end
Expand Down
Loading

0 comments on commit 65da7fb

Please sign in to comment.