diff options
author | stephenbroyer <stephen.broyer@sonarsource.com> | 2013-10-11 18:29:01 +0200 |
---|---|---|
committer | stephenbroyer <stephen.broyer@sonarsource.com> | 2013-10-23 17:53:44 +0200 |
commit | ee5fe9ad9530ac5a63be6f8916df67bf778fb869 (patch) | |
tree | b5cd1df08ff196050197c6553db00aaf862ba008 /sonar-server | |
parent | 37ca5cdb866cbd9bc9c216126888c875faf8a153 (diff) | |
download | sonarqube-ee5fe9ad9530ac5a63be6f8916df67bf778fb869.tar.gz sonarqube-ee5fe9ad9530ac5a63be6f8916df67bf778fb869.zip |
SONAR-4760 Use modal windows in Manual Rules pages
Diffstat (limited to 'sonar-server')
4 files changed, 121 insertions, 51 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb index 4207b14337f..29f2ab1b8bd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb @@ -31,31 +31,53 @@ class ManualRulesController < ApplicationController end def edit - @rules = Rule.manual_rules() - @rule=Rule.manual_rule(params['id'].to_i) - bad_request('Missing rule id') unless @rule - render :action => 'index' + verify_post_request + access_denied unless is_admin? + begin + # Update rule + rule=Rule.manual_rule(params['id'].to_i) + bad_request('Unknown rule') unless rule + rule.name=(params[:name]) + rule.description=params[:description] + rule.save! + rescue Exception => e + @error= e.message + end + @rule = rule + if @error + render :partial => 'manual_rules/edit_form', :status => 400 + else + flash[:notice] = 'Manual rule saved' + render :text => 'ok', :status => 200 + end + end def create verify_post_request access_denied unless is_admin? begin - if params[:id].to_i>0 - # Update rule - rule=Rule.manual_rule(params['id'].to_i) - bad_request('Unknown rule') unless rule - rule.name=(params[:name]) - rule.description=params[:description] - rule.save! - else # Create rule Rule.create_manual_rule(params) - end rescue Exception => e - flash[:error]= e.message + @error= e.message end - redirect_to :action => 'index' + if @error + render :partial => 'manual_rules/create_form', :status => 400 + else + flash[:notice] = 'Manual rule created' + render :text => 'ok', :status => 200 + end + end + + def create_form + @rule = Rule.new + render :partial => 'manual_rules/create_form' + end + + def edit_form + @rule=Rule.manual_rule(params['id'].to_i) + render :partial => 'manual_rules/edit_form', :status => 200 end def delete diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/_create_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/_create_form.html.erb new file mode 100644 index 00000000000..3a7350ae605 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/_create_form.html.erb @@ -0,0 +1,35 @@ +<% if is_admin? %> + <form action="<%= ApplicationController.root_context -%>/manual_rules/create" method="POST" id="manual-rules-form"> + <fieldset> + <div class="modal-head"> + <h2>Create Manual Rule</h2> + </div> + + <div class="modal-body"> + <% if @error %> + <p class="error"><%= @error -%></p> + <% end %> + <div class="modal-field"> + <label for="manual_rules[]">Name<em class="mandatory">*</em>:</label> + <input type="text" name="name" value=""/> + <br/> + <span class="desc">Ex. : Performance</span> + </div> + <div class="modal-field"> + <label for="manual_rules[]">Description:</label> + <textarea rows="5" cols="25" name="description"></textarea> + <br/> + </div> + </div> + + <div class="modal-foot"> + <input type="submit" value="Create"/> + <%= link_to 'Cancel', { :controller => 'manual_rules', :action => 'index'}, { :class => 'action' } %><br/> + </div> + </fieldset> + </form> +<% end %> + +<script> + $j("#manual-rules-form").modalForm(); +</script>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/_edit_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/_edit_form.html.erb new file mode 100644 index 00000000000..ddf0b708c98 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/_edit_form.html.erb @@ -0,0 +1,36 @@ +<% if is_admin? %> + <form action="<%= ApplicationController.root_context -%>/manual_rules/edit" method="POST" id="manual-rules-form"> + <fieldset> + <div class="modal-head"> + <h2>Edir rule <%= @rule.name -%></h2> + </div> + + <div class="modal-body"> + <% if @error %> + <p class="error"><%= @error -%></p> + <% end %> + <input type="hidden" name="id" value="<%= @rule.id -%>"/> + <div class="modal-field"> + <label for="manual_rules[]">Name<em class="mandatory">*</em>:</label> + <input type="text" name="name" value="<%= h @rule.name -%>"/> + <br/> + <span class="desc">Ex. : Performance</span> + </div> + <div class="modal-field"> + <label for="manual_rules[]">Description:</label> + <textarea rows="5" cols="25" name="description"><%= h(@rule.description) -%></textarea> + <br/> + </div> + </div> + + <div class="modal-foot"> + <input type="submit" value="save"/> + <%= link_to 'Cancel', { :controller => 'manual_rules', :action => 'index'}, { :class => 'action' } %><br/> + </div> + </fieldset> + </form> +<% end %> + +<script> + $j("#manual-rules-form").modalForm(); +</script>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/index.html.erb index 590ee37467d..1c7ad51f159 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_rules/index.html.erb @@ -1,7 +1,17 @@ +<div class="line-block"> + <% if profiles_administrator? %> + <ul style="float: right" class="horizontal"> + <li class="marginleft10 add"> + <a href="<%=ApplicationController.root_context-%>/manual_rules/create_form" class="open-modal link-action">Create Manual Rule</a> + </li> + </ul> + <% end %> + <h1 class="marginbottom10"><%= message('manual_rules.page') -%></h1> +</div> + <table width="100%"> <tr> <td valign="top"> - <h1 class="marginbottom10"><%= message('manual_rules.page') -%></h1> <table class="data width100" id="manual-rules"> <thead> <tr> @@ -23,8 +33,8 @@ <span class="note"><%= h rule.description -%></span> </td> <td class="right thin nowrap"> - <%= link_to 'Edit', {:action => 'edit', :id => rule.id}, {:id => "edit_#{u(rule.key)}", :class => 'link-action'} %> - + <a id="edit-<%= u(rule.key) -%>" class="open-modal link-action" href="<%=ApplicationController.root_context-%>/manual_rules/edit_form/<%= h rule.id -%>">Edit</a> + <%= link_to 'Delete', {:action => 'delete', :id => rule.id}, {:confirm => message('are_you_sure'), :id => "delete_#{u(rule.key)}", :class => 'link-action link-red', :method => 'delete'} %> </td> </tr> @@ -32,38 +42,5 @@ </tbody> </table> </td> - <% if is_admin? %> - <td class="sep"></td> - <td valign="top" align="right" width="210"> - <form action="<%= ApplicationController.root_context -%>/manual_rules/create" method="POST" id="manual-rules-form"> - <table class="admintable" width="100%"> - <input type="hidden" name="id" value="<%= @rule.id -%>"/> - <tr> - <td class="left"><h1 class="marginbottom10"><%= @rule && @rule.id.nil? ? 'Create Manual Rule' : 'Edit Manual Rule' -%></h1></td> - </tr> - <tr> - <td class="left" valign="top"> - Name:<br/><input type="text" name="name" value="<%= h @rule.name -%>"/> - <br/> - <span class="desc">Ex. : Performance</span> - </td> - </tr> - <tr> - <td class="left" valign="top"> - Description:<br/> - <textarea rows="5" cols="25" name="description"><%= h(@rule.description) -%></textarea> - <br/> - </td> - </tr> - <tr> - <td class="left" valign="top"> - <input type="submit" value="<%= @rule.id.nil? ? message('create') : message('edit') -%>"/> - <%= link_to 'Cancel', { :controller => 'manual_rules', :action => 'index'}, { :class => 'action' } %><br/> - </td> - </tr> - </table> - </form> - </td> - <% end %> </tr> </table> |