forked from radiant/radiant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: config/locales/en.yml lib/generators/extension/extension_generator.rb vendor/extensions/archive vendor/extensions/site_templates/Rakefile
- Loading branch information
Showing
40 changed files
with
1,074 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
module Admin::PreferencesHelper | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.