summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-09-23 14:36:37 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-09-23 14:36:37 +0200
commitdda87de17a39c55ad6e1817aa8f492cb01554efb (patch)
tree9f49a55c370543f8635a52787ef1e45834e9cb6f
parent979787042b3377fc173ebc2e4739d907d2b2b1f6 (diff)
downloadsonarqube-dda87de17a39c55ad6e1817aa8f492cb01554efb.tar.gz
sonarqube-dda87de17a39c55ad6e1817aa8f492cb01554efb.zip
SONAR-3263 add JS API for the forms opened in modal windows
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb20
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/confirm/_confirm.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb13
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb7
-rw-r--r--sonar-server/src/main/webapp/javascripts/application.js52
7 files changed, 81 insertions, 42 deletions
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
"<a href='#{url}' modal-width='#{width}' class='open-modal button #{clazz}' #{id}>#{label}</a>"
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 @@
<fieldset>
<div class="form-head">
<img src="<%= ApplicationController.root_context -%>/images/warning.png" style="vertical-align: text-bottom"/>
- <%= message(message_key, :params => message_params) -%>
+ <%= h message(message_key, :params => message_params) -%>
</div>
<div class="form-foot">
<input type="submit" value="Confirm"/>
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 @@
+<form id="form-copy-profile" method="post" action="profiles/copy">
+ <input type="hidden" name="id" value="<%= @profile.id -%>"/>
+ <fieldset>
+ <div class="form-head">
+ <h2>Copy Profile: <%= h @profile.name -%></h2>
+ </div>
+ <div class="form-body">
+ <% if @error %>
+ <div class="form-field">
+ <p class="error"><%= h @error -%></p>
+ </div>
+ <% end %>
+ <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-foot">
+ <input type="submit" value="Copy"/>
+ <a href="#" onclick="return closeModalWindow()"><%= message('cancel') -%></a>
+ </div>
+ </fieldset>
+</form>
+<script>
+ $j("#form-copy-profile").modalForm();
+ $j('#new-name').focus();
+</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 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 @@
</fieldset>
</form>
<script>
+ $j("#form-rename-profile").modalForm();
$j('#new-name').focus();
- $j("#form-rename-profile").submit(function (event) {
- $j('input[type=submit]', this).attr('disabled', 'disabled');
- $j.ajax({type:"POST", data:$j(this).serialize(), url:$j(this).attr('action'),
- success:function (data) {
- location.reload();
- },
- error:function (xhr, textStatus, errorThrown) {
- $j("#modal").html(xhr.responseText);
- }
- });
- return false;
- });
</script> \ 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 @@
<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>
+ <a id="rename-<%= profile.key.parameterize -%>" href="profiles/rename_form/<%= 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 %>
+ <a id="copy-<%= profile.key.parameterize -%>" href="profiles/copy_form/<%= profile.id -%>" class="button open-modal"><%= message('copy') -%></a>
</td>
<td>
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");
});
@@ -294,6 +294,26 @@ Treemap.prototype.onLoaded = function (componentsSize) {
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;
+ });
+ });
}
});
})(jQuery);