From 9ae9db5585225d07a6450a78ec292f4cfc70fde6 Mon Sep 17 00:00:00 2001 From: stephenbroyer Date: Thu, 10 Oct 2013 16:12:10 +0200 Subject: SONAR-4538 Use modal windows to create & edit in SonarQube (edit and update user) --- .../WEB-INF/app/controllers/users_controller.rb | 43 +++++++++++++++++++++ .../users/_change_password_modal_form.html.erb | 39 +++++++++++++++++++ .../app/views/users/_create_modal_form.html.erb | 40 ++++++------------- .../app/views/users/_edit_modal_form.html.erb | 45 ++++++++++++++++++++++ .../webapp/WEB-INF/app/views/users/index.html.erb | 5 +++ .../src/main/webapp/WEB-INF/config/routes.rb | 1 + 6 files changed, 144 insertions(+), 29 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/users/_change_password_modal_form.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/users/_edit_modal_form.html.erb 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("
\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("
\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| %> +
+ + + +
+<% end %> + + \ 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| %>
@@ -35,30 +24,23 @@ <%= f.text_field :login, :size => 30, :maxLength => 40 %> <% end %> - <% if params[:action] != 'change_password' %> - + + + + - - <% end %> - <% if !@user.id || @errors %> - - - <% elsif params[:action] == 'change_password' %> - - - <% end %>
- <% end %> + \ 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| %> +
+ + + +
+<% end %> + + \ 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 @@ <%= link_to "Edit", { :id => user.id, :action => 'edit'}, {:id => "edit-#{u user.login}", :class => 'link-action'} %>   + + Edit_modal +   <%= link_to "Change password", { :id => user.id, :action => 'change_password'}, {:id => "change-password-#{u user.login}", :class => 'link-action'} %>   + <%= 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 "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'} %> 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| -- cgit v1.2.3