##// END OF EJS Templates
fixed: crash on my/page_layout (trying to modify a frozen hash)...
Jean-Philippe Lang -
r255:7b164b5cd41e
parent child
Show More
@@ -1,135 +1,135
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class MyController < ApplicationController
19 19 layout 'base'
20 20 before_filter :require_login
21 21
22 22 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
23 23 'issuesreportedbyme' => :label_reported_issues,
24 24 'news' => :label_news_latest,
25 25 'calendar' => :label_calendar,
26 26 'documents' => :label_document_plural
27 27 }.freeze
28 28
29 29 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
30 30 'right' => ['issuesreportedbyme']
31 31 }.freeze
32 32
33 33 verify :xhr => true,
34 34 :session => :page_layout,
35 35 :only => [:add_block, :remove_block, :order_blocks]
36 36
37 37 def index
38 38 page
39 39 render :action => 'page'
40 40 end
41 41
42 42 # Show user's page
43 43 def page
44 44 @user = self.logged_in_user
45 45 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
46 46 end
47 47
48 48 # Edit user's account
49 49 def account
50 50 @user = self.logged_in_user
51 51 @pref = @user.pref
52 52 @user.attributes = params[:user]
53 53 @user.pref.attributes = params[:pref]
54 54 if request.post? and @user.save and @user.pref.save
55 55 set_localization
56 56 flash.now[:notice] = l(:notice_account_updated)
57 57 self.logged_in_user.reload
58 58 end
59 59 end
60 60
61 61 # Change user's password
62 62 def change_password
63 63 @user = self.logged_in_user
64 64 flash[:notice] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
65 65 if @user.check_password?(params[:password])
66 66 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
67 67 if @user.save
68 68 flash[:notice] = l(:notice_account_password_updated)
69 69 else
70 70 render :action => 'account'
71 71 return
72 72 end
73 73 else
74 74 flash[:notice] = l(:notice_account_wrong_password)
75 75 end
76 76 redirect_to :action => 'account'
77 77 end
78 78
79 79 # User's page layout configuration
80 80 def page_layout
81 81 @user = self.logged_in_user
82 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
82 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
83 83 session[:page_layout] = @blocks
84 84 %w(top left right).each {|f| session[:page_layout][f] ||= [] }
85 85 @block_options = []
86 86 BLOCKS.each {|k, v| @block_options << [l(v), k]}
87 87 end
88 88
89 89 # Add a block to user's page
90 90 # The block is added on top of the page
91 91 # params[:block] : id of the block to add
92 92 def add_block
93 93 @user = self.logged_in_user
94 94 block = params[:block]
95 95 # remove if already present in a group
96 96 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
97 97 # add it on top
98 98 session[:page_layout]['top'].unshift block
99 99 render :partial => "block", :locals => {:user => @user, :block_name => block}
100 100 end
101 101
102 102 # Remove a block to user's page
103 103 # params[:block] : id of the block to remove
104 104 def remove_block
105 105 block = params[:block]
106 106 # remove block in all groups
107 107 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
108 108 render :nothing => true
109 109 end
110 110
111 111 # Change blocks order on user's page
112 112 # params[:group] : group to order (top, left or right)
113 113 # params[:list-(top|left|right)] : array of block ids of the group
114 114 def order_blocks
115 115 group = params[:group]
116 116 group_items = params["list-#{group}"]
117 117 if group_items and group_items.is_a? Array
118 118 # remove group blocks if they are presents in other groups
119 119 %w(top left right).each {|f|
120 120 session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
121 121 }
122 122 session[:page_layout][group] = group_items
123 123 end
124 124 render :nothing => true
125 125 end
126 126
127 127 # Save user's page layout
128 128 def page_layout_save
129 129 @user = self.logged_in_user
130 130 @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
131 131 @user.pref.save
132 132 session[:page_layout] = nil
133 133 redirect_to :action => 'page'
134 134 end
135 135 end
General Comments 0
You need to be logged in to leave comments. Login now