@@ -1,161 +1,163 | |||
|
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 | 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 | }.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(v), k]} | |
|
111 | BLOCKS.each {|k, v| @block_options << [l(v), 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 | block = params[:block] | |
|
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 | block = params[:block] | |
|
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 | group_items = params["list-#{group}"] | |
|
143 | if group_items and group_items.is_a? Array | |
|
144 | # remove group blocks if they are presents in other groups | |
|
145 | %w(top left right).each {|f| | |
|
146 | session[:page_layout][f] = (session[:page_layout][f] || []) - group_items | |
|
147 | } | |
|
148 | session[:page_layout][group] = group_items | |
|
142 | if group.is_a?(Array) | |
|
143 | group_items = params["list-#{group}"].collect(&:underscore) | |
|
144 | if group_items and group_items.is_a? Array | |
|
145 | # remove group blocks if they are presents in other groups | |
|
146 | %w(top left right).each {|f| | |
|
147 | session[:page_layout][f] = (session[:page_layout][f] || []) - group_items | |
|
148 | } | |
|
149 | session[:page_layout][group] = group_items | |
|
150 | end | |
|
149 | 151 | end |
|
150 | 152 | render :nothing => true |
|
151 | 153 | end |
|
152 | 154 | |
|
153 | 155 | # Save user's page layout |
|
154 | 156 | def page_layout_save |
|
155 | 157 | @user = User.current |
|
156 | 158 | @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout] |
|
157 | 159 | @user.pref.save |
|
158 | 160 | session[:page_layout] = nil |
|
159 | 161 | redirect_to :action => 'page' |
|
160 | 162 | end |
|
161 | 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 | 3 | <div style="float:right;margin-right:16px;z-index:500;"> |
|
4 | 4 | <%= link_to_remote "", { |
|
5 | 5 | :url => { :action => "remove_block", :block => block_name }, |
|
6 | :complete => "removeBlock('block_#{block_name}')" }, | |
|
6 | :complete => "removeBlock('block_#{block_name.dasherize}')" }, | |
|
7 | 7 | :class => "close-icon" |
|
8 | 8 | %> |
|
9 | 9 | </div> |
|
10 | 10 | |
|
11 | 11 | <div class="handle"> |
|
12 | 12 | <%= render :partial => "my/blocks/#{block_name}", :locals => { :user => user } %> |
|
13 | 13 | </div> |
|
14 | 14 | </div> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now