From 9a4fbc1ef8507856ad24ca7218d1819a27dd2b1d Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 22 Sep 2012 00:44:30 +0200 Subject: [PATCH] SONAR-3623 support confirmation popups --- .../app/controllers/confirm_controller.rb | 27 ++ .../app/controllers/profiles_controller.rb | 3 +- .../WEB-INF/app/helpers/application_helper.rb | 25 ++ .../app/views/confirm/_confirm.html.erb | 16 ++ .../dashboard/_widget_definitions.html.erb | 2 +- .../WEB-INF/app/views/layouts/_head.html.erb | 4 +- .../app/views/profiles/_rename_form.html.erb | 24 +- .../WEB-INF/app/views/profiles/index.html.erb | 238 +++++++++--------- .../main/webapp/javascripts/application.js | 15 +- .../src/main/webapp/stylesheets/style.css | 20 +- 10 files changed, 221 insertions(+), 153 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/controllers/confirm_controller.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/confirm/_confirm.html.erb 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=&[t= '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}" end + + # + # Creates a button linked to a POST action. A confirmation popup is opened when user clicks on the button. + # ==== Options + # * :id - HTML ID of the button + # * :class - Additional CSS class, generally 'red-button' for deletions + # * :message_key - + # * :message_params - + # * :width - 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 + + "#{label}" + 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] || [] +%> +
+
+
+ + <%= message(message_key, :params => message_params) -%> +
+ +
+
\ 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 @@ Search: - + 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 %> + var $j = jQuery.noConflict(); + $j(document).ready(function () {$j('.open-modal').modal()}); + <%= yield :script -%> \ 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 @@ -
+
- <% if @error %> -

<%= h @error -%>

- <% end %> +
+

Rename Profile: <%= h @profile.name -%>

+
+
+ <% if @error %> +
+

<%= h @error -%>

+
+ <% end %> -
-
- - +
+ + +
-