diff options
author | stephenbroyer <stephen.broyer@sonarsource.com> | 2013-10-11 15:13:10 +0200 |
---|---|---|
committer | stephenbroyer <stephen.broyer@sonarsource.com> | 2013-10-18 09:57:34 +0200 |
commit | a1255e6cacbb9b4b042dbbd0518b49a7043fe031 (patch) | |
tree | 2eb1df5330c43c96f50bd3a18d7b591e7f3fbce6 | |
parent | fad84b62f24cf7934413c3ffe241feb135e8c69a (diff) | |
download | sonarqube-a1255e6cacbb9b4b042dbbd0518b49a7043fe031.tar.gz sonarqube-a1255e6cacbb9b4b042dbbd0518b49a7043fe031.zip |
SONAR-4759 Use modal windows in Groups pages
(create and edit)
4 files changed, 137 insertions, 3 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb index f2d5fd5d878..3960b8aad5e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb @@ -30,16 +30,48 @@ class GroupsController < ApplicationController @group = Group.new end end - + + def create_modal_form + @groups = Group.find(:all, :order => 'name') + if params[:id] + @group = Group.find(params[:id]) + else + @group = Group.new + end + render :partial => 'groups/create_modal_form' + end + + def edit_modal_form + if params[:id] + @group = Group.find(params[:id]) + else + @group = Group.new + end + render :partial => 'groups/edit_modal_form' + end + def create group = Group.new(params[:group]) if group.save flash[:notice] = 'Group is created.' end - + to_index(group.errors, nil) end + def create_modal + group = Group.new(params[:group]) + if group.save + flash[:notice] = 'The new group is created.' + render :text => 'ok', :status => 200 + else + @group = group + @errors = [] + group.errors.full_messages.each{|msg| @errors<<msg} + render :partial => 'groups/create_modal_form', :status => 400 + end + end + def update group = Group.find(params[:id]) if group.update_attributes(params[:group]) @@ -49,6 +81,19 @@ class GroupsController < ApplicationController to_index(group.errors, nil) end + def update_modal + group = Group.find(params[:id]) + if group.update_attributes(params[:group]) + flash[:notice] = 'Group is updated.' + render :text => 'ok', :status => 200 + else + @group = group + @errors = [] + group.errors.full_messages.each{|msg| @errors<<msg} + render :partial => 'groups/edit_modal_form', :status => 400 + end + end + def destroy group = Group.find(params[:id]) if group.destroy diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/groups/_create_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/groups/_create_modal_form.html.erb new file mode 100644 index 00000000000..4584b5e297c --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/groups/_create_modal_form.html.erb @@ -0,0 +1,38 @@ +<% + action_name = 'create_modal' + title="Add new group" +%> +<% form_for :group, @group, :url => { :action => action_name, :id => @group.id}, :html => { :id =>'group_modal_form'} 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="group[]">Name:<em class="mandatory">*</em></label> + <%= f.text_field :name, :size => 25 %><br/> + <span class="desc">Ex: my-group</span> + </div> + <div class="modal-field"> + <label for="group[]">Description:</label> + <%= f.text_area :description, :rows => 3, :cols => 25 %> + </div> + </div> + + <div class="modal-foot"> + <%= submit_tag 'Create' %> + <%= link_to 'Cancel', { :controller => 'groups', :action => 'index', :id => nil}, { :class => 'action' } %><br/> + </div> + </fieldset> +<% end %> +<script> + $j("#group_modal_form").modalForm(); +</script>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/groups/_edit_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/groups/_edit_modal_form.html.erb new file mode 100644 index 00000000000..3e7297757b9 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/groups/_edit_modal_form.html.erb @@ -0,0 +1,38 @@ +<% + action_name = 'update_modal' + title='Edit group' +%> +<% form_for :group, @group, :url => { :action => action_name, :id => @group.id}, :html => { :id =>'group_modal_form'} do |f| %> + <fieldset> + <div class="modal-head"> + <h2><%= title %> <%= @group.name -%></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="group[]">Name:<em class="mandatory">*</em></label> + <%= f.text_field :name, :size => 25 %><br/> + <span class="desc">Ex: my-group</span> + </div> + <div class="modal-field"> + <label for="group[]">Description:</label> + <%= f.text_area :description, :rows => 3, :cols => 25 %> + </div> + </div> + + <div class="modal-foot"> + <%= submit_tag 'Save' -%> + <%= link_to 'Cancel', { :controller => 'groups', :action => 'index', :id => nil}, { :class => 'action' } %><br/> + </div> + </fieldset> +<% end %> +<script> + $j("#group_modal_form").modalForm(); +</script>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/groups/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/groups/index.html.erb index 70dcedfa53a..c5d889a6cdf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/groups/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/groups/index.html.erb @@ -1,7 +1,18 @@ +<div class="line-block"> + <% if profiles_administrator? %> + <ul style="float: right" class="horizontal"> + <li class="marginleft10 add"> + <a href="<%=ApplicationController.root_context-%>/groups/create_modal_form" class="open-modal link-action">Add new group</a> + </li> + </ul> + <% end %> + <h1 class="marginbottom10">Groups</h1> +</div> + + <table width="100%"> <tr> <td valign="top"> - <h1 class="marginbottom10">Groups</h1> <table class="data width100 sortable" id="groups"> <thead> @@ -24,6 +35,8 @@ <%= link_to "Edit", { :action => 'index', :id => group.id}, { :method => :get, :id => "edit-#{u group.name}", :class => 'link-action'} %> + <a id='edit-<%= h group.name %>' method='get' class='open-modal link-action' href="<%=ApplicationController.root_context-%>/groups/edit_modal_form/<%= h group.id %>">Edit_modal</a> + <%= link_to "Delete", { :action => 'destroy', :id => group.id}, {:confirm => "Are you sure that you want to delete this group? Members will not be deleted.", :class => 'link-action link-red', :method => 'get', :id => "delete-#{u group.name}"} %> </td> |