##// END OF EJS Templates
Set a default scope for 'My page' block names translations (#3057)....
Jean-Philippe Lang -
r2570:dea072f50619
parent child
Show More
@@ -1,163 +1,163
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2009 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 before_filter :require_login
20 20
21 21 helper :issues
22 22 helper :custom_fields
23 23
24 24 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
25 25 'issuesreportedbyme' => :label_reported_issues,
26 26 'issueswatched' => :label_watched_issues,
27 27 'news' => :label_news_latest,
28 28 'calendar' => :label_calendar,
29 29 'documents' => :label_document_plural,
30 30 'timelog' => :label_spent_time
31 31 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
32 32
33 33 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
34 34 'right' => ['issuesreportedbyme']
35 35 }.freeze
36 36
37 37 verify :xhr => true,
38 38 :session => :page_layout,
39 39 :only => [:add_block, :remove_block, :order_blocks]
40 40
41 41 def index
42 42 page
43 43 render :action => 'page'
44 44 end
45 45
46 46 # Show user's page
47 47 def page
48 48 @user = User.current
49 49 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
50 50 end
51 51
52 52 # Edit user's account
53 53 def account
54 54 @user = User.current
55 55 @pref = @user.pref
56 56 if request.post?
57 57 @user.attributes = params[:user]
58 58 @user.mail_notification = (params[:notification_option] == 'all')
59 59 @user.pref.attributes = params[:pref]
60 60 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
61 61 if @user.save
62 62 @user.pref.save
63 63 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
64 64 set_language_if_valid @user.language
65 65 flash[:notice] = l(:notice_account_updated)
66 66 redirect_to :action => 'account'
67 67 return
68 68 end
69 69 end
70 70 @notification_options = [[l(:label_user_mail_option_all), 'all'],
71 71 [l(:label_user_mail_option_none), 'none']]
72 72 # Only users that belong to more than 1 project can select projects for which they are notified
73 73 # Note that @user.membership.size would fail since AR ignores :include association option when doing a count
74 74 @notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
75 75 @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
76 76 end
77 77
78 78 # Manage user's password
79 79 def password
80 80 @user = User.current
81 81 flash[:error] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
82 82 if request.post?
83 83 if @user.check_password?(params[:password])
84 84 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
85 85 if @user.save
86 86 flash[:notice] = l(:notice_account_password_updated)
87 87 redirect_to :action => 'account'
88 88 end
89 89 else
90 90 flash[:error] = l(:notice_account_wrong_password)
91 91 end
92 92 end
93 93 end
94 94
95 95 # Create a new feeds key
96 96 def reset_rss_key
97 97 if request.post? && User.current.rss_token
98 98 User.current.rss_token.destroy
99 99 flash[:notice] = l(:notice_feeds_access_key_reseted)
100 100 end
101 101 redirect_to :action => 'account'
102 102 end
103 103
104 104 # User's page layout configuration
105 105 def page_layout
106 106 @user = User.current
107 107 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
108 108 session[:page_layout] = @blocks
109 109 %w(top left right).each {|f| session[:page_layout][f] ||= [] }
110 110 @block_options = []
111 BLOCKS.each {|k, v| @block_options << [l_or_humanize(v), k.dasherize]}
111 BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
112 112 end
113 113
114 114 # Add a block to user's page
115 115 # The block is added on top of the page
116 116 # params[:block] : id of the block to add
117 117 def add_block
118 118 block = params[:block].to_s.underscore
119 119 render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
120 120 @user = User.current
121 121 # remove if already present in a group
122 122 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
123 123 # add it on top
124 124 session[:page_layout]['top'].unshift block
125 125 render :partial => "block", :locals => {:user => @user, :block_name => block}
126 126 end
127 127
128 128 # Remove a block to user's page
129 129 # params[:block] : id of the block to remove
130 130 def remove_block
131 131 block = params[:block].to_s.underscore
132 132 # remove block in all groups
133 133 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
134 134 render :nothing => true
135 135 end
136 136
137 137 # Change blocks order on user's page
138 138 # params[:group] : group to order (top, left or right)
139 139 # params[:list-(top|left|right)] : array of block ids of the group
140 140 def order_blocks
141 141 group = params[:group]
142 142 if group.is_a?(String)
143 143 group_items = (params["list-#{group}"] || []).collect(&:underscore)
144 144 if group_items and group_items.is_a? Array
145 145 # remove group blocks if they are presents in other groups
146 146 %w(top left right).each {|f|
147 147 session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
148 148 }
149 149 session[:page_layout][group] = group_items
150 150 end
151 151 end
152 152 render :nothing => true
153 153 end
154 154
155 155 # Save user's page layout
156 156 def page_layout_save
157 157 @user = User.current
158 158 @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
159 159 @user.pref.save
160 160 session[:page_layout] = nil
161 161 redirect_to :action => 'page'
162 162 end
163 163 end
@@ -1,32 +1,32
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2009 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 module Redmine
19 19 module Views
20 20 module MyPage
21 21 module Block
22 22 def self.additional_blocks
23 23 @@additional_blocks ||= Dir.glob("#{RAILS_ROOT}/vendor/plugins/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file|
24 24 name = File.basename(file).split('.').first.gsub(/^_/, '')
25 h[name] = name
25 h[name] = name.to_sym
26 26 h
27 27 end
28 28 end
29 29 end
30 30 end
31 31 end
32 32 end
General Comments 0
You need to be logged in to leave comments. Login now