From 5b96d1b083a82d3ae68072c77af9521e720a3af8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 26 Feb 2009 16:15:07 +0000 Subject: Allow underscore in block partial name (#2840). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2528 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/my_controller.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'app/controllers/my_controller.rb') diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 5e1b9d2c8..ae063d60a 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -108,14 +108,14 @@ class MyController < ApplicationController session[:page_layout] = @blocks %w(top left right).each {|f| session[:page_layout][f] ||= [] } @block_options = [] - BLOCKS.each {|k, v| @block_options << [l(v), k]} + BLOCKS.each {|k, v| @block_options << [l(v), k.dasherize]} end # Add a block to user's page # The block is added on top of the page # params[:block] : id of the block to add def add_block - block = params[:block] + block = params[:block].to_s.underscore render(:nothing => true) and return unless block && (BLOCKS.keys.include? block) @user = User.current # remove if already present in a group @@ -128,7 +128,7 @@ class MyController < ApplicationController # Remove a block to user's page # params[:block] : id of the block to remove def remove_block - block = params[:block] + block = params[:block].to_s.underscore # remove block in all groups %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block } render :nothing => true @@ -139,13 +139,15 @@ class MyController < ApplicationController # params[:list-(top|left|right)] : array of block ids of the group def order_blocks group = params[:group] - group_items = params["list-#{group}"] - if group_items and group_items.is_a? Array - # remove group blocks if they are presents in other groups - %w(top left right).each {|f| - session[:page_layout][f] = (session[:page_layout][f] || []) - group_items - } - session[:page_layout][group] = group_items + if group.is_a?(Array) + group_items = params["list-#{group}"].collect(&:underscore) + if group_items and group_items.is_a? Array + # remove group blocks if they are presents in other groups + %w(top left right).each {|f| + session[:page_layout][f] = (session[:page_layout][f] || []) - group_items + } + session[:page_layout][group] = group_items + end end render :nothing => true end -- cgit v1.2.3