##// END OF EJS Templates
removed underscores in block names (problem with scriptaculous sortables)...
Jean-Philippe Lang -
r239:08ff4dfb216c
parent child
Show More
@@ -1,131 +1,135
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 layout 'base'
19 layout 'base'
20 before_filter :require_login
20 before_filter :require_login
21
21
22 BLOCKS = { 'issues_assigned_to_me' => :label_assigned_to_me_issues,
22 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
23 'issues_reported_by_me' => :label_reported_issues,
23 'issuesreportedbyme' => :label_reported_issues,
24 'latest_news' => :label_news_latest,
24 'news' => :label_news_latest,
25 'calendar' => :label_calendar,
25 'calendar' => :label_calendar,
26 'documents' => :label_document_plural
26 'documents' => :label_document_plural
27 }.freeze
27 }.freeze
28
28
29 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
30 'right' => ['issuesreportedbyme']
31 }.freeze
32
29 verify :xhr => true,
33 verify :xhr => true,
30 :session => :page_layout,
34 :session => :page_layout,
31 :only => [:add_block, :remove_block, :order_blocks]
35 :only => [:add_block, :remove_block, :order_blocks]
32
36
33 def index
37 def index
34 page
38 page
35 render :action => 'page'
39 render :action => 'page'
36 end
40 end
37
41
38 # Show user's page
42 # Show user's page
39 def page
43 def page
40 @user = self.logged_in_user
44 @user = self.logged_in_user
41 @blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] }
45 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
42 end
46 end
43
47
44 # Edit user's account
48 # Edit user's account
45 def account
49 def account
46 @user = self.logged_in_user
50 @user = self.logged_in_user
47 @pref = @user.pref
51 @pref = @user.pref
48 @user.attributes = params[:user]
52 @user.attributes = params[:user]
49 @user.pref.attributes = params[:pref]
53 @user.pref.attributes = params[:pref]
50 if request.post? and @user.save
54 if request.post? and @user.save
51 set_localization
55 set_localization
52 flash.now[:notice] = l(:notice_account_updated)
56 flash.now[:notice] = l(:notice_account_updated)
53 self.logged_in_user.reload
57 self.logged_in_user.reload
54 end
58 end
55 end
59 end
56
60
57 # Change user's password
61 # Change user's password
58 def change_password
62 def change_password
59 @user = self.logged_in_user
63 @user = self.logged_in_user
60 flash[:notice] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
64 flash[:notice] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
61 if @user.check_password?(params[:password])
65 if @user.check_password?(params[:password])
62 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
66 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
63 if @user.save
67 if @user.save
64 flash[:notice] = l(:notice_account_password_updated)
68 flash[:notice] = l(:notice_account_password_updated)
65 else
69 else
66 render :action => 'account'
70 render :action => 'account'
67 return
71 return
68 end
72 end
69 else
73 else
70 flash[:notice] = l(:notice_account_wrong_password)
74 flash[:notice] = l(:notice_account_wrong_password)
71 end
75 end
72 redirect_to :action => 'account'
76 redirect_to :action => 'account'
73 end
77 end
74
78
75 # User's page layout configuration
79 # User's page layout configuration
76 def page_layout
80 def page_layout
77 @user = self.logged_in_user
81 @user = self.logged_in_user
78 @blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] }
82 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
79 session[:page_layout] = @blocks
83 session[:page_layout] = @blocks
80 %w(top left right).each {|f| session[:page_layout][f] ||= [] }
84 %w(top left right).each {|f| session[:page_layout][f] ||= [] }
81 @block_options = []
85 @block_options = []
82 BLOCKS.each {|k, v| @block_options << [l(v), k]}
86 BLOCKS.each {|k, v| @block_options << [l(v), k]}
83 end
87 end
84
88
85 # Add a block to user's page
89 # Add a block to user's page
86 # The block is added on top of the page
90 # The block is added on top of the page
87 # params[:block] : id of the block to add
91 # params[:block] : id of the block to add
88 def add_block
92 def add_block
89 @user = self.logged_in_user
93 @user = self.logged_in_user
90 block = params[:block]
94 block = params[:block]
91 # remove if already present in a group
95 # remove if already present in a group
92 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
96 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
93 # add it on top
97 # add it on top
94 session[:page_layout]['top'].unshift block
98 session[:page_layout]['top'].unshift block
95 render :partial => "block", :locals => {:user => @user, :block_name => block}
99 render :partial => "block", :locals => {:user => @user, :block_name => block}
96 end
100 end
97
101
98 # Remove a block to user's page
102 # Remove a block to user's page
99 # params[:block] : id of the block to remove
103 # params[:block] : id of the block to remove
100 def remove_block
104 def remove_block
101 block = params[:block]
105 block = params[:block]
102 # remove block in all groups
106 # remove block in all groups
103 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
107 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
104 render :nothing => true
108 render :nothing => true
105 end
109 end
106
110
107 # Change blocks order on user's page
111 # Change blocks order on user's page
108 # params[:group] : group to order (top, left or right)
112 # params[:group] : group to order (top, left or right)
109 # params[:list-(top|left|right)] : array of block ids of the group
113 # params[:list-(top|left|right)] : array of block ids of the group
110 def order_blocks
114 def order_blocks
111 group = params[:group]
115 group = params[:group]
112 group_items = params["list-#{group}"]
116 group_items = params["list-#{group}"]
113 if group_items and group_items.is_a? Array
117 if group_items and group_items.is_a? Array
114 # remove group blocks if they are presents in other groups
118 # remove group blocks if they are presents in other groups
115 %w(top left right).each {|f|
119 %w(top left right).each {|f|
116 session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
120 session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
117 }
121 }
118 session[:page_layout][group] = group_items
122 session[:page_layout][group] = group_items
119 end
123 end
120 render :nothing => true
124 render :nothing => true
121 end
125 end
122
126
123 # Save user's page layout
127 # Save user's page layout
124 def page_layout_save
128 def page_layout_save
125 @user = self.logged_in_user
129 @user = self.logged_in_user
126 @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
130 @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
127 @user.pref.save
131 @user.pref.save
128 session[:page_layout] = nil
132 session[:page_layout] = nil
129 redirect_to :action => 'page'
133 redirect_to :action => 'page'
130 end
134 end
131 end
135 end
1 NO CONTENT: file renamed from app/views/my/blocks/_issues_assigned_to_me.rhtml to app/views/my/blocks/_issuesassignedtome.rhtml
NO CONTENT: file renamed from app/views/my/blocks/_issues_assigned_to_me.rhtml to app/views/my/blocks/_issuesassignedtome.rhtml
1 NO CONTENT: file renamed from app/views/my/blocks/_issues_reported_by_me.rhtml to app/views/my/blocks/_issuesreportedbyme.rhtml
NO CONTENT: file renamed from app/views/my/blocks/_issues_reported_by_me.rhtml to app/views/my/blocks/_issuesreportedbyme.rhtml
1 NO CONTENT: file renamed from app/views/my/blocks/_latest_news.rhtml to app/views/my/blocks/_news.rhtml
NO CONTENT: file renamed from app/views/my/blocks/_latest_news.rhtml to app/views/my/blocks/_news.rhtml
General Comments 0
You need to be logged in to leave comments. Login now