From dda87de17a39c55ad6e1817aa8f492cb01554efb Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 23 Sep 2012 14:36:37 +0200 Subject: [PATCH] SONAR-3263 add JS API for the forms opened in modal windows --- .../app/controllers/profiles_controller.rb | 20 ++++--- .../WEB-INF/app/helpers/application_helper.rb | 2 +- .../app/views/confirm/_confirm.html.erb | 2 +- .../app/views/profiles/_copy_form.html.erb | 27 ++++++++++ .../app/views/profiles/_rename_form.html.erb | 13 +---- .../WEB-INF/app/views/profiles/index.html.erb | 7 +-- .../main/webapp/javascripts/application.js | 52 +++++++++++++------ 7 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb 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 8cde294ce38..2e41cc0eab8 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 @@ -113,6 +113,10 @@ class ProfilesController < ApplicationController end + def copy_form + @profile = Profile.find(params[:id]) + render :partial => 'profiles/copy_form' + end # # @@ -120,18 +124,20 @@ class ProfilesController < ApplicationController # # def copy - profile = Profile.find(params[:id]) - name = params['copy_' + profile.id.to_s] + render :text => 'Not an ajax request', :status => '400' unless request.xhr? - validation_errors = profile.validate_copy(name) + @profile = Profile.find(params[:id]) + name = params['name'] + + validation_errors = @profile.validate_copy(name) if validation_errors.empty? - java_facade.copyProfile(profile.id, name) + java_facade.copyProfile(@profile.id, name) flash[:notice]= message('quality_profiles.profile_x_not_activated', :params => name) + render :text => 'ok', :status => 200 else - flash[:error] = validation_errors.full_messages.first + @error = validation_errors.full_messages.first + render :partial => 'profiles/copy_form', :status => 400 end - - redirect_to :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 dce4ccbea67..ad2aa501ad8 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 @@ -739,7 +739,7 @@ module ApplicationHelper 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 + url += message_params.map{|p| "p=#{u p}"}.join('&') if message_params end "#{label}" 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 index 241ce2d0d4f..dceb6db2f4a 100644 --- 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 @@ -6,7 +6,7 @@
- <%= message(message_key, :params => message_params) -%> + <%= h message(message_key, :params => message_params) -%>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb new file mode 100644 index 00000000000..13c26d3096c --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb @@ -0,0 +1,27 @@ +
+ +
+
+

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

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

<%= h @error -%>

+
+ <% end %> +
+ + +
+
+ +
+
+ \ 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 4364287eff6..6026b876a27 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 @@ -24,17 +24,6 @@
\ No newline at end of file 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 f4bd608413a..fd31c1266d7 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 @@ -133,15 +133,12 @@ <% if !profile.provided? %> - <%= message('rename') -%> + <%= message('rename') -%> <% end %> - <% form_tag(:action => 'copy', :id => profile.id) do -%> - <%= hidden_field_tag 'copy_' + profile.id.to_s %> - "); if (name!=null) {$("copy_<%= profile.id %>").value=name; submit();} else {return false;}'> - <% end %> + <%= message('copy') -%> diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index 50ae86c1269..a4a1ac077fa 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -215,11 +215,11 @@ Treemap.prototype.load = function () { } new Ajax.Request( - baseUrl + '/treemap/index?id=' + this.id + '&width=' + width + '&height=' + height + '&size_metric=' + this.sizeMetric + '&color_metric=' + this.colorMetric + '&' + context.type + '=' + context.id, - { - asynchronous:true, - evalScripts:true - }); + baseUrl + '/treemap/index?id=' + this.id + '&width=' + width + '&height=' + height + '&size_metric=' + this.sizeMetric + '&color_metric=' + this.colorMetric + '&' + context.type + '=' + context.id, + { + asynchronous:true, + evalScripts:true + }); }; Treemap.prototype.htmlNode = function (nodeId) { return $('tm-node-' + this.id + '-' + nodeId); @@ -272,17 +272,17 @@ Treemap.prototype.onLoaded = function (componentsSize) { $j.get($link.attr('href'), {}, function (html) { $dialog.html(html); $dialog - .dialog({ - width:($link.attr('modal-width')||540), - draggable:false, - autoOpen:false, - modal:true, - minHeight: 50, - resizable:false, - close: function() { - $j('#modal').remove(); - } - }); + .dialog({ + width:($link.attr('modal-width') || 540), + draggable:false, + autoOpen:false, + modal:true, + minHeight:50, + resizable:false, + close:function () { + $j('#modal').remove(); + } + }); $dialog.dialog("open"); }); @@ -291,6 +291,26 @@ Treemap.prototype.onLoaded = function (componentsSize) { return false; }); + return false; + }); + }); + }, + modalForm:function () { + return this.each(function () { + var obj = $j(this); + obj.submit(function (event) { + $j('input[type=submit]', this).attr('disabled', 'disabled'); + $j.ajax({ + type:'POST', + url:obj.attr('action'), + data:obj.serialize(), + success:function (data) { + location.reload(); + }, + error:function (xhr, textStatus, errorThrown) { + $j("#modal").html(xhr.responseText); + } + }); return false; }); }); -- 2.39.5