To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_checkout / lib / checkout / settings_controller_patch.rb @ 1315:12556ba57d17
History | View | Annotate | Download (1.34 KB)
| 1 |
require_dependency 'settings_controller'
|
|---|---|
| 2 |
|
| 3 |
module Checkout |
| 4 |
module SettingsControllerPatch |
| 5 |
def self.included(base) # :nodoc: |
| 6 |
base.send(:include, InstanceMethods) |
| 7 |
|
| 8 |
base.class_eval do
|
| 9 |
unloadable |
| 10 |
|
| 11 |
alias_method_chain :edit, :checkout |
| 12 |
end
|
| 13 |
end
|
| 14 |
|
| 15 |
module InstanceMethods |
| 16 |
def edit_with_checkout |
| 17 |
if request.post? && params['tab'] == 'checkout' |
| 18 |
if params[:settings] && params[:settings].is_a?(Hash) |
| 19 |
settings = HashWithIndifferentAccess.new
|
| 20 |
(params[:settings] || {}).each do |name, value| |
| 21 |
if name = name.to_s.slice(/checkout_(.+)/, 1) |
| 22 |
case value
|
| 23 |
when Array |
| 24 |
# remove blank values in array settings
|
| 25 |
value.delete_if {|v| v.blank? }
|
| 26 |
when Hash |
| 27 |
# change protocols hash to array.
|
| 28 |
value = value.sort{|(ak,av),(bk,bv)|ak<=>bk}.collect{|id,protocol| protocol} if name.start_with? "protocols_"
|
| 29 |
end
|
| 30 |
settings[name.to_sym] = value |
| 31 |
end
|
| 32 |
end
|
| 33 |
|
| 34 |
Setting.plugin_redmine_checkout = settings
|
| 35 |
params[:settings] = {}
|
| 36 |
end
|
| 37 |
end
|
| 38 |
edit_without_checkout |
| 39 |
end
|
| 40 |
end
|
| 41 |
end
|
| 42 |
end
|
| 43 |
|
| 44 |
SettingsController.send(:include, Checkout::SettingsControllerPatch) |