diff vendor/plugins/redmine_checkout/lib/checkout/settings_controller_patch.rb @ 16:020926a36823 yuya

* Add redmine-checkout plugin (as of svn rev 179 of the plugin)
author Chris Cannam
date Wed, 25 Aug 2010 16:39:01 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_checkout/lib/checkout/settings_controller_patch.rb	Wed Aug 25 16:39:01 2010 +0100
@@ -0,0 +1,44 @@
+require_dependency 'settings_controller'
+
+module Checkout
+  module SettingsControllerPatch
+    def self.included(base) # :nodoc:
+      base.send(:include, InstanceMethods)
+
+      base.class_eval do
+        unloadable
+      
+        alias_method_chain :edit, :checkout
+      end
+    end
+    
+    module InstanceMethods
+      def edit_with_checkout
+        if request.post? && params['tab'] == 'checkout'
+          if params[:settings] && params[:settings].is_a?(Hash)
+            settings = HashWithIndifferentAccess.new
+            (params[:settings] || {}).each do |name, value|
+              if name = name.to_s.slice(/checkout_(.+)/, 1)
+                case value
+                when Array
+                  # remove blank values in array settings
+                  value.delete_if {|v| v.blank? }
+                when Hash
+                  # change protocols hash to array.
+                  value = value.sort{|(ak,av),(bk,bv)|ak<=>bk}.collect{|id,protocol| protocol} if name.start_with? "protocols_"
+                end
+                settings[name.to_sym] = value
+              end
+            end
+                        
+            Setting.plugin_redmine_checkout = settings
+            params[:settings] = {}
+          end
+        end
+        edit_without_checkout
+      end
+    end
+  end
+end
+
+SettingsController.send(:include, Checkout::SettingsControllerPatch)