settings_controller.rb
66 lines
| 2.4 KiB
| text/x-ruby
|
RubyLexer
|
r5707 | # Redmine - project management software | ||
|
r9453 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r164 | # | ||
# This program is free software; you can redistribute it and/or | ||||
# modify it under the terms of the GNU General Public License | ||||
# as published by the Free Software Foundation; either version 2 | ||||
# of the License, or (at your option) any later version. | ||||
|
r1987 | # | ||
|
r164 | # This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
|
r1987 | # | ||
|
r164 | # You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
class SettingsController < ApplicationController | ||||
|
r3062 | layout 'admin' | ||
|
r8559 | menu_item :plugins, :only => :plugin | ||
|
r5707 | |||
|
r164 | before_filter :require_admin | ||
|
r1987 | |||
|
r164 | def index | ||
edit | ||||
render :action => 'edit' | ||||
end | ||||
def edit | ||||
|
r4106 | @notifiables = Redmine::Notifiable.all | ||
|
r1033 | if request.post? && params[:settings] && params[:settings].is_a?(Hash) | ||
settings = (params[:settings] || {}).dup.symbolize_keys | ||||
settings.each do |name, value| | ||||
# remove blank values in array settings | ||||
value.delete_if {|v| v.blank? } if value.is_a?(Array) | ||||
Setting[name] = value | ||||
end | ||||
flash[:notice] = l(:notice_successful_update) | ||||
redirect_to :action => 'edit', :tab => params[:tab] | ||||
|
r5491 | else | ||
@options = {} | ||||
|
r10331 | user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]} | ||
|
r10333 | @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]} | ||
|
r5491 | @deliveries = ActionMailer::Base.perform_deliveries | ||
|
r1987 | |||
|
r5491 | @guessed_host_and_path = request.host_with_port.dup | ||
@guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank? | ||||
|
r5707 | |||
|
r5491 | Redmine::Themes.rescan | ||
end | ||||
|
r164 | end | ||
|
r1987 | |||
|
r741 | def plugin | ||
|
r2037 | @plugin = Redmine::Plugin.find(params[:id]) | ||
|
r741 | if request.post? | ||
|
r7919 | Setting.send "plugin_#{@plugin.id}=", params[:settings] | ||
|
r741 | flash[:notice] = l(:notice_successful_update) | ||
|
r2037 | redirect_to :action => 'plugin', :id => @plugin.id | ||
|
r5491 | else | ||
@partial = @plugin.settings[:partial] | ||||
|
r7919 | @settings = Setting.send "plugin_#{@plugin.id}" | ||
|
r741 | end | ||
|
r2037 | rescue Redmine::PluginNotFound | ||
render_404 | ||||
|
r741 | end | ||
|
r164 | end | ||