]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3623 use modal windows for renaming Q profiles
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 21 Sep 2012 16:20:35 +0000 (18:20 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 21 Sep 2012 16:20:35 +0000 (18:20 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb
sonar-server/src/main/webapp/javascripts/application.js
sonar-server/src/main/webapp/stylesheets/jquery-ui.css
sonar-server/src/main/webapp/stylesheets/layout.css
sonar-server/src/main/webapp/stylesheets/style.css

index 061183c3b846a0509a762c03d168a96bc1242340..f4dce0e9777a59c014355d48c6291eae1a248200 100644 (file)
@@ -298,27 +298,41 @@ class ProfilesController < ApplicationController
   end
 
 
+  # GET /profiles/rename_form?id=<id>
+  def rename_form
+    @profile = Profile.find(params[:id])
+    render :partial => 'profiles/rename_form'
+  end
 
   #
   #
-  # POST /profiles/rename/<id>?name=<new name>
+  # POST /profiles/rename?id=<id>&name=<new name>
   #
   #
   def rename
-    profile = Profile.find(params[:id])
-    name = params['rename_' + profile.id.to_s]
+    render :text => 'Not an ajax request', :status => '400' unless request.xhr?
+
+    @profile = Profile.find(params[:id])
+    name = params[:name]
 
+    success=false
     if name.blank?
-      flash[:warning]=message('quality_profiles.profile_name_cant_be_blank')
+      @error=message('quality_profiles.profile_name_cant_be_blank')
     else
-      existing=Profile.find(:first, :conditions => {:name => name, :language => profile.language, :enabled => true})
+      existing=Profile.find(:first, :conditions => {:name => name, :language => @profile.language, :enabled => true})
       if existing
-        flash[:warning]=message('quality_profiles.profile_name_already_exists')
-      elsif !profile.provided?
-        java_facade.renameProfile(profile.id, name)
+        @error=message('quality_profiles.profile_name_already_exists')
+      elsif !@profile.provided?
+        java_facade.renameProfile(@profile.id, name)
+        success=true
       end
     end
-    redirect_to :action => 'index'
+
+    if success
+      render :text => 'ok', :status => 200
+    else
+      render :partial => 'profiles/rename_form', :status => 400
+    end
   end
 
 
index a17ff125ff948c9e75bc0da91aaca06b55021baf..c2f6ada98e35aafb26e01483fb05f62c0008043b 100644 (file)
@@ -46,5 +46,5 @@
 <%= javascript_include_tag 'resource' %>
 <% end %>
 <!--[if lte IE 8]><%= javascript_include_tag 'protovis-msie' -%><![endif]-->
-<script>var baseUrl = '<%= ApplicationController.root_context -%>';var $j = jQuery.noConflict();</script>
+<script>var baseUrl = '<%= ApplicationController.root_context -%>';var $j = jQuery.noConflict();<%= yield :javascript_header -%></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
new file mode 100644 (file)
index 0000000..f643152
--- /dev/null
@@ -0,0 +1,38 @@
+<h2 class="modal-title" xmlns="http://www.w3.org/1999/html">Rename Profile</h2>
+<form id="form-rename-profile" method="post" action="profiles/rename">
+  <input type="hidden" name="id" value="<%= @profile.id -%>"/>
+
+  <% if @error %>
+    <p class="error"><%= h @error -%></p>
+  <% end %>
+
+  <fieldset>
+    <div class="form-field">
+      <label for="">Old name</label>
+      <input type="text" disabled="disabled" value="<%= h @profile.name -%>"/>
+    </div>
+    <div class="form-field">
+      <label for="name">New name</label>
+      <input id="new-name" name="name" type="text"/>
+    </div>
+    <div class="form-footer">
+      <input type="submit" value="Rename"/>
+      <a href="#" onclick="return closeModalWindow()"><%= message('cancel') -%></a>
+    </div>
+  </fieldset>
+</form>
+<script>
+  $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
index 87df20e4c2b404c00673ae67625b1d8cfe6ab507..e1e8e3bd93e176c6243af0d2f63324d9b0e20353 100644 (file)
         </td>
 
         <td align="right">
-          <% if !(profile.provided?) %>
-             <% form_tag(:action => 'rename', :id => profile.id) do -%>
-              <%= hidden_field_tag 'rename_' + profile.id.to_s %>
-              <input type="button" name="button_rename" id="rename_<%= u profile.key %>" value="<%= message('rename') -%>" onClick='var name=prompt("<%= message('quality_profiles.new_name') -%>", "<%= profile.name -%>"); if (name!=null) {$("rename_<%= profile.id %>").value=name; submit();} else {return false;}'>
-            <% end
-            end %>
+          <% 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>
+          <% end %>
         </td>
 
         <td align="right">
                         :method => :post %>
           <% end %>
         </td>
-
       <% end %>
     </tr>
     <% end %>
 </table>
 <br/><br/>
 <% end %>
+
+<% content_for :javascript_header do %>
+  $j(document).ready(function () {
+    $j('.open-modal').modal();
+  });
+<% end %>
index ffcd14ce03f09e8382254caabfa5f218487220da..5fcbff6a86fb8e7c07105017914d1c52d33e3f20 100644 (file)
@@ -284,13 +284,9 @@ Treemap.prototype.onLoaded = function (componentsSize) {
                 draggable:false,
                 autoOpen:false,
                 modal:true,
+                minHeight: 50,
                 resizable:false,
                 dialogClass:o.dialogClass,
-                open:function (event,ui) {
-                  $j('.ui-widget-overlay').bind('click', function () {
-                    $j('#modal').dialog('close');
-                  })
-                },
                 close: function() {
                   $j('#modal').remove();
                 }
@@ -306,8 +302,6 @@ Treemap.prototype.onLoaded = function (componentsSize) {
 
           return false;
         });
-
-
       });
     }
   });
@@ -315,4 +309,5 @@ Treemap.prototype.onLoaded = function (componentsSize) {
 
 function closeModalWindow() {
   $j('#modal').dialog('close');
+  return false;
 }
\ No newline at end of file
index e17356e0599166d576ee8206f9671dbec5af30ea..2f131a68a02396e86eea9aebc1585c3df6bf7069 100755 (executable)
 .ui-helper-clearfix { zoom: 1; }
 .ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); }
 .ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%;background: none repeat scroll 0 0 rgba(0, 0, 0, 0.5) }
-.ui-widget { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1.1em; }
 .ui-widget .ui-widget { font-size: 1em; }
-.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1em; }
 .ui-widget-content { border: 1px solid #dddddd; background: #eeeeee 50% top repeat-x; color: #333333; }
 .ui-widget-content a { color: #333333; }
 .ui-widget-header { border: 1px solid #e78f08; background: #f6a828 50% 50% repeat-x; color: #ffffff; font-weight: bold; }
 .ui-widget-header a { color: #ffffff; }
 .ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }
-.ui-dialog { position: absolute; padding: .2em; width: 300px; overflow: hidden; box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.5);background-color: #FFF}
+.ui-dialog { position: absolute; width: 300px; overflow: hidden; box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.5);background-color: #FFF}
 .ui-dialog .ui-dialog-titlebar { display:none }
-.ui-dialog .ui-dialog-content { position: relative; border: 0; padding: .5em 1em; background: none; overflow: auto; zoom: 1; }
\ No newline at end of file
+.ui-dialog .ui-dialog-content { position: relative; border: 0; background: none; overflow: auto; zoom: 1; }
\ No newline at end of file
index 7dd4a87c4186751c015245c6385167816a0ba757..b6410c2ba6d651a5aef26b0270dbb280d2d52b71 100644 (file)
@@ -250,3 +250,7 @@ body, a {
 .nolayout {
   padding: 10px;
 }
+
+#modal {
+  display: none;
+}
\ No newline at end of file
index 7b6ab514660ebaef501a737462b119441a2bfdd4..fa9cf6cb609e33209365d0b1c47873c98748d919 100644 (file)
@@ -1,6 +1,5 @@
 /* CSS optimized by http://www.cleancss.com */
 
-
 /* ------------------- PROJECTS SEARCH FORM ------------------- */
 #projectSearch {
   color: #444;
@@ -19,6 +18,7 @@
   padding: 4px 0;
   margin-top: 10px;
 }
+
 .ie6-warn {
   color: #EEE;
   background: #FF5252;
@@ -975,6 +975,7 @@ table.reviewDetails td img {
 .discussionComment li {
   list-style: square inside;
 }
+
 .discussionComment pre {
   padding: 10px;
   border: 1px dashed #DDD;
@@ -2274,13 +2275,13 @@ td.spacer-top {
   padding: 4px 5px;
   vertical-align: top;
 }
+
 .table > tfoot > tr > td {
   font-size: 93%;
   color: #777;
   padding: 4px 5px;
 }
 
-
 .table-bordered > tbody {
   border-left: 1px solid #DDD;
   border-right: 1px solid #DDD;
@@ -2345,3 +2346,34 @@ select.medium-width {
 #dependencies .colbody > div > img {
   //vertical-align: baseline;
 }
+
+.modal-title {
+  border-bottom: 1px solid #ccc;
+  padding: 0.5em;
+  background-color: #EFEFEF;
+}
+.form-field {
+  padding: 5px;
+}
+.form-field label:before {
+  content: "";
+}
+.form-field label {
+  display: block;
+  text-align: right;
+  width: 120px;
+  float: left;
+  line-height: 1;
+  padding: 5px 5px 0 0;
+}
+.form-footer {
+  text-align: right;
+  padding: 0.5em;
+  border-top: 1px solid #CCC;
+}
+.form-footer input {
+  margin-right: 10px;
+}
+input[type=text] {
+  height: 20px;
+}