Permalink
Browse files

Implemented configuration controller & views

- ConfigurationController with update_category action implemented
- AdministrationController's configuration action implemented
- app/views/config/* and app/views/administration/configuration.rhtml
- Route for config controller added
  • Loading branch information...
1 parent f08d560 commit 8e3448f988faada656bca244c28de80eb683241b @jamesu committed May 22, 2008
@@ -46,8 +46,7 @@ def clients
end
def configuration
- error_status(true, :edit_config_yml_for_options)
- redirect_back_or_default :controller => 'administration'
+ @categories = ConfigCategory.find(:all, :order => 'category_order DESC')
end
def tools
@@ -5,9 +5,50 @@
=end
class ConfigController < ApplicationController
-
+ layout 'administration'
+
before_filter :login_required
before_filter :process_session
- after_filter :user_track
+
+ def update_category
+ begin
+ @category = ConfigCategory.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ error_status(true, :invalid_category)
+ redirect_to :controller => 'administration', :action => 'configuration'
+ return false
+ end
+
+ if @category.options.empty?
+ error_status(true, :config_category_empty)
+ redirect_to :controller => 'administration', :action => 'configuration'
+ end
+
+ @content_for_sidebar = 'update_category_sidebar'
+ @options = @category.options
+ @categories = ConfigCategory.find(:all, :order => 'category_order DESC')
+
+ case request.method
+ when :post
+ option_values = params[:options]
+
+ @options.each do |option|
+ if option_values.has_key? option.name
+ option.value = option_values[option.name]
+ option.save
+ end
+ end
+
+ # Force reload of configuration
+ ConfigOption.reload_all
+
+ error_status(false, :success_updated_config_category)
+ redirect_to :controller => 'administration', :action => 'configuration'
+ end
+ end
+
+ def authorize?(user)
+ return user.is_admin
+ end
end
@@ -5,4 +5,5 @@
=end
module ConfigHelper
+ include AdministrationHelper
end
@@ -0,0 +1,26 @@
+<%
+ @page_title = :configuration.l
+
+ @tabbed_navigation_items = administration_tabbed_navigation(:configuration)
+ @bread_crumbs = administration_crumbs(:configuration)
+
+ @page_actions = []
+
+ @additional_stylesheets = []
+%>
+
+<div id="configuration">
+<% if !@categories.empty? %>
+<% @categories.each do |category| -%>
+<% if !category.options.empty? %>
+ <div class="configCategory" id="category_<%= category.name %>">
+ <h2><%= link_to h(category.display_name), :controller => 'config', :action => 'update_category', :id => category.id %></h2>
+<% if !category.display_description.strip.empty? %>
+ <div class="configCategoryDescription"><%= textilize category.display_description %></div>
+<% end %>
+ </div>
+
+<% end %>
+<% end %>
+<% end %>
+</div>
@@ -0,0 +1,12 @@
+<% if !@categories.empty? %>
+<div class="sidebarBlock">
+ <h2><%= :configuration_categories.l %></h2>
+ <div class="blockContent">
+ <ul class="listWithDetails">
+<% @categories.each do |category| -%>
+ <li><%= link_to h(category.display_name), :controller => 'config', :action => 'update_category', :id => category.id %></li>
+<% end %>
+ </ul>
+ </div>
+</div>
+<% end %>
@@ -0,0 +1,40 @@
+<%
+ @page_title = @category.display_name
+
+ @tabbed_navigation_items = administration_tabbed_navigation(:configuration)
+ @bread_crumbs = administration_crumbs(@category.display_name, [{:title => :configuration, :url => "/administration/configuration"}])
+
+ @page_actions = []
+
+ @additional_stylesheets = ['admin/config']
+%>
+
+<% if !@options.empty? %>
+<%= form_tag :controller => 'config', :action => 'update_category', :id => @category.id %>
+ <div id="configCategoryOptions">
+<% counter = 0 %>
+<% @options.each do |option| -%>
+ <% counter += 1 %>
+ <% if (counter % 2) == 1 %>
+ <div class="configCategoryOption even"
+ <% else %>
+ <div class="configCategoryOption odd"
+ <% end %> id="configCategoryOption_<%= option.name %>">
+ <div class="configOptionInfo">
+ <div class="configOptionLabel"><label><%= h(option.display_name) %>:</label></div>
+<% option_description = option.display_description.strip %>
+<% if !option_description.empty? %>
+ <div class="configOptionDescription desc"><%= h(option_description) %></div>
+<% end %>
+ </div>
+ <div class="configOptionControl"><%= option.render("options[#{option.name}]", {}) %></div>
+ <div class="clear"></div>
+ </div>
+<% end %>
+ </div>
+
+ <button class="submit" type="submit"><%= :save.l %></button>&nbsp;<button type="reset"><%= :reset.l %></button>
+</form>
+<% else %>
+<p><%= :config_category_empty.l %></p>
+<% end %>
View
@@ -41,7 +41,7 @@
# The rest of the simple controllers
- ['dashboard', 'access', 'administration', 'comment', 'user'].each do |controller|
+ ['dashboard', 'access', 'administration', 'comment', 'user', 'config'].each do |controller|
map.connect "#{controller}/:action/:id", :controller => controller
map.connect "#{controller}/:action/:id.format", :controller => controller
end

0 comments on commit 8e3448f

Please sign in to comment.