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