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