aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstephenbroyer <stephen.broyer@sonarsource.com>2013-10-10 16:12:10 +0200
committerstephenbroyer <stephen.broyer@sonarsource.com>2013-10-10 16:12:36 +0200
commit9ae9db5585225d07a6450a78ec292f4cfc70fde6 (patch)
tree7a0948ea807523d90c7c8b708855f9e69d5a3ba4
parentf11d84b4c45711fb168aecc047332051ede8aeea (diff)
downloadsonarqube-9ae9db5585225d07a6450a78ec292f4cfc70fde6.tar.gz
sonarqube-9ae9db5585225d07a6450a78ec292f4cfc70fde6.zip
SONAR-4538 Use modal windows to create & edit in SonarQube
(edit and update user)
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb43
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_modal_form.html.erb39
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb40
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_modal_form.html.erb45
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb5
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/config/routes.rb1
6 files changed, 144 insertions, 29 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 2639c182385..e8464b29432 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
@@ -137,12 +137,24 @@ class UsersController < ApplicationController
redirect_to(:action => 'index', :id => params[:id])
end
+ def edit_modal_form
+ init_users_list
+ @user = User.find(params[:id])
+ render :partial => 'users/edit_modal_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
+ init_users_list
+ @user = User.find(params[:id])
+ render :partial => 'users/change_password_modal_form', :status =>200
+ end
+
def update_password
user = User.find(params[:id])
@@ -172,6 +184,37 @@ class UsersController < ApplicationController
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
+ 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
+ end
+ end
+
+ def update_modal
+ 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
+ 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
+ end
+ end
+
def reactivate
user = User.find_by_login(params[:user][:login])
if user
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_modal_form.html.erb
new file mode 100644
index 00000000000..b6a43fe97e4
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_modal_form.html.erb
@@ -0,0 +1,39 @@
+<%
+ submit_button_label = 'Update'
+ 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| %>
+ <fieldset>
+ <div class="modal-head">
+ <h2><%= title %></h2>
+ </div>
+ <div class="modal-body">
+ <% if @errors
+ @errors.each do |error|
+ %>
+ <p class="error"><%= h error -%></p>
+ <% end
+ end
+ %>
+ <div class="modal-field"><label for="user[login]">Login<em class="mandatory">*</em></label>
+ <% if @user.id %>
+ <%= @user.login %>
+ <%= f.hidden_field :login %>
+ <% else %>
+ <%= f.text_field :login, :size => 30, :maxLength => 40 %>
+ <% end %>
+ </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 %>
+ <%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
+ </div>
+ </fieldset>
+<% end %>
+
+<script>
+ $j("#user_modal_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_modal_form.html.erb
index 60f117d50eb..a3e1e025b41 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_modal_form.html.erb
@@ -2,17 +2,6 @@
action_name = 'create_modal'
title = 'Add new user'
submit_button_label = 'Create'
- if @user.id
- if @user.active
- action_name = 'update_modal'
- title = 'Edit user'
- submit_button_label = 'Update'
- if params[:action] == 'change_password'
- action_name = 'update_password_modal'
- title = 'Change password'
- end
- end
- end
%>
<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
<fieldset>
@@ -35,30 +24,23 @@
<%= f.text_field :login, :size => 30, :maxLength => 40 %>
<% end %>
</div>
- <% if params[:action] != 'change_password' %>
- <div class="modal-field">
- <label for="user[]">Name<em class="mandatory">*</em></label>
- <%= f.text_field :name, :size => 30, :maxLength => 200 %></div>
+ <div class="modal-field">
+ <label for="user[]">Name<em class="mandatory">*</em></label>
+ <%= f.text_field :name, :size => 30, :maxLength => 200 %></div>
+ <div class="modal-field">
+ <label for="user[]">Email</label>
+ <%= f.text_field :email, :size => 30, :maxLength => 100 %></div>
+ <div class="modal-field"><label for="user[password]">Password<em class="mandatory">*</em></label><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
+ <div class="modal-field"><label for="user[password_confirmation]">Confirm password<em class="mandatory">*</em></label><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
- <div class="modal-field">
- <label for="user[]">Email</label>
- <%= f.text_field :email, :size => 30, :maxLength => 100 %></div>
- <% end %>
- <% if !@user.id || @errors %>
- <div class="modal-field"><label for="user[password]">Password<em class="mandatory">*</em></label><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
- <div class="modal-field"><label for="user[password_confirmation]">Confirm password<em class="mandatory">*</em></label><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
- <% elsif params[:action] == 'change_password' %>
- <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>
- <% end %>
</div>
<div class="modal-foot">
<%= submit_tag submit_button_label %>
<%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
</div>
</fieldset>
- <script>
- $j("#user_modal_form").modalForm();
- </script>
<% end %>
+<script>
+ $j("#user_modal_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_modal_form.html.erb
new file mode 100644
index 00000000000..0f2cb74e518
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_modal_form.html.erb
@@ -0,0 +1,45 @@
+<%
+ action_name = 'update_modal'
+ title = 'Edit user'
+ submit_button_label = 'Update'
+%>
+<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
+ <fieldset>
+ <div class="modal-head">
+ <h2><%= title %></h2>
+ </div>
+ <div class="modal-body">
+ <% if @errors
+ @errors.each do |error|
+ %>
+ <p class="error"><%= h error -%></p>
+ <% end
+ end
+ %>
+ <div class="modal-field"><label for="user[login]">Login<em class="mandatory">*</em></label>
+ <% if @user.id %>
+ <%= @user.login %>
+ <%= f.hidden_field :login %>
+ <% else %>
+ <%= f.text_field :login, :size => 30, :maxLength => 40 %>
+ <% end %>
+ </div>
+ <div class="modal-field">
+ <label for="user[]">Name<em class="mandatory">*</em></label>
+ <%= f.text_field :name, :size => 30, :maxLength => 200 %>
+ </div>
+ <div class="modal-field">
+ <label for="user[]">Email</label>
+ <%= f.text_field :email, :size => 30, :maxLength => 100 %>
+ </div>
+ </div>
+ <div class="modal-foot">
+ <%= submit_tag submit_button_label %>
+ <%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
+ </div>
+ </fieldset>
+<% end %>
+
+<script>
+ $j("#user_modal_form").modalForm();
+</script> \ No newline at end of file
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 946e98169bb..039f6af1b6b 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
@@ -34,8 +34,13 @@
<td class="left" valign="top">
<%= link_to "Edit", { :id => user.id, :action => 'edit'}, {:id => "edit-#{u user.login}", :class => 'link-action'} %>
&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'} %>
+ &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'} %>
</td>
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 8164614f56e..348c0d68535 100644
--- a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
@@ -2,6 +2,7 @@ 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.resources :users
map.namespace :api do |api|