@@ -1,167 +1,166 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 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 | }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze |
|
31 | }.merge(Redmine::Views::MyPage::Block.additional_blocks).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, |
|
|||
39 | :only => [:add_block, :remove_block, :order_blocks] |
|
38 | :only => [:add_block, :remove_block, :order_blocks] | |
40 |
|
39 | |||
41 | def index |
|
40 | def index | |
42 | page |
|
41 | page | |
43 | render :action => 'page' |
|
42 | render :action => 'page' | |
44 | end |
|
43 | end | |
45 |
|
44 | |||
46 | # Show user's page |
|
45 | # Show user's page | |
47 | def page |
|
46 | def page | |
48 | @user = User.current |
|
47 | @user = User.current | |
49 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT |
|
48 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT | |
50 | end |
|
49 | end | |
51 |
|
50 | |||
52 | # Edit user's account |
|
51 | # Edit user's account | |
53 | def account |
|
52 | def account | |
54 | @user = User.current |
|
53 | @user = User.current | |
55 | @pref = @user.pref |
|
54 | @pref = @user.pref | |
56 | if request.post? |
|
55 | if request.post? | |
57 | @user.attributes = params[:user] |
|
56 | @user.attributes = params[:user] | |
58 | @user.mail_notification = (params[:notification_option] == 'all') |
|
57 | @user.mail_notification = (params[:notification_option] == 'all') | |
59 | @user.pref.attributes = params[:pref] |
|
58 | @user.pref.attributes = params[:pref] | |
60 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
59 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') | |
61 | if @user.save |
|
60 | if @user.save | |
62 | @user.pref.save |
|
61 | @user.pref.save | |
63 | @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) |
|
62 | @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) | |
64 | set_language_if_valid @user.language |
|
63 | set_language_if_valid @user.language | |
65 | flash[:notice] = l(:notice_account_updated) |
|
64 | flash[:notice] = l(:notice_account_updated) | |
66 | redirect_to :action => 'account' |
|
65 | redirect_to :action => 'account' | |
67 | return |
|
66 | return | |
68 | end |
|
67 | end | |
69 | end |
|
68 | end | |
70 | @notification_options = [[l(:label_user_mail_option_all), 'all'], |
|
69 | @notification_options = [[l(:label_user_mail_option_all), 'all'], | |
71 | [l(:label_user_mail_option_none), 'none']] |
|
70 | [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 |
|
71 | # 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 |
|
72 | # 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 |
|
73 | @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') |
|
74 | @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected') | |
76 | end |
|
75 | end | |
77 |
|
76 | |||
78 | # Manage user's password |
|
77 | # Manage user's password | |
79 | def password |
|
78 | def password | |
80 | @user = User.current |
|
79 | @user = User.current | |
81 | if @user.auth_source_id |
|
80 | if @user.auth_source_id | |
82 | flash[:error] = l(:notice_can_t_change_password) |
|
81 | flash[:error] = l(:notice_can_t_change_password) | |
83 | redirect_to :action => 'account' |
|
82 | redirect_to :action => 'account' | |
84 | return |
|
83 | return | |
85 | end |
|
84 | end | |
86 | if request.post? |
|
85 | if request.post? | |
87 | if @user.check_password?(params[:password]) |
|
86 | if @user.check_password?(params[:password]) | |
88 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] |
|
87 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] | |
89 | if @user.save |
|
88 | if @user.save | |
90 | flash[:notice] = l(:notice_account_password_updated) |
|
89 | flash[:notice] = l(:notice_account_password_updated) | |
91 | redirect_to :action => 'account' |
|
90 | redirect_to :action => 'account' | |
92 | end |
|
91 | end | |
93 | else |
|
92 | else | |
94 | flash[:error] = l(:notice_account_wrong_password) |
|
93 | flash[:error] = l(:notice_account_wrong_password) | |
95 | end |
|
94 | end | |
96 | end |
|
95 | end | |
97 | end |
|
96 | end | |
98 |
|
97 | |||
99 | # Create a new feeds key |
|
98 | # Create a new feeds key | |
100 | def reset_rss_key |
|
99 | def reset_rss_key | |
101 | if request.post? && User.current.rss_token |
|
100 | if request.post? && User.current.rss_token | |
102 | User.current.rss_token.destroy |
|
101 | User.current.rss_token.destroy | |
103 | flash[:notice] = l(:notice_feeds_access_key_reseted) |
|
102 | flash[:notice] = l(:notice_feeds_access_key_reseted) | |
104 | end |
|
103 | end | |
105 | redirect_to :action => 'account' |
|
104 | redirect_to :action => 'account' | |
106 | end |
|
105 | end | |
107 |
|
106 | |||
108 | # User's page layout configuration |
|
107 | # User's page layout configuration | |
109 | def page_layout |
|
108 | def page_layout | |
110 | @user = User.current |
|
109 | @user = User.current | |
111 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
|
110 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup | |
112 | session[:page_layout] = @blocks |
|
|||
113 | %w(top left right).each {|f| session[:page_layout][f] ||= [] } |
|
|||
114 | @block_options = [] |
|
111 | @block_options = [] | |
115 | BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]} |
|
112 | BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]} | |
116 | end |
|
113 | end | |
117 |
|
114 | |||
118 | # Add a block to user's page |
|
115 | # Add a block to user's page | |
119 | # The block is added on top of the page |
|
116 | # The block is added on top of the page | |
120 | # params[:block] : id of the block to add |
|
117 | # params[:block] : id of the block to add | |
121 | def add_block |
|
118 | def add_block | |
122 | block = params[:block].to_s.underscore |
|
119 | block = params[:block].to_s.underscore | |
123 | (render :nothing => true; return) unless block && (BLOCKS.keys.include? block) |
|
120 | (render :nothing => true; return) unless block && (BLOCKS.keys.include? block) | |
124 | @user = User.current |
|
121 | @user = User.current | |
|
122 | layout = @user.pref[:my_page_layout] || {} | |||
125 | # remove if already present in a group |
|
123 | # remove if already present in a group | |
126 |
%w(top left right).each {|f| ( |
|
124 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |
127 | # add it on top |
|
125 | # add it on top | |
128 |
|
|
126 | layout['top'].unshift block | |
|
127 | @user.pref[:my_page_layout] = layout | |||
|
128 | @user.pref.save | |||
129 | render :partial => "block", :locals => {:user => @user, :block_name => block} |
|
129 | render :partial => "block", :locals => {:user => @user, :block_name => block} | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | # Remove a block to user's page |
|
132 | # Remove a block to user's page | |
133 | # params[:block] : id of the block to remove |
|
133 | # params[:block] : id of the block to remove | |
134 | def remove_block |
|
134 | def remove_block | |
135 | block = params[:block].to_s.underscore |
|
135 | block = params[:block].to_s.underscore | |
|
136 | @user = User.current | |||
136 | # remove block in all groups |
|
137 | # remove block in all groups | |
137 | %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block } |
|
138 | layout = @user.pref[:my_page_layout] || {} | |
|
139 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |||
|
140 | @user.pref[:my_page_layout] = layout | |||
|
141 | @user.pref.save | |||
138 | render :nothing => true |
|
142 | render :nothing => true | |
139 | end |
|
143 | end | |
140 |
|
144 | |||
141 | # Change blocks order on user's page |
|
145 | # Change blocks order on user's page | |
142 | # params[:group] : group to order (top, left or right) |
|
146 | # params[:group] : group to order (top, left or right) | |
143 | # params[:list-(top|left|right)] : array of block ids of the group |
|
147 | # params[:list-(top|left|right)] : array of block ids of the group | |
144 | def order_blocks |
|
148 | def order_blocks | |
145 | group = params[:group] |
|
149 | group = params[:group] | |
|
150 | @user = User.current | |||
146 | if group.is_a?(String) |
|
151 | if group.is_a?(String) | |
147 | group_items = (params["list-#{group}"] || []).collect(&:underscore) |
|
152 | group_items = (params["list-#{group}"] || []).collect(&:underscore) | |
148 | if group_items and group_items.is_a? Array |
|
153 | if group_items and group_items.is_a? Array | |
|
154 | layout = @user.pref[:my_page_layout] || {} | |||
149 | # remove group blocks if they are presents in other groups |
|
155 | # remove group blocks if they are presents in other groups | |
150 | %w(top left right).each {|f| |
|
156 | %w(top left right).each {|f| | |
151 |
|
|
157 | layout[f] = (layout[f] || []) - group_items | |
152 | } |
|
158 | } | |
153 |
|
|
159 | layout[group] = group_items | |
|
160 | @user.pref[:my_page_layout] = layout | |||
|
161 | @user.pref.save | |||
154 | end |
|
162 | end | |
155 | end |
|
163 | end | |
156 | render :nothing => true |
|
164 | render :nothing => true | |
157 | end |
|
165 | end | |
158 |
|
||||
159 | # Save user's page layout |
|
|||
160 | def page_layout_save |
|
|||
161 | @user = User.current |
|
|||
162 | @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout] |
|
|||
163 | @user.pref.save |
|
|||
164 | session[:page_layout] = nil |
|
|||
165 | redirect_to :action => 'page' |
|
|||
166 | end |
|
|||
167 | end |
|
166 | end |
@@ -1,107 +1,106 | |||||
1 | <script language="JavaScript"> |
|
1 | <script language="JavaScript"> | |
2 | //<![CDATA[ |
|
2 | //<![CDATA[ | |
3 | function recreateSortables() { |
|
3 | function recreateSortables() { | |
4 | Sortable.destroy('list-top'); |
|
4 | Sortable.destroy('list-top'); | |
5 | Sortable.destroy('list-left'); |
|
5 | Sortable.destroy('list-left'); | |
6 | Sortable.destroy('list-right'); |
|
6 | Sortable.destroy('list-right'); | |
7 |
|
7 | |||
8 | Sortable.create("list-top", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('/my/order_blocks?group=top', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-top")})}, only:'mypage-box', tag:'div'}) |
|
8 | Sortable.create("list-top", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('/my/order_blocks?group=top', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-top")})}, only:'mypage-box', tag:'div'}) | |
9 | Sortable.create("list-left", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('/my/order_blocks?group=left', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-left")})}, only:'mypage-box', tag:'div'}) |
|
9 | Sortable.create("list-left", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('/my/order_blocks?group=left', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-left")})}, only:'mypage-box', tag:'div'}) | |
10 | Sortable.create("list-right", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('/my/order_blocks?group=right', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-right")})}, only:'mypage-box', tag:'div'}) |
|
10 | Sortable.create("list-right", {constraint:false, containment:['list-top','list-left','list-right'], dropOnEmpty:true, handle:'handle', onUpdate:function(){new Ajax.Request('/my/order_blocks?group=right', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("list-right")})}, only:'mypage-box', tag:'div'}) | |
11 | } |
|
11 | } | |
12 |
|
12 | |||
13 | function updateSelect() { |
|
13 | function updateSelect() { | |
14 | s = $('block-select') |
|
14 | s = $('block-select') | |
15 | for (var i = 0; i < s.options.length; i++) { |
|
15 | for (var i = 0; i < s.options.length; i++) { | |
16 | if ($('block_' + s.options[i].value)) { |
|
16 | if ($('block_' + s.options[i].value)) { | |
17 | s.options[i].disabled = true; |
|
17 | s.options[i].disabled = true; | |
18 | } else { |
|
18 | } else { | |
19 | s.options[i].disabled = false; |
|
19 | s.options[i].disabled = false; | |
20 | } |
|
20 | } | |
21 | } |
|
21 | } | |
22 | s.options[0].selected = true; |
|
22 | s.options[0].selected = true; | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | function afterAddBlock() { |
|
25 | function afterAddBlock() { | |
26 | recreateSortables(); |
|
26 | recreateSortables(); | |
27 | updateSelect(); |
|
27 | updateSelect(); | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | function removeBlock(block) { |
|
30 | function removeBlock(block) { | |
31 | Effect.DropOut(block); |
|
31 | Effect.DropOut(block); | |
32 | updateSelect(); |
|
32 | updateSelect(); | |
33 | } |
|
33 | } | |
34 | //]]> |
|
34 | //]]> | |
35 | </script> |
|
35 | </script> | |
36 |
|
36 | |||
37 | <div class="contextual"> |
|
37 | <div class="contextual"> | |
38 | <% form_tag({:action => "add_block"}, :id => "block-form") do %> |
|
38 | <% form_tag({:action => "add_block"}, :id => "block-form") do %> | |
39 | <%= select_tag 'block', "<option></option>" + options_for_select(@block_options), :id => "block-select" %> |
|
39 | <%= select_tag 'block', "<option></option>" + options_for_select(@block_options), :id => "block-select" %> | |
40 | <%= link_to_remote l(:button_add), |
|
40 | <%= link_to_remote l(:button_add), | |
41 | {:url => { :action => "add_block" }, |
|
41 | {:url => { :action => "add_block" }, | |
42 | :with => "Form.serialize('block-form')", |
|
42 | :with => "Form.serialize('block-form')", | |
43 | :update => "list-top", |
|
43 | :update => "list-top", | |
44 | :position => :top, |
|
44 | :position => :top, | |
45 | :complete => "afterAddBlock();" |
|
45 | :complete => "afterAddBlock();" | |
46 | }, :class => 'icon icon-add' |
|
46 | }, :class => 'icon icon-add' | |
47 | %> |
|
47 | %> | |
48 | <% end %> |
|
48 | <% end %> | |
49 |
<%= link_to l(:button_ |
|
49 | <%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %> | |
50 | <%= link_to l(:button_cancel), {:action => 'page'}, :class => 'icon icon-cancel' %> |
|
|||
51 | </div> |
|
50 | </div> | |
52 |
|
51 | |||
53 | <h2><%=l(:label_my_page)%></h2> |
|
52 | <h2><%=l(:label_my_page)%></h2> | |
54 |
|
53 | |||
55 | <div id="list-top" class="block-receiver"> |
|
54 | <div id="list-top" class="block-receiver"> | |
56 | <% @blocks['top'].each do |b| |
|
55 | <% @blocks['top'].each do |b| | |
57 | next unless MyController::BLOCKS.keys.include? b %> |
|
56 | next unless MyController::BLOCKS.keys.include? b %> | |
58 | <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> |
|
57 | <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> | |
59 | <% end if @blocks['top'] %> |
|
58 | <% end if @blocks['top'] %> | |
60 | </div> |
|
59 | </div> | |
61 |
|
60 | |||
62 | <div id="list-left" class="splitcontentleft block-receiver"> |
|
61 | <div id="list-left" class="splitcontentleft block-receiver"> | |
63 | <% @blocks['left'].each do |b| |
|
62 | <% @blocks['left'].each do |b| | |
64 | next unless MyController::BLOCKS.keys.include? b %> |
|
63 | next unless MyController::BLOCKS.keys.include? b %> | |
65 | <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> |
|
64 | <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> | |
66 | <% end if @blocks['left'] %> |
|
65 | <% end if @blocks['left'] %> | |
67 | </div> |
|
66 | </div> | |
68 |
|
67 | |||
69 | <div id="list-right" class="splitcontentright block-receiver"> |
|
68 | <div id="list-right" class="splitcontentright block-receiver"> | |
70 | <% @blocks['right'].each do |b| |
|
69 | <% @blocks['right'].each do |b| | |
71 | next unless MyController::BLOCKS.keys.include? b %> |
|
70 | next unless MyController::BLOCKS.keys.include? b %> | |
72 | <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> |
|
71 | <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> | |
73 | <% end if @blocks['right'] %> |
|
72 | <% end if @blocks['right'] %> | |
74 | </div> |
|
73 | </div> | |
75 |
|
74 | |||
76 | <%= sortable_element 'list-top', |
|
75 | <%= sortable_element 'list-top', | |
77 | :tag => 'div', |
|
76 | :tag => 'div', | |
78 | :only => 'mypage-box', |
|
77 | :only => 'mypage-box', | |
79 | :handle => "handle", |
|
78 | :handle => "handle", | |
80 | :dropOnEmpty => true, |
|
79 | :dropOnEmpty => true, | |
81 | :containment => ['list-top', 'list-left', 'list-right'], |
|
80 | :containment => ['list-top', 'list-left', 'list-right'], | |
82 | :constraint => false, |
|
81 | :constraint => false, | |
83 | :url => { :action => "order_blocks", :group => "top" } |
|
82 | :url => { :action => "order_blocks", :group => "top" } | |
84 | %> |
|
83 | %> | |
85 |
|
84 | |||
86 |
|
85 | |||
87 | <%= sortable_element 'list-left', |
|
86 | <%= sortable_element 'list-left', | |
88 | :tag => 'div', |
|
87 | :tag => 'div', | |
89 | :only => 'mypage-box', |
|
88 | :only => 'mypage-box', | |
90 | :handle => "handle", |
|
89 | :handle => "handle", | |
91 | :dropOnEmpty => true, |
|
90 | :dropOnEmpty => true, | |
92 | :containment => ['list-top', 'list-left', 'list-right'], |
|
91 | :containment => ['list-top', 'list-left', 'list-right'], | |
93 | :constraint => false, |
|
92 | :constraint => false, | |
94 | :url => { :action => "order_blocks", :group => "left" } |
|
93 | :url => { :action => "order_blocks", :group => "left" } | |
95 | %> |
|
94 | %> | |
96 |
|
95 | |||
97 | <%= sortable_element 'list-right', |
|
96 | <%= sortable_element 'list-right', | |
98 | :tag => 'div', |
|
97 | :tag => 'div', | |
99 | :only => 'mypage-box', |
|
98 | :only => 'mypage-box', | |
100 | :handle => "handle", |
|
99 | :handle => "handle", | |
101 | :dropOnEmpty => true, |
|
100 | :dropOnEmpty => true, | |
102 | :containment => ['list-top', 'list-left', 'list-right'], |
|
101 | :containment => ['list-top', 'list-left', 'list-right'], | |
103 | :constraint => false, |
|
102 | :constraint => false, | |
104 | :url => { :action => "order_blocks", :group => "right" } |
|
103 | :url => { :action => "order_blocks", :group => "right" } | |
105 | %> |
|
104 | %> | |
106 |
|
105 | |||
107 | <%= javascript_tag "updateSelect()" %> |
|
106 | <%= javascript_tag "updateSelect()" %> |
@@ -1,24 +1,31 | |||||
1 | --- |
|
1 | --- | |
2 | user_preferences_001: |
|
2 | user_preferences_001: | |
3 | others: | |
|
3 | others: | | |
4 | --- |
|
4 | --- | |
5 | :my_page_layout: |
|
5 | :my_page_layout: | |
6 | left: |
|
6 | left: | |
7 |
- latest |
|
7 | - latestnews | |
8 | - documents |
|
8 | - documents | |
9 | right: |
|
9 | right: | |
10 |
- issues |
|
10 | - issuesassignedtome | |
11 | - issues_reported_by_me |
|
|||
12 | top: |
|
11 | top: | |
13 | - calendar |
|
12 | - calendar | |
14 |
|
13 | |||
15 | id: 1 |
|
14 | id: 1 | |
16 | user_id: 1 |
|
15 | user_id: 1 | |
17 | hide_mail: true |
|
16 | hide_mail: true | |
18 | user_preferences_002: |
|
17 | user_preferences_002: | |
19 |
others: | |
|
18 | others: | | |
20 |
--- |
|
19 | --- | |
|
20 | :my_page_layout: | |||
|
21 | left: | |||
|
22 | - latestnews | |||
|
23 | - documents | |||
|
24 | right: | |||
|
25 | - issuesassignedtome | |||
|
26 | top: | |||
|
27 | - calendar | |||
21 |
|
|
28 | ||
22 | id: 2 |
|
29 | id: 2 | |
23 | user_id: 3 |
|
30 | user_id: 3 | |
24 | hide_mail: false No newline at end of file |
|
31 | hide_mail: false |
@@ -1,108 +1,132 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'my_controller' |
|
19 | require 'my_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class MyController; def rescue_action(e) raise e end; end |
|
22 | class MyController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class MyControllerTest < ActionController::TestCase |
|
24 | class MyControllerTest < ActionController::TestCase | |
25 | fixtures :users, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields |
|
25 | fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = MyController.new |
|
28 | @controller = MyController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @request.session[:user_id] = 2 |
|
30 | @request.session[:user_id] = 2 | |
31 | @response = ActionController::TestResponse.new |
|
31 | @response = ActionController::TestResponse.new | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_index |
|
34 | def test_index | |
35 | get :index |
|
35 | get :index | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'page' |
|
37 | assert_template 'page' | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def test_page |
|
40 | def test_page | |
41 | get :page |
|
41 | get :page | |
42 | assert_response :success |
|
42 | assert_response :success | |
43 | assert_template 'page' |
|
43 | assert_template 'page' | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_my_account_should_show_editable_custom_fields |
|
46 | def test_my_account_should_show_editable_custom_fields | |
47 | get :account |
|
47 | get :account | |
48 | assert_response :success |
|
48 | assert_response :success | |
49 | assert_template 'account' |
|
49 | assert_template 'account' | |
50 | assert_equal User.find(2), assigns(:user) |
|
50 | assert_equal User.find(2), assigns(:user) | |
51 |
|
51 | |||
52 | assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} |
|
52 | assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_my_account_should_not_show_non_editable_custom_fields |
|
55 | def test_my_account_should_not_show_non_editable_custom_fields | |
56 | UserCustomField.find(4).update_attribute :editable, false |
|
56 | UserCustomField.find(4).update_attribute :editable, false | |
57 |
|
57 | |||
58 | get :account |
|
58 | get :account | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'account' |
|
60 | assert_template 'account' | |
61 | assert_equal User.find(2), assigns(:user) |
|
61 | assert_equal User.find(2), assigns(:user) | |
62 |
|
62 | |||
63 | assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} |
|
63 | assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_update_account |
|
66 | def test_update_account | |
67 | post :account, :user => {:firstname => "Joe", |
|
67 | post :account, :user => {:firstname => "Joe", | |
68 | :login => "root", |
|
68 | :login => "root", | |
69 | :admin => 1, |
|
69 | :admin => 1, | |
70 | :custom_field_values => {"4" => "0100562500"}} |
|
70 | :custom_field_values => {"4" => "0100562500"}} | |
71 | assert_redirected_to 'my/account' |
|
71 | assert_redirected_to 'my/account' | |
72 | user = User.find(2) |
|
72 | user = User.find(2) | |
73 | assert_equal user, assigns(:user) |
|
73 | assert_equal user, assigns(:user) | |
74 | assert_equal "Joe", user.firstname |
|
74 | assert_equal "Joe", user.firstname | |
75 | assert_equal "jsmith", user.login |
|
75 | assert_equal "jsmith", user.login | |
76 | assert_equal "0100562500", user.custom_value_for(4).value |
|
76 | assert_equal "0100562500", user.custom_value_for(4).value | |
77 | assert !user.admin? |
|
77 | assert !user.admin? | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_change_password |
|
80 | def test_change_password | |
81 | get :password |
|
81 | get :password | |
82 | assert_response :success |
|
82 | assert_response :success | |
83 | assert_template 'password' |
|
83 | assert_template 'password' | |
84 |
|
84 | |||
85 | # non matching password confirmation |
|
85 | # non matching password confirmation | |
86 | post :password, :password => 'jsmith', |
|
86 | post :password, :password => 'jsmith', | |
87 | :new_password => 'hello', |
|
87 | :new_password => 'hello', | |
88 | :new_password_confirmation => 'hello2' |
|
88 | :new_password_confirmation => 'hello2' | |
89 | assert_response :success |
|
89 | assert_response :success | |
90 | assert_template 'password' |
|
90 | assert_template 'password' | |
91 | assert_tag :tag => "div", :attributes => { :class => "errorExplanation" } |
|
91 | assert_tag :tag => "div", :attributes => { :class => "errorExplanation" } | |
92 |
|
92 | |||
93 | # wrong password |
|
93 | # wrong password | |
94 | post :password, :password => 'wrongpassword', |
|
94 | post :password, :password => 'wrongpassword', | |
95 | :new_password => 'hello', |
|
95 | :new_password => 'hello', | |
96 | :new_password_confirmation => 'hello' |
|
96 | :new_password_confirmation => 'hello' | |
97 | assert_response :success |
|
97 | assert_response :success | |
98 | assert_template 'password' |
|
98 | assert_template 'password' | |
99 | assert_equal 'Wrong password', flash[:error] |
|
99 | assert_equal 'Wrong password', flash[:error] | |
100 |
|
100 | |||
101 | # good password |
|
101 | # good password | |
102 | post :password, :password => 'jsmith', |
|
102 | post :password, :password => 'jsmith', | |
103 | :new_password => 'hello', |
|
103 | :new_password => 'hello', | |
104 | :new_password_confirmation => 'hello' |
|
104 | :new_password_confirmation => 'hello' | |
105 | assert_redirected_to 'my/account' |
|
105 | assert_redirected_to 'my/account' | |
106 | assert User.try_to_login('jsmith', 'hello') |
|
106 | assert User.try_to_login('jsmith', 'hello') | |
107 | end |
|
107 | end | |
|
108 | ||||
|
109 | def test_page_layout | |||
|
110 | get :page_layout | |||
|
111 | assert_response :success | |||
|
112 | assert_template 'page_layout' | |||
|
113 | end | |||
|
114 | ||||
|
115 | def test_add_block | |||
|
116 | xhr :post, :add_block, :block => 'issuesreportedbyme' | |||
|
117 | assert_response :success | |||
|
118 | assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') | |||
|
119 | end | |||
|
120 | ||||
|
121 | def test_remove_block | |||
|
122 | xhr :post, :remove_block, :block => 'issuesassignedtome' | |||
|
123 | assert_response :success | |||
|
124 | assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') | |||
|
125 | end | |||
|
126 | ||||
|
127 | def test_order_blocks | |||
|
128 | xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews'] | |||
|
129 | assert_response :success | |||
|
130 | assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] | |||
|
131 | end | |||
108 | end |
|
132 | end |
General Comments 0
You need to be logged in to leave comments.
Login now