diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-10-29 10:25:55 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-10-29 10:25:55 +0000 |
commit | 55be5e82b84946c173fcb147485251193157b71b (patch) | |
tree | ae79a006e5c812e7e037e79412399bd769df01d2 /app/controllers | |
parent | ac7e5f4db2ce0224d9cfc30f41d10881c20c6963 (diff) | |
download | redmine-55be5e82b84946c173fcb147485251193157b71b.tar.gz redmine-55be5e82b84946c173fcb147485251193157b71b.zip |
Adds #add_block and #remove_block methods.
git-svn-id: http://svn.redmine.org/redmine/trunk@15932 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/my_controller.rb | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 6e328c270..a01d4e0ea 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -140,52 +140,34 @@ class MyController < ApplicationController # The block is added on top of the page # params[:block] : id of the block to add def add_block - block = params[:block].to_s.underscore - if block.present? && Redmine::MyPage.blocks.key?(block) - @user = User.current - layout = @user.pref.my_page_layout - # remove if already present in a group - %w(top left right).each {|f| (layout[f] ||= []).delete block } - # add it on top - layout['top'].unshift block - @user.pref.my_page_layout = layout - @user.pref.save - end + @user = User.current + @user.pref.add_block params[:block] + @user.pref.save redirect_to my_page_layout_path end # Remove a block to user's page # params[:block] : id of the block to remove def remove_block - block = params[:block].to_s.underscore @user = User.current - # remove block in all groups - layout = @user.pref.my_page_layout - %w(top left right).each {|f| (layout[f] ||= []).delete block } - @user.pref.my_page_layout = layout + @user.pref.remove_block params[:block] @user.pref.save redirect_to my_page_layout_path end # Change blocks order on user's page # params[:group] : group to order (top, left or right) - # params[:list-(top|left|right)] : array of block ids of the group + # params[:blocks] : array of block ids of the group def order_blocks group = params[:group] @user = User.current if group.is_a?(String) group_items = (params["blocks"] || []).collect(&:underscore) group_items.each {|s| s.sub!(/^block_/, '')} - if group_items and group_items.is_a? Array - layout = @user.pref.my_page_layout - # remove group blocks if they are presents in other groups - %w(top left right).each {|f| - layout[f] = (layout[f] || []) - group_items - } - layout[group] = group_items - @user.pref.my_page_layout = layout - @user.pref.save - end + # remove group blocks if they are presents in other groups + group_items.each {|s| @user.pref.remove_block(s)} + @user.pref.my_page_layout[group] = group_items + @user.pref.save end head 200 end |