aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstephenbroyer <stephen.broyer@sonarsource.com>2013-10-11 16:13:34 +0200
committerstephenbroyer <stephen.broyer@sonarsource.com>2013-10-18 09:57:34 +0200
commitb0333039ef7ff91584bac05464e17e8cb44f8799 (patch)
treee21a9e3c7cb89e84fb0c4b64dd0a36ba2112eeaf
parenta1255e6cacbb9b4b042dbbd0518b49a7043fe031 (diff)
downloadsonarqube-b0333039ef7ff91584bac05464e17e8cb44f8799.tar.gz
sonarqube-b0333039ef7ff91584bac05464e17e8cb44f8799.zip
SONAR-4758 Use modal windows in Users pages
(remove yellow form)
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb109
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_form.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_modal_form.html.erb)14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_form.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb)13
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_form.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_modal_form.html.erb)13
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_form.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_modal_form.html.erb)12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb96
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/config/routes.rb4
7 files changed, 38 insertions, 223 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
index e8464b29432..1d42a422405 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
@@ -27,33 +27,6 @@ class UsersController < ApplicationController
def create
return unless request.post?
cookies.delete :auth_token
-
- user = User.find_by_login(params[:user][:login])
- if user && !user.active
- # users is deativated, this is a special case:
- # 1- first, we save the given information, in case the user is reactivated (to not ask for it twice)
- if user.update_attributes(params[:user])
- # 2- if info correctly saved, then we display a message to ask wether the user should be reactivated or not
- @user = user
- init_users_list
- render :index
- else
- to_index(user.errors, nil)
- end
- else
- user=prepare_user
- if user.save
- user.notify_creation_handlers
- flash[:notice] = 'User is created.'
- end
- to_index(user.errors, nil)
- end
-
- end
-
- def create_modal
- return unless request.post?
- cookies.delete :auth_token
@errors = []
user = User.find_by_login(params[:user][:login])
if user && !user.active
@@ -61,13 +34,13 @@ class UsersController < ApplicationController
# case user: exist,inactive,no errors when update BUT TO REACTIVATE
@user = user
user.errors.full_messages.each{|msg| @errors<<msg}
- render :partial => 'users/reactivate_modal_form', :status => 400
+ render :partial => 'users/reactivate_form', :status => 400
else
# case user: exist,inactive, WITH ERRORS when update
@user = user
@user.id = nil
user.errors.full_messages.each{|msg| @errors<<msg}
- render :partial => 'users/create_modal_form', :status => 400
+ render :partial => 'users/create_form', :status => 400
end
else
user=prepare_user
@@ -81,7 +54,7 @@ class UsersController < ApplicationController
# case user: exist and ACTIVE, whith or without errors when create
@user = user
user.errors.full_messages.each{|msg| @errors<<msg}
- render :partial => 'users/create_modal_form', :status => 400
+ render :partial => 'users/create_form', :status => 400
end
end
end
@@ -109,109 +82,71 @@ class UsersController < ApplicationController
end
end
- def create_modal_form
+ def create_form
init_users_list
if params[:id]
@user = User.find(params[:id])
else
@user = User.new
end
- render :partial => 'users/create_modal_form'
+ render :partial => 'users/create_form'
end
- def reactivate_modal_form
+ def reactivate_form
init_users_list
if params[:id]
@user = User.find(params[:id])
else
@user = User.new
end
- render :partial => 'users/reactivate_modal_form'
+ render :partial => 'users/reactivate_form'
end
def new
render :action => 'new', :layout => 'nonav'
end
- def edit
- redirect_to(:action => 'index', :id => params[:id])
- end
-
- def edit_modal_form
+ def edit_form
init_users_list
@user = User.find(params[:id])
- render :partial => 'users/edit_modal_form', :status =>200
+ render :partial => 'users/edit_form', :status =>200
end
- def change_password
- init_users_list
- @user = User.find(params[:id])
- render :action => 'index', :id => params[:id]
- end
- def change_password_modal_form
+ def change_password_form
init_users_list
@user = User.find(params[:id])
- render :partial => 'users/change_password_modal_form', :status =>200
+ render :partial => 'users/change_password_form', :status =>200
end
def update_password
user = User.find(params[:id])
-
- if params[:user][:password].blank?
- flash[:error] = 'Password required.'
- redirect_to(:action => 'change_password', :id => params[:id])
- elsif user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation])
- flash[:notice] = 'Password was successfully updated.'
- to_index(user.errors, nil)
- else
- flash[:error] = user.errors.full_messages.join("<br/>\n")
- redirect_to(:action => 'change_password', :id => params[:id])
- end
-
- end
-
- def update
- user = User.find(params[:id])
-
- if user.login!=params[:user][:login]
- flash[:error] = 'Login can not be changed.'
-
- elsif user.update_attributes(params[:user])
- flash[:notice] = 'User was successfully updated.'
- end
-
- to_index(user.errors, nil)
- end
-
- def update_password_modal
- user = User.find(params[:id])
@user = user
if params[:user][:password].blank?
@errors = 'Password required.'
- render :partial => 'users/change_password_modal_form', :status => 400
+ render :partial => 'users/change_password_form', :status => 400
elsif user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation])
flash[:notice] = 'Password was successfully updated.'
render :text => 'ok', :status => 200
else
@errors = user.errors.full_messages.join("<br/>\n")
- render :partial => 'users/change_password_modal_form', :status => 400
+ render :partial => 'users/change_password_form', :status => 400
end
end
- def update_modal
+ def update
user = User.find(params[:id])
@user = user
@errors = []
if user.login!=params[:user][:login]
@errors = 'Login can not be changed.'
- render :partial => 'users/edit_modal_form', :status => 400
+ render :partial => 'users/edit_form', :status => 400
elsif user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
render :text => 'ok', :status => 200
else
@errors = user.errors.full_messages.join("<br/>\n")
- render :partial => 'users/edit_modal_form', :status => 400
+ render :partial => 'users/edit_form', :status => 400
end
end
@@ -221,18 +156,6 @@ class UsersController < ApplicationController
user.reactivate!(java_facade.getSettings().getString('sonar.defaultGroup'))
user.notify_creation_handlers
flash[:notice] = 'User was successfully reactivated.'
- else
- flash[:error] = "A user with login #{params[:user][:login]} does not exist."
- end
- to_index(user.errors, nil)
- end
-
- def reactivate_modal
- user = User.find_by_login(params[:user][:login])
- if user
- user.reactivate!(java_facade.getSettings().getString('sonar.defaultGroup'))
- user.notify_creation_handlers
- flash[:notice] = 'User was successfully reactivated.'
render :text => 'ok', :status => 200
else
flash[:error] = "A user with login #{params[:user][:login]} does not exist."
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_form.html.erb
index e13d7e6065d..3b6a1542731 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_modal_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_form.html.erb
@@ -1,12 +1,7 @@
-<%
- submit_button_label = 'Save'
- action_name = 'update_password_modal'
- title = 'Change password'
-%>
-<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
+<% form_for :user, @user, :url => { :id => @user.id, :action => 'update_password'}, :html => { :id =>'user_form', :method => @user.id.nil? ? :post : :put} do |f| %>
<fieldset>
<div class="modal-head">
- <h2><%= title %>&nbsp;for user&nbsp;<%= @user.login %></h2>
+ <h2>Change password &nbsp;for user&nbsp;<%= @user.login %></h2>
</div>
<div class="modal-body">
<% if @errors
@@ -25,14 +20,15 @@
</div>
<div class="modal-field"><label for="user[password]">New password</label><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
<div class="modal-field"><label for="user[password_confirmation]">Confirm password</label><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
+
</div>
<div class="modal-foot">
- <%= submit_tag submit_button_label %>
+ <%= submit_tag 'Save' %>
<%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
</div>
</fieldset>
<% end %>
<script>
- $j("#user_modal_form").modalForm();
+ $j("#user_form").modalForm();
</script> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_form.html.erb
index a3e1e025b41..03cfadafbe7 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_form.html.erb
@@ -1,12 +1,7 @@
-<%
- action_name = 'create_modal'
- title = 'Add new user'
- submit_button_label = 'Create'
-%>
-<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
+<% form_for :user, @user, :url => { :id => @user.id, :action => 'create' }, :html => { :id =>'user_form', :method => @user.id.nil? ? :post : :put} do |f| %>
<fieldset>
<div class="modal-head">
- <h2><%= title %></h2>
+ <h2>Add new user</h2>
</div>
<div class="modal-body">
<% if @errors
@@ -35,12 +30,12 @@
</div>
<div class="modal-foot">
- <%= submit_tag submit_button_label %>
+ <%= submit_tag 'Create' %>
<%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
</div>
</fieldset>
<% end %>
<script>
- $j("#user_modal_form").modalForm();
+ $j("#user_form").modalForm();
</script> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_form.html.erb
index c78ab4290f5..18fb61fa69b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_modal_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_form.html.erb
@@ -1,12 +1,7 @@
-<%
- action_name = 'update_modal'
- title = 'Edit user'
- submit_button_label = 'Save'
-%>
-<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
+<% form_for :user, @user, :url => { :id => @user.id, :action => 'update'}, :html => { :id =>'user_form', :method => @user.id.nil? ? :post : :put} do |f| %>
<fieldset>
<div class="modal-head">
- <h2><%= title %>&nbsp;<%= @user.login %></h2>
+ <h2>Edit user &nbsp;<%= @user.login %></h2>
</div>
<div class="modal-body">
<% if @errors
@@ -33,12 +28,12 @@
</div>
</div>
<div class="modal-foot">
- <%= submit_tag submit_button_label %>
+ <%= submit_tag 'Save' %>
<%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
</div>
</fieldset>
<% end %>
<script>
- $j("#user_modal_form").modalForm();
+ $j("#user_form").modalForm();
</script> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_form.html.erb
index aa105217040..60e05a82539 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_modal_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_form.html.erb
@@ -1,11 +1,7 @@
-<% action_name = 'reactivate_modal'
- title = 'Reactivate user?'
- submit_button_label = 'Reactivate user'
-%>
-<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
+<% form_for :user, @user, :url => { :id => @user.id, :action => 'reactivate' }, :html => { :id =>'user_form', :method => @user.id.nil? ? :post : :put} do |f| %>
<fieldset>
<div class="modal-head">
- <h2><%= title %></h2>
+ <h2>Reactivate user?</h2>
</div>
<div class="modal-body">
<%= f.hidden_field :login %>
@@ -17,12 +13,12 @@
</p>
</div>
<div class="modal-foot">
- <%= submit_tag submit_button_label %>
+ <%= submit_tag 'Reactivate user' %>
<%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
</div>
</fieldset>
<script>
- $j("#user_modal_form").modalForm();
+ $j("#user_form").modalForm();
</script>
<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb
index 039f6af1b6b..dd6cee25cf0 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb
@@ -2,7 +2,7 @@
<% if profiles_administrator? %>
<ul style="float: right" class="horizontal">
<li class="marginleft10 add">
- <a href="<%=ApplicationController.root_context-%>/users/create_modal_form" class="open-modal link-action">Add new user</a>
+ <a href="<%=ApplicationController.root_context-%>/users/create_form" class="open-modal link-action">Add new user</a>
</li>
</ul>
<% end %>
@@ -32,14 +32,9 @@
<%= user.groups.sort.map(&:name).join(', ') %> (<%= link_to "select", {:action => 'select_group', :id => user.id}, {:id => "select-#{u user.login}", :class => 'link-action'} %>)
</td>
<td class="left" valign="top">
- <%= link_to "Edit", { :id => user.id, :action => 'edit'}, {:id => "edit-#{u user.login}", :class => 'link-action'} %>
+ <a id="edit-<%= user.name -%>" class="open-modal link-action" href="<%=ApplicationController.root_context-%>/users/edit_form/<%= user.id -%>">Edit</a>
&nbsp;
-
- <a id="edit-modal-azaz" class="open-modal link-action" href="<%=ApplicationController.root_context-%>/users/edit_modal_form/<%= user.id -%>">Edit_modal</a>
- &nbsp;
- <%= link_to "Change password", { :id => user.id, :action => 'change_password'}, {:id => "change-password-#{u user.login}", :class => 'link-action'} %>
- &nbsp;
- <%= link_to "Change password_modal", { :id => user.id, :action => 'change_password_modal_form'}, {:id => "change-password-modal-#{u user.login}", :class => 'open-modal link-action'} %>
+ <%= link_to "Change password", { :id => user.id, :action => 'change_password_form'}, {:id => "change-password-#{u user.login}", :class => 'open-modal link-action'} %>
&nbsp;
<%= link_to "Delete", {:action => 'destroy', :id => user.id}, {:confirm => "Warning : are you sure to delete this user?", :method => 'delete',
:id => "delete-#{u user.login}", :class => 'link-action link-red'} %>
@@ -50,90 +45,5 @@
</table>
<script>TableKit.Sortable.init('users');</script>
</td>
- <td class="sep"> </td>
- <td valign="top" align="right" width="210">
- <%
- action_name = 'create'
- title = 'Add new user'
- submit_button_label = 'Create'
- if @user.id
- if @user.active
- action_name = 'update'
- title = 'Edit user'
- submit_button_label = 'Update'
- if params[:action] == 'change_password'
- action_name = 'update_password'
- title = 'Change password'
- end
- else
- action_name = 'reactivate'
- title = 'Reactivate user?'
- submit_button_label = 'Reactivate user'
- end
- end
- %>
-
- <% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :method => @user.id.nil?? :post : :put } do |f| %>
- <table class="admintable" width="100%">
- <tr>
- <td class="left" valign="top"><h1><%= title %></h1></td>
- </tr>
-
- <% if @user && !@user.active %>
- <%= f.hidden_field :login %>
- <tr>
- <td>
- <p class="error">
- A user with login "<%= @user.login -%>" already exists in the database but is deactivated.<br/>
- <br/>
- Do you really want to reactivate this user?
- </p>
- </td>
- <tr>
- <% else %>
- <tr>
- <td class="left" valign="top">Login:
- <% if @user.id %>
- <%= @user.login %>
- <%= f.hidden_field :login %>
- <% else %>
- <br/><%= f.text_field :login, :size => 30, :maxLength => 40 %>
- <% end %>
- </td>
- </tr>
- <% if params[:action] != 'change_password' %>
- <tr>
- <td class="left" valign="top">Name:<br/><%= f.text_field :name, :size => 30, :maxLength => 200 %></td>
- </tr>
- <tr>
- <td class="left" valign="top">Email:<br/><%= f.text_field :email, :size => 30, :maxLength => 100 %></td>
- </tr>
- <% end %>
- <% if !@user.id %>
- <tr>
- <td class="left" valign="top">Password:<br/><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></td>
- </tr>
- <tr>
- <td class="left" valign="top">Confirm password:<br/><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></td>
- </tr>
- <% elsif params[:action] == 'change_password' %>
- <tr>
- <td class="left" valign="top">New password:<br/><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></td>
- </tr>
- <tr>
- <td class="left" valign="top">Confirm new password:<br/><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></td>
- </tr>
- <% end %>
- <% end %>
-
- <tr>
- <td class="left" nowrap="nowrap" valign="top" colspan="2">
- <%= submit_tag submit_button_label %>
- <%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
- </td>
- </tr>
- </table>
- <% end %>
- </td>
</tr>
</table>
diff --git a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
index 348c0d68535..6c60ff70a8e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
@@ -1,8 +1,8 @@
ActionController::Routing::Routes.draw do |map|
map.connect 'users/select_group', :controller => 'users', :action => 'select_group'
map.connect 'users/set_groups', :controller => 'users', :action => 'set_groups'
- map.connect 'users/create_modal_form', :controller => 'users', :action => 'create_modal_form'
- map.connect 'users/edit_modal_form', :controller => 'users', :action => 'edit_modal_form'
+ map.connect 'users/create_form', :controller => 'users', :action => 'create_form'
+ map.connect 'users/edit_form', :controller => 'users', :action => 'edit_form'
map.resources :users
map.namespace :api do |api|