##// END OF EJS Templates
Split user edit screen into tabs....
Jean-Philippe Lang -
r1389:63951812a1ed
parent child
Show More
@@ -0,0 +1,4
1 <% labelled_tabular_form_for :user, @user, :url => { :action => "edit" } do |f| %>
2 <%= render :partial => 'form', :locals => { :f => f } %>
3 <%= submit_tag l(:button_save) %>
4 <% end %>
@@ -1,113 +1,110
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 UsersController < ApplicationController
19 19 layout 'base'
20 20 before_filter :require_admin
21 21
22 22 helper :sort
23 23 include SortHelper
24 24 helper :custom_fields
25 25 include CustomFieldsHelper
26 26
27 27 def index
28 28 list
29 29 render :action => 'list' unless request.xhr?
30 30 end
31 31
32 32 def list
33 33 sort_init 'login', 'asc'
34 34 sort_update
35 35
36 36 @status = params[:status] ? params[:status].to_i : 1
37 37 conditions = "status <> 0"
38 38 conditions = ["status=?", @status] unless @status == 0
39 39
40 40 @user_count = User.count(:conditions => conditions)
41 41 @user_pages = Paginator.new self, @user_count,
42 42 per_page_option,
43 43 params['page']
44 44 @users = User.find :all,:order => sort_clause,
45 45 :conditions => conditions,
46 46 :limit => @user_pages.items_per_page,
47 47 :offset => @user_pages.current.offset
48 48
49 49 render :action => "list", :layout => false if request.xhr?
50 50 end
51 51
52 52 def add
53 53 if request.get?
54 54 @user = User.new(:language => Setting.default_language)
55 55 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
56 56 else
57 57 @user = User.new(params[:user])
58 58 @user.admin = params[:user][:admin] || false
59 59 @user.login = params[:user][:login]
60 60 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
61 61 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
62 62 @user.custom_values = @custom_values
63 63 if @user.save
64 64 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
65 65 flash[:notice] = l(:notice_successful_create)
66 66 redirect_to :action => 'list'
67 67 end
68 68 end
69 69 @auth_sources = AuthSource.find(:all)
70 70 end
71 71
72 72 def edit
73 73 @user = User.find(params[:id])
74 74 if request.get?
75 75 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
76 76 else
77 77 @user.admin = params[:user][:admin] if params[:user][:admin]
78 78 @user.login = params[:user][:login] if params[:user][:login]
79 79 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
80 80 if params[:custom_fields]
81 81 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
82 82 @user.custom_values = @custom_values
83 83 end
84 84 if @user.update_attributes(params[:user])
85 85 flash[:notice] = l(:notice_successful_update)
86 86 # Give a string to redirect_to otherwise it would use status param as the response code
87 87 redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
88 88 end
89 89 end
90 90 @auth_sources = AuthSource.find(:all)
91 91 @roles = Role.find_all_givable
92 92 @projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
93 93 @membership ||= Member.new
94 @memberships = @user.memberships
94 95 end
95 96
96 97 def edit_membership
97 98 @user = User.find(params[:id])
98 99 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
99 100 @membership.attributes = params[:membership]
100 if request.post? and @membership.save
101 flash[:notice] = l(:notice_successful_update)
102 end
103 redirect_to :action => 'edit', :id => @user and return
101 @membership.save if request.post?
102 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
104 103 end
105 104
106 105 def destroy_membership
107 106 @user = User.find(params[:id])
108 if request.post? and Member.find(params[:membership_id]).destroy
109 flash[:notice] = l(:notice_successful_update)
110 end
111 redirect_to :action => 'edit', :id => @user and return
107 Member.find(params[:membership_id]).destroy if request.post?
108 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
112 109 end
113 110 end
@@ -1,51 +1,57
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 module UsersHelper
19 19 def status_options_for_select(selected)
20 20 options_for_select([[l(:label_all), ''],
21 21 [l(:status_active), 1],
22 22 [l(:status_registered), 2],
23 23 [l(:status_locked), 3]], selected)
24 24 end
25 25
26 26 # Options for the new membership projects combo-box
27 27 def projects_options_for_select(projects)
28 28 options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
29 29 projects_by_root = projects.group_by(&:root)
30 30 projects_by_root.keys.sort.each do |root|
31 31 options << content_tag('option', h(root.name), :value => root.id, :disabled => (!projects.include?(root)))
32 32 projects_by_root[root].sort.each do |project|
33 33 next if project == root
34 34 options << content_tag('option', '&#187; ' + h(project.name), :value => project.id)
35 35 end
36 36 end
37 37 options
38 38 end
39 39
40 40 def change_status_link(user)
41 41 url = {:action => 'edit', :id => user, :page => params[:page], :status => params[:status]}
42 42
43 43 if user.locked?
44 44 link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
45 45 elsif user.registered?
46 46 link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
47 47 else
48 48 link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock'
49 49 end
50 50 end
51
52 def user_settings_tabs
53 tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general},
54 {:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
55 ]
56 end
51 57 end
@@ -1,32 +1,31
1 1 <%= error_messages_for 'user' %>
2 2
3 3 <!--[form:user]-->
4 4 <div class="box">
5 <h3><%=l(:label_information_plural)%></h3>
6 5 <p><%= f.text_field :login, :required => true, :size => 25 %></p>
7 6 <p><%= f.text_field :firstname, :required => true %></p>
8 7 <p><%= f.text_field :lastname, :required => true %></p>
9 8 <p><%= f.text_field :mail, :required => true %></p>
10 9 <p><%= f.select :language, lang_options_for_select %></p>
11 10
12 11 <% for @custom_value in @custom_values %>
13 12 <p><%= custom_field_tag_with_label @custom_value %></p>
14 13 <% end if @custom_values%>
15 14
16 15 <p><%= f.check_box :admin %></p>
17 16 </div>
18 17
19 18 <div class="box">
20 19 <h3><%=l(:label_authentication)%></h3>
21 20 <% unless @auth_sources.empty? %>
22 21 <p><%= f.select :auth_source_id, ([[l(:label_internal), ""]] + @auth_sources.collect { |a| [a.name, a.id] }), {}, :onchange => "if (this.value=='') {Element.show('password_fields');} else {Element.hide('password_fields');}" %></p>
23 22 <% end %>
24 23 <div id="password_fields" style="<%= 'display:none;' if @user.auth_source %>">
25 24 <p><label for="password"><%=l(:field_password)%><span class="required"> *</span></label>
26 25 <%= password_field_tag 'password', nil, :size => 25 %><br />
27 26 <em><%= l(:text_caracters_minimum, 4) %></em></p>
28 27 <p><label for="password_confirmation"><%=l(:field_password_confirmation)%><span class="required"> *</span></label>
29 28 <%= password_field_tag 'password_confirmation', nil, :size => 25 %></p>
30 29 </div>
31 30 </div>
32 31 <!--[eoform:user]-->
@@ -1,29 +1,40
1 <div class="box" style="margin-top: 16px;">
2 <h3><%= l(:label_project_plural) %></h3>
3
4 <% @user.memberships.each do |membership| %>
5 <% form_tag({ :action => 'edit_membership', :id => @user, :membership_id => membership }, :class => "tabular") do %>
6 <p style="margin:0;padding-top:0;">
7 <label><%= membership.project.name %></label>
8 <select name="membership[role_id]">
9 <%= options_from_collection_for_select @roles, "id", "name", membership.role_id %>
10 </select>
11 <%= submit_tag l(:button_change), :class => "button-small" %>
12 <%= link_to l(:button_delete), {:action => 'destroy_membership', :id => @user, :membership_id => membership }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
13 </p>
14 <% end %>
1 <% if @memberships.any? %>
2 <table class="list memberships">
3 <thead>
4 <th><%= l(:label_project) %></th>
5 <th><%= l(:label_role) %></th>
6 <th style="width:15%"></th>
7 </thead>
8 <tbody>
9 <% @memberships.each do |membership| %>
10 <% next if membership.new_record? %>
11 <tr class="<%= cycle 'odd', 'even' %>">
12 <td><%=h membership.project %></td>
13 <td align="center">
14 <% form_tag({ :action => 'edit_membership', :id => @user, :membership_id => membership }) do %>
15 <%= select_tag 'membership[role_id]', options_from_collection_for_select(@roles, "id", "name", membership.role_id) %>
16 <%= submit_tag l(:button_change), :class => "small" %>
17 <% end %>
18 </td>
19 <td align="center">
20 <%= link_to l(:button_delete), {:action => 'destroy_membership', :id => @user, :membership_id => membership }, :method => :post, :class => 'icon icon-del' %>
21 </td>
22 </tr>
23 </tbody>
24 <% end; reset_cycle %>
25 </table>
26 <% else %>
27 <p class="nodata"><%= l(:label_no_data) %></p>
15 28 <% end %>
16 29
17 30 <% if @projects.any? %>
18 <hr />
19 31 <p>
20 32 <label><%=l(:label_project_new)%></label><br/>
21 33 <% form_tag({ :action => 'edit_membership', :id => @user }) do %>
22 34 <%= select_tag 'membership[project_id]', projects_options_for_select(@projects) %>
23 35 <%= l(:label_role) %>:
24 36 <%= select_tag 'membership[role_id]', options_from_collection_for_select(@roles, "id", "name") %>
25 37 <%= submit_tag l(:button_add) %>
26 38 <% end %>
27 39 </p>
28 40 <% end %>
29 </div> No newline at end of file
@@ -1,8 +1,23
1 <h2><%=l(:label_user)%></h2>
1 <h2><%=l(:label_user)%>: <%=h @user.login %></h2>
2 2
3 <% labelled_tabular_form_for :user, @user, :url => { :action => "edit" } do |f| %>
4 <%= render :partial => 'form', :locals => { :f => f } %>
5 <%= submit_tag l(:button_save) %>
6 <% end %>
3 <% selected_tab = params[:tab] ? params[:tab].to_s : user_settings_tabs.first[:name] %>
7 4
8 <%= render :partial => 'memberships' %> No newline at end of file
5 <div class="tabs">
6 <ul>
7 <% user_settings_tabs.each do |tab| -%>
8 <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
9 :id => "tab-#{tab[:name]}",
10 :class => (tab[:name] != selected_tab ? nil : 'selected'),
11 :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
12 <% end -%>
13 </ul>
14 </div>
15
16 <% user_settings_tabs.each do |tab| -%>
17 <%= content_tag('div', render(:partial => tab[:partial]),
18 :id => "tab-content-#{tab[:name]}",
19 :style => (tab[:name] != selected_tab ? 'display:none' : nil),
20 :class => 'tab-content') %>
21 <% end -%>
22
23 <% html_title(l(:label_user), @user.login, l(:label_administration)) -%>
General Comments 0
You need to be logged in to leave comments. Login now