Commit 5b96d1b0 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Allow underscore in block partial name (#2840).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2528 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 4c28291a
...@@ -108,14 +108,14 @@ class MyController < ApplicationController ...@@ -108,14 +108,14 @@ class MyController < ApplicationController
session[:page_layout] = @blocks session[:page_layout] = @blocks
%w(top left right).each {|f| session[:page_layout][f] ||= [] } %w(top left right).each {|f| session[:page_layout][f] ||= [] }
@block_options = [] @block_options = []
BLOCKS.each {|k, v| @block_options << [l(v), k]} BLOCKS.each {|k, v| @block_options << [l(v), k.dasherize]}
end end
# Add a block to user's page # Add a block to user's page
# The block is added on top of the page # The block is added on top of the page
# params[:block] : id of the block to add # params[:block] : id of the block to add
def add_block def add_block
block = params[:block] block = params[:block].to_s.underscore
render(:nothing => true) and return unless block && (BLOCKS.keys.include? block) render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
@user = User.current @user = User.current
# remove if already present in a group # remove if already present in a group
...@@ -128,7 +128,7 @@ class MyController < ApplicationController ...@@ -128,7 +128,7 @@ class MyController < ApplicationController
# Remove a block to user's page # Remove a block to user's page
# params[:block] : id of the block to remove # params[:block] : id of the block to remove
def remove_block def remove_block
block = params[:block] block = params[:block].to_s.underscore
# remove block in all groups # remove block in all groups
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block } %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
render :nothing => true render :nothing => true
...@@ -139,13 +139,15 @@ class MyController < ApplicationController ...@@ -139,13 +139,15 @@ class MyController < ApplicationController
# params[:list-(top|left|right)] : array of block ids of the group # params[:list-(top|left|right)] : array of block ids of the group
def order_blocks def order_blocks
group = params[:group] group = params[:group]
group_items = params["list-#{group}"] if group.is_a?(Array)
if group_items and group_items.is_a? Array group_items = params["list-#{group}"].collect(&:underscore)
# remove group blocks if they are presents in other groups if group_items and group_items.is_a? Array
%w(top left right).each {|f| # remove group blocks if they are presents in other groups
session[:page_layout][f] = (session[:page_layout][f] || []) - group_items %w(top left right).each {|f|
} session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
session[:page_layout][group] = group_items }
session[:page_layout][group] = group_items
end
end end
render :nothing => true render :nothing => true
end end
......
<div id="block_<%= block_name %>" class="mypage-box"> <div id="block_<%= block_name.dasherize %>" class="mypage-box">
<div style="float:right;margin-right:16px;z-index:500;"> <div style="float:right;margin-right:16px;z-index:500;">
<%= link_to_remote "", { <%= link_to_remote "", {
:url => { :action => "remove_block", :block => block_name }, :url => { :action => "remove_block", :block => block_name },
:complete => "removeBlock('block_#{block_name}')" }, :complete => "removeBlock('block_#{block_name.dasherize}')" },
:class => "close-icon" :class => "close-icon"
%> %>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment