Mercurial > hg > soundsoftware-site
comparison app/controllers/my_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 097d38a73624 |
children | 51364c0cd58f |
comparison
equal
deleted
inserted
replaced
1209:1b1138f6f55e | 1338:25603efa57b5 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
20 | 20 |
21 helper :issues | 21 helper :issues |
22 helper :users | 22 helper :users |
23 helper :custom_fields | 23 helper :custom_fields |
24 helper :projects | 24 helper :projects |
25 helper :activities | |
25 | 26 |
26 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, | 27 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, |
27 'issuesreportedbyme' => :label_reported_issues, | 28 'issuesreportedbyme' => :label_reported_issues, |
28 'issueswatched' => :label_watched_issues, | 29 'issueswatched' => :label_watched_issues, |
29 'activitymyprojects' => :label_activity_my_recent, | 30 'activitymyprojects' => :label_activity_my_recent, |
30 'news' => :label_news_latest, | 31 'news' => :label_news_latest, |
31 'tipoftheday' => :label_tipoftheday, | 32 'tipoftheday' => :label_tipoftheday, |
32 'calendar' => :label_calendar, | 33 'calendar' => :label_calendar, |
33 'documents' => :label_document_plural, | 34 'documents' => :label_document_plural, |
34 'timelog' => :label_spent_time, | 35 'timelog' => :label_spent_time, |
35 'myprojects' => :label_my_projects | 36 'myprojects' => :label_my_projects, |
37 'colleagues' => :label_my_colleagues | |
36 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze | 38 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze |
37 | 39 |
38 DEFAULT_LAYOUT = { 'left' => ['myprojects', 'activitymyprojects'], | 40 DEFAULT_LAYOUT = { 'left' => ['myprojects', 'activitymyprojects'], |
39 'right' => ['tipoftheday', 'issueswatched'] | 41 'right' => ['colleagues', 'tipoftheday', 'issueswatched'] |
40 }.freeze | 42 }.freeze |
41 | |
42 verify :xhr => true, | |
43 :only => [:add_block, :remove_block, :order_blocks] | |
44 | 43 |
45 def index | 44 def index |
46 page | 45 page |
47 render :action => 'page' | 46 render :action => 'page' |
48 end | 47 end |
99 return | 98 return |
100 end | 99 end |
101 end | 100 end |
102 end | 101 end |
103 | 102 |
103 # Destroys user's account | |
104 def destroy | |
105 @user = User.current | |
106 unless @user.own_account_deletable? | |
107 redirect_to :action => 'account' | |
108 return | |
109 end | |
110 | |
111 if request.post? && params[:confirm] | |
112 @user.destroy | |
113 if @user.destroyed? | |
114 logout_user | |
115 flash[:notice] = l(:notice_account_deleted) | |
116 end | |
117 redirect_to home_path | |
118 end | |
119 end | |
120 | |
104 # Manage user's password | 121 # Manage user's password |
105 def password | 122 def password |
106 @user = User.current | 123 @user = User.current |
107 unless @user.change_password_allowed? | 124 unless @user.change_password_allowed? |
108 flash[:error] = l(:notice_can_t_change_password) | 125 flash[:error] = l(:notice_can_t_change_password) |
151 # User's page layout configuration | 168 # User's page layout configuration |
152 def page_layout | 169 def page_layout |
153 @user = User.current | 170 @user = User.current |
154 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup | 171 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
155 @block_options = [] | 172 @block_options = [] |
156 BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]} | 173 BLOCKS.each do |k, v| |
174 unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)} | |
175 @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] | |
176 end | |
177 end | |
157 end | 178 end |
158 | 179 |
159 # Add a block to user's page | 180 # Add a block to user's page |
160 # The block is added on top of the page | 181 # The block is added on top of the page |
161 # params[:block] : id of the block to add | 182 # params[:block] : id of the block to add |
162 def add_block | 183 def add_block |
163 block = params[:block].to_s.underscore | 184 block = params[:block].to_s.underscore |
164 (render :nothing => true; return) unless block && (BLOCKS.keys.include? block) | 185 if block.present? && BLOCKS.key?(block) |
165 @user = User.current | 186 @user = User.current |
166 layout = @user.pref[:my_page_layout] || {} | 187 layout = @user.pref[:my_page_layout] || {} |
167 # remove if already present in a group | 188 # remove if already present in a group |
168 %w(top left right).each {|f| (layout[f] ||= []).delete block } | 189 %w(top left right).each {|f| (layout[f] ||= []).delete block } |
169 # add it on top | 190 # add it on top |
170 layout['top'].unshift block | 191 layout['top'].unshift block |
171 @user.pref[:my_page_layout] = layout | 192 @user.pref[:my_page_layout] = layout |
172 @user.pref.save | 193 @user.pref.save |
173 render :partial => "block", :locals => {:user => @user, :block_name => block} | 194 end |
195 redirect_to :action => 'page_layout' | |
174 end | 196 end |
175 | 197 |
176 # Remove a block to user's page | 198 # Remove a block to user's page |
177 # params[:block] : id of the block to remove | 199 # params[:block] : id of the block to remove |
178 def remove_block | 200 def remove_block |
181 # remove block in all groups | 203 # remove block in all groups |
182 layout = @user.pref[:my_page_layout] || {} | 204 layout = @user.pref[:my_page_layout] || {} |
183 %w(top left right).each {|f| (layout[f] ||= []).delete block } | 205 %w(top left right).each {|f| (layout[f] ||= []).delete block } |
184 @user.pref[:my_page_layout] = layout | 206 @user.pref[:my_page_layout] = layout |
185 @user.pref.save | 207 @user.pref.save |
186 render :nothing => true | 208 redirect_to :action => 'page_layout' |
187 end | 209 end |
188 | 210 |
189 # Change blocks order on user's page | 211 # Change blocks order on user's page |
190 # params[:group] : group to order (top, left or right) | 212 # params[:group] : group to order (top, left or right) |
191 # params[:list-(top|left|right)] : array of block ids of the group | 213 # params[:list-(top|left|right)] : array of block ids of the group |
192 def order_blocks | 214 def order_blocks |
193 group = params[:group] | 215 group = params[:group] |
194 @user = User.current | 216 @user = User.current |
195 if group.is_a?(String) | 217 if group.is_a?(String) |
196 group_items = (params["list-#{group}"] || []).collect(&:underscore) | 218 group_items = (params["blocks"] || []).collect(&:underscore) |
219 group_items.each {|s| s.sub!(/^block_/, '')} | |
197 if group_items and group_items.is_a? Array | 220 if group_items and group_items.is_a? Array |
198 layout = @user.pref[:my_page_layout] || {} | 221 layout = @user.pref[:my_page_layout] || {} |
199 # remove group blocks if they are presents in other groups | 222 # remove group blocks if they are presents in other groups |
200 %w(top left right).each {|f| | 223 %w(top left right).each {|f| |
201 layout[f] = (layout[f] || []) - group_items | 224 layout[f] = (layout[f] || []) - group_items |