diff options
10 files changed, 221 insertions, 153 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/confirm_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/confirm_controller.rb new file mode 100644 index 00000000000..b7152864157 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/confirm_controller.rb @@ -0,0 +1,27 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2012 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# Sonar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# +class ConfirmController < ApplicationController + + # GET /confirm?url=<return_to_url>&[t=<title_key] + def index + render :partial => 'confirm/confirm' + end + +end
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index f4dce0e9777..8cde294ce38 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -24,7 +24,7 @@ class ProfilesController < ApplicationController verify :method => :post, :only => ['create', 'delete', 'copy', 'set_as_default', 'restore', 'set_projects', 'rename', 'change_parent'], :redirect_to => { :action => 'index' } # the backup action is allow to non-admin users : see http://jira.codehaus.org/browse/SONAR-2039 - before_filter :admin_required, :only => ['create', 'delete', 'set_as_default', 'copy', 'restore', 'change_parent', 'set_projects', 'rename'] + before_filter :admin_required, :only => ['create', 'delete', 'set_as_default', 'copy', 'restore', 'change_parent', 'set_projects', 'rename_form', 'rename'] # # @@ -95,7 +95,6 @@ class ProfilesController < ApplicationController @profile = Profile.find(params[:id]) if @profile && @profile.deletable? java_facade.deleteProfile(@profile.id) - flash[:notice]=message('quality_profiles.profile_x_deleted', :params => @profile.name) end redirect_to(:controller => 'profiles', :action => 'index') end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index 6113d09b376..fd50d5d2c1e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -719,4 +719,29 @@ module ApplicationHelper js = "$j('##{html_id}').select2({#{js_options.map{|k,v| "#{k}:#{v}"}.join(',')}});" "#{html}<script>#{js}</script>" end + + # + # Creates a button linked to a POST action. A confirmation popup is opened when user clicks on the button. + # ==== Options + # * <tt>:id</tt> - HTML ID of the button + # * <tt>:class</tt> - Additional CSS class, generally 'red-button' for deletions + # * <tt>:message_key</tt> - + # * <tt>:message_params</tt> - + # * <tt>:width</tt> - width in pixels + # + def button_to_action(label, post_url, options={}) + clazz = options[:class] + id = "id='#{options[:id]}'" if options[:id] + message_key = options[:message_key] + message_params = options[:message_params] + width = options[:width]||450 + + url = "#{ApplicationController.root_context}/confirm?url=#{u post_url}" + if message_key + url += "&k=#{message_key}&" + url += message_params.map{|p| "p=#{p}"}.join('&') if message_params + end + + "<a href='#{url}' modal-width='#{width}' class='open-modal button #{clazz}' #{id}>#{label}</a>" + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/confirm/_confirm.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/confirm/_confirm.html.erb new file mode 100644 index 00000000000..241ce2d0d4f --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/confirm/_confirm.html.erb @@ -0,0 +1,16 @@ +<% + message_key = params[:k] || 'are_you_sure' + message_params = params[:p] || [] +%> +<form id="form-confirm" method="post" action="<%= params[:url] -%>"> + <fieldset> + <div class="form-head"> + <img src="<%= ApplicationController.root_context -%>/images/warning.png" style="vertical-align: text-bottom"/> + <%= message(message_key, :params => message_params) -%> + </div> + <div class="form-foot"> + <input type="submit" value="Confirm"/> + <a href="#" onclick="return closeModalWindow()"><%= message('cancel') -%></a> + </div> + </fieldset> +</form>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_definitions.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_definitions.html.erb index af498ab13a9..152208a55ed 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_definitions.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_definitions.html.erb @@ -16,7 +16,7 @@ </td> <td nowrap valign="top"> Search: - <input id="filter-widget-box" name="filter-widget-box" size="10" onKeyUp="filtersWidgetsByContent(this.value);"/> + <input id="filter-widget-box" name="filter-widget-box" size="10" onKeyUp="filtersWidgetsByContent(this.value);" type="text"/> </td> </tr> </table> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb index 8ef39b808f0..e64ca8eab87 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb @@ -55,7 +55,9 @@ <% end %> <!--[if lte IE 8]><%= javascript_include_tag 'protovis-msie' -%><![endif]--> <script>var baseUrl = '<%= ApplicationController.root_context -%>'; - var $j = jQuery.noConflict();</script> + var $j = jQuery.noConflict(); + $j(document).ready(function () {$j('.open-modal').modal()}); + </script> <%= yield :script -%> </head> <body>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb index d024b747940..4364287eff6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb @@ -1,17 +1,23 @@ -<h2 class="modal-title">Rename Profile: <%= h @profile.name -%></h2> <form id="form-rename-profile" method="post" action="profiles/rename"> <input type="hidden" name="id" value="<%= @profile.id -%>"/> + <fieldset> - <% if @error %> - <p class="error"><%= h @error -%></p> - <% end %> + <div class="form-head"> + <h2>Rename Profile: <%= h @profile.name -%></h2> + </div> + <div class="form-body"> + <% if @error %> + <div class="form-field"> + <p class="error"><%= h @error -%></p> + </div> + <% end %> - <fieldset> - <div class="form-field"> - <label for="name">New name</label> - <input id="new-name" name="name" type="text"/> + <div class="form-field"> + <label for="name">New name</label> + <input id="new-name" name="name" type="text" size="50" maxlength="100"/> + </div> </div> - <div class="form-footer"> + <div class="form-foot"> <input type="submit" value="Rename"/> <a href="#" onclick="return closeModalWindow()"><%= message('cancel') -%></a> </div> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb index b69715c0791..3be4a3463c8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb @@ -1,24 +1,24 @@ <div class="line-block marginbottom10"> -<% if administrator? %> - <ul style="float: right" class="operations"> - <li> - <%= image_tag 'compare.png' -%> - <a href="<%= ApplicationController.root_context-%>/profiles/compare" id="compare-link"><%= message('quality_profiles.compare_profiles') -%></a> - </li> - <li class="last"> - <%= image_tag 'restore.gif' -%> - <a href="#" onclick="$('restore-form').show();return false;" id="restore-link"><%= message('quality_profiles.restore_profile') -%></a> - </li> - </ul> -<% end %> + <% if administrator? %> + <ul style="float: right" class="operations"> + <li> + <%= image_tag 'compare.png' -%> + <a href="<%= ApplicationController.root_context -%>/profiles/compare" id="compare-link"><%= message('quality_profiles.compare_profiles') -%></a> + </li> + <li class="last"> + <%= image_tag 'restore.gif' -%> + <a href="#" onclick="$('restore-form').show();return false;" id="restore-link"><%= message('quality_profiles.restore_profile') -%></a> + </li> + </ul> + <% end %> <h1 class="marginbottom10"><%= message('quality_profiles.page') -%></h1> </div> <% if administrator? %> -<form class="admin marginbottom10" id="restore-form" action="<%= url_for :action => 'restore' -%>" enctype="multipart/form-data" style="display: none" method="post"> + <form class="admin marginbottom10" id="restore-form" action="<%= url_for :action => 'restore' -%>" enctype="multipart/form-data" style="display: none" method="post"> <table class="spaced width100"> <tr> - <td width="1%" nowrap><%= message('backup_verb') -%>: </td> + <td width="1%" nowrap><%= message('backup_verb') -%>:</td> <td><%= file_field_tag 'backup' %></td> </tr> @@ -34,134 +34,130 @@ <% - languages.sort{|x,y| x.getName() <=> y.getName()}.each do |language| - importers=controller.java_facade.getProfileImportersForLanguage(language.getKey()) + languages.sort { |x, y| x.getName() <=> y.getName() }.each do |language| + importers=controller.java_facade.getProfileImportersForLanguage(language.getKey()) %> -<div class="line-block"> - <% if administrator? %> - <ul style="float: right" class="horizontal"> - <li class="marginleft10 add"> - <a href="#" onClick="$('create-form-<%= language.getKey() -%>').show();$('create-form-<%= language.getKey() -%>-name').focus();return false;" id="create-link-<%= language.getKey() -%>"><%= message('create') -%></a> - </li> - </ul> - <% end %> - <h2><%= message('quality_profiles.x_language_profiles', :params => language.getName()) -%></h2> -</div> + <div class="line-block"> + <% if administrator? %> + <ul style="float: right" class="horizontal"> + <li class="marginleft10 add"> + <a href="#" onClick="$('create-form-<%= language.getKey() -%>').show();$('create-form-<%= language.getKey() -%>-name').focus();return false;" id="create-link-<%= language.getKey() -%>"><%= message('create') -%></a> + </li> + </ul> + <% end %> + <h2><%= message('quality_profiles.x_language_profiles', :params => language.getName()) -%></h2> + </div> -<% if administrator? %> - <form class="admin" id="create-form-<%= language.getKey()-%>" action="<%= url_for :action => 'create' -%>" style="display: none" enctype="multipart/form-data" method="post"> - <input type="hidden" name="language" value="<%= language.getKey() -%>"/> - <table class="spaced width100"> - <tr> - <td width="1%" nowrap><%= message('name') -%>: </td> - <td><input type="text" name="name" id="create-form-<%= language.getKey()-%>-name"/></td> - </tr> - <% importers.to_a.sort{|x,y| x.getName() <=> y.getName()}.each do |importer| %> - <tr> - <td width="1%" nowrap><%= importer.getName() -%>: </td> - <td> - <%= file_field_tag "backup[#{importer.getKey()}]" %> - <span class="note"><%= message('quality_profiles.optional_configuration_file') -%></span> - </td> - </tr> - <% end %> + <% if administrator? %> + <form class="admin" id="create-form-<%= language.getKey() -%>" action="<%= url_for :action => 'create' -%>" style="display: none" enctype="multipart/form-data" method="post"> + <input type="hidden" name="language" value="<%= language.getKey() -%>"/> + <table class="spaced width100"> + <tr> + <td width="1%" nowrap><%= message('name') -%>:</td> + <td><input type="text" name="name" id="create-form-<%= language.getKey() -%>-name"/></td> + </tr> + <% importers.to_a.sort { |x, y| x.getName() <=> y.getName() }.each do |importer| %> + <tr> + <td width="1%" nowrap><%= importer.getName() -%>:</td> + <td> + <%= file_field_tag "backup[#{importer.getKey()}]" %> + <span class="note"><%= message('quality_profiles.optional_configuration_file') -%></span> + </td> + </tr> + <% end %> - <tr> - <td colspan="2"> - <input type="submit" value="<%= message('quality_profiles.create_x_language_profile', :params => language.getName()) -%>" id="create-submit-<%= language.getKey() -%>"/> - <a href="#" onclick="$('create-form-<%= language.getKey()-%>').reset();$('create-form-<%= language.getKey()-%>').hide();return false;"><%= message('cancel') -%></a> - </td> - </tr> - </table> - </form> -<% end %> + <tr> + <td colspan="2"> + <input type="submit" value="<%= message('quality_profiles.create_x_language_profile', :params => language.getName()) -%>" id="create-submit-<%= language.getKey() -%>"/> + <a href="#" onclick="$('create-form-<%= language.getKey()-%>').reset();$('create-form-<%= language.getKey()-%>').hide();return false;"><%= message('cancel') -%></a> + </td> + </tr> + </table> + </form> + <% end %> -<table class="data width100" id="profiles_<%= language.getKey() -%>"> + <table class="data width100" id="profiles_<%= language.getKey() -%>"> <thead> - <tr> - <th class="left"><%= message('name') -%></th> - <th class="right"><%= message('rules') -%></th> - <th class="right"><%= message('alerts') -%></th> - <th class="right"><%= message('projects') -%></th> - <th class="right"><%= message('default') -%></th> - <% if administrator? %> + <tr> + <th class="left"><%= message('name') -%></th> + <th class="right"><%= message('rules') -%></th> + <th class="right"><%= message('alerts') -%></th> + <th class="right"><%= message('projects') -%></th> + <th class="right"><%= message('default') -%></th> + <% if administrator? %> <th width="1%" class="right" colspan="4"><%= message('operations') -%></th> - <% end %> - </tr> + <% end %> + </tr> </thead> <tbody> - <% @profiles.select{|p| p.language==language.getKey()}.each do |profile| %> - <tr class="<%= cycle 'even', 'odd', :name => language.getKey() -%>" id="<%= u profile.key %>"> - <td><a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id -%>" id="rules-<%= language.getKey() -%>-<%= u(profile.name) -%>"><%= h profile.name %></a></td> - - <td align="right"> - <span id="activated_rules_<%= u profile.key -%>"><%= profile.count_active_rules -%></span> - </td> - - <td align="right"><span id="alerts_<%= u profile.key -%>"><%= profile.alerts.size -%></span></td> - - <td align="right"> - <% unless profile.default_profile? %> - <span id="projects_<%= u profile.key -%>"><%= profile.projects.size -%></span> - <% end %> - </td> - - <td align="right"> - <% if (!profile.default_profile? && administrator?) %> - <%= button_to message('set_as_default'), { :action => 'set_as_default', :id => profile.id }, :class => 'action', - :id => "activate_#{u profile.key}", - :confirm => message('quality_profiles.are_you_sure_want_x_profile_as_default', :params => profile.name), - :method => :post %> - <% end %> - <% if profile.default_profile? %> - <%= image_tag 'tick.png', :id => "is_active_#{u profile.key}" %> - <% end %> - </td> + <% @profiles.select { |p| p.language==language.getKey() }.each do |profile| %> + <tr class="<%= cycle 'even', 'odd', :name => language.getKey() -%>" id="<%= u profile.key %>"> + <td> + <a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id -%>" id="rules-<%= language.getKey() -%>-<%= u(profile.name) -%>"><%= h profile.name %></a> + </td> + <td align="right"> + <span id="activated_rules_<%= u profile.key -%>"><%= profile.count_active_rules -%></span> + </td> - <% if administrator? %> + <td align="right"><span id="alerts_<%= u profile.key -%>"><%= profile.alerts.size -%></span></td> - <td align="right"> - <% if !profile.provided? %> - <% form_tag(:action => 'backup', :id => profile.id) do -%> - <input type="submit" name="button_backup" id="backup_<%= u profile.key %>" value="<%= message('backup_verb') -%>"/> - <% end - end %> + <td align="right"> + <% unless profile.default_profile? %> + <span id="projects_<%= u profile.key -%>"><%= profile.projects.size -%></span> + <% end %> </td> <td align="right"> - <% if !profile.provided? %> - <a id="rename-<%= profile.key.parameterize -%>" href="<%= ApplicationController.root_context -%>/profiles/rename_form?id=<%= profile.id -%>" class="button open-modal"><%= message('rename') -%></a> + <% if (!profile.default_profile? && administrator?) %> + <%= button_to message('set_as_default'), {:action => 'set_as_default', :id => profile.id}, :class => 'action', + :id => "activate_#{u profile.key}", + :confirm => message('quality_profiles.are_you_sure_want_x_profile_as_default', :params => profile.name), + :method => :post %> + <% end %> + <% if profile.default_profile? %> + <%= image_tag 'tick.png', :id => "is_active_#{u profile.key}" %> <% end %> </td> - <td align="right"> - <% form_tag(:action => 'copy', :id => profile.id) do -%> + + <% if administrator? %> + + <td align="right"> + <% if !profile.provided? %> + <% form_tag(:action => 'backup', :id => profile.id) do -%> + <input type="submit" name="button_backup" id="backup_<%= u profile.key %>" value="<%= message('backup_verb') -%>"/> + <% end + end %> + </td> + + <td align="right"> + <% if !profile.provided? %> + <a id="rename-<%= profile.key.parameterize -%>" href="profiles/rename_form?id=<%= profile.id -%>" class="button open-modal"><%= message('rename') -%></a> + <% end %> + </td> + + <td align="right"> + <% form_tag(:action => 'copy', :id => profile.id) do -%> <%= hidden_field_tag 'copy_' + profile.id.to_s %> <input type="button" name="button_copy" id="copy_<%= u profile.key %>" value="<%= message('copy') -%>" onClick='var name=prompt("<%= message('quality_profiles.name_for_new_profile') -%>"); if (name!=null) {$("copy_<%= profile.id %>").value=name; submit();} else {return false;}'> <% end %> - </td> + </td> - <td> + <td> <% if profile.deletable? %> - <%= button_to message('delete'), { :action => 'delete', :id => profile.id }, :class => 'action red-button', - :id => "delete_#{u profile.key}", - :confirm => message('quality_profiles.are_you_sure_want_delete_profile_x', :params => profile.name), - :method => :post %> - <% end %> - </td> - <% end %> - </tr> + <%= button_to_action message('delete'), "profiles/delete/#{profile.id}", + :class => 'red-button', + :id => "delete_#{profile.key.parameterize}", + :message_key => 'quality_profiles.are_you_sure_want_delete_profile_x', + :message_params => [profile.name] + -%> + <% end %> + </td> + <% end %> + </tr> <% end %> </tbody> -</table> -<br/><br/> -<% end %> - -<% content_for :script do %> -<script> - $j(document).ready(function () { - $j('.open-modal').modal(); - }); -</script> -<% end %> + </table> + <br/><br/> +<% end %>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index 5fcbff6a86f..50ae86c1269 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -261,32 +261,24 @@ Treemap.prototype.onLoaded = function (componentsSize) { (function ($j) { $j.fn.extend({ - modal:function (options) { - var defaults = { - width:540, - urlAttr:'href' - }; - var options = $j.extend(defaults, options); - + modal:function () { return this.each(function () { - var o = options; var obj = $j(this); var $link = obj.bind('click', function () { if ($j('#modal').length) { return; // another window is already opening } var $dialog = $j('<div id="modal"></div>').appendTo('body'); - $j.get($link.attr(o.urlAttr), {}, function (html) { + $j.get($link.attr('href'), {}, function (html) { $dialog.html(html); $dialog .dialog({ - width:o.width, + width:($link.attr('modal-width')||540), draggable:false, autoOpen:false, modal:true, minHeight: 50, resizable:false, - dialogClass:o.dialogClass, close: function() { $j('#modal').remove(); } @@ -294,7 +286,6 @@ Treemap.prototype.onLoaded = function (componentsSize) { $dialog.dialog("open"); }); - $link.click(function () { $dialog.dialog('open'); return false; diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 565a81f3bfb..5d9dfa29c0c 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -2347,13 +2347,17 @@ select.medium-width { //vertical-align: baseline; } -.modal-title { - border-bottom: 1px solid #ccc; - padding: 0.5em; +.form-head { + padding: 0 10px; background-color: #EFEFEF; + line-height: 30px; + height: 30px; +} +.form-body { + border-top: 1px solid #ccc; } .form-field { - padding: 5px; + padding: 5px 10px; } .form-field label:before { content: ""; @@ -2366,12 +2370,14 @@ select.medium-width { line-height: 1; padding: 5px 5px 0 0; } -.form-footer { +.form-foot { text-align: right; - padding: 4px 10px; + padding: 0 10px; border-top: 1px solid #CCC; + line-height: 30px; + height: 30px; } -.form-footer input { +.form-foot input { margin-right: 10px; } input[type=text],input[type=password] { |