]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4971 Use modal window instead of browser popup in the project deletion page
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Apr 2014 13:03:35 +0000 (15:03 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Apr 2014 13:03:48 +0000 (15:03 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/project/_delete_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb

index 8da6b853e676c560f1efee6f01bbc68f6edb6b63..689d3cc57cee1b1b308a0cf29c366c2eb3fa3a73 100644 (file)
@@ -28,13 +28,31 @@ class ProjectController < ApplicationController
     redirect_to :overwrite_params => {:controller => :dashboard, :action => 'index'}
   end
 
+  def delete_form
+    access_denied unless (is_admin?(@project))
+    @project = get_current_project(params[:id])
+    render :partial => 'delete_form'
+  end
+
+  def delete
+    access_denied unless (is_admin?(@project))
+    @project = get_current_project(params[:id])
+
+    # Ask the resource deletion manager to start the migration
+    # => this is an asynchronous AJAX call
+    ResourceDeletionManager.instance.delete_resources([@project.id])
+
+    # and return some text that will actually never be displayed
+    render :text => ResourceDeletionManager.instance.message
+  end
+
   def deletion
     @project = get_current_project(params[:id])
 
     if java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'deletable')
       deletion_manager = ResourceDeletionManager.instance
       if deletion_manager.currently_deleting_resources? ||
-        (!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
+          (!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
         # a deletion is happening or it has just finished with errors => display the message from the Resource Deletion Manager
         render :template => 'project/pending_deletion'
       else
@@ -45,17 +63,6 @@ class ProjectController < ApplicationController
     end
   end
 
-  def delete
-    @project = get_current_project(params[:id])
-
-    # Ask the resource deletion manager to start the migration
-    # => this is an asynchronous AJAX call
-    ResourceDeletionManager.instance.delete_resources([@project.id])
-
-    # and return some text that will actually never be displayed
-    render :text => ResourceDeletionManager.instance.message
-  end
-
   def pending_deletion
     deletion_manager = ResourceDeletionManager.instance
 
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_delete_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_delete_form.html.erb
new file mode 100644 (file)
index 0000000..6bde157
--- /dev/null
@@ -0,0 +1,37 @@
+<% resource_qualifier = message('qualifier.' + @project.qualifier) %>
+<form id="delete-project-form" method="post" action="<%= ApplicationController.root_context -%>/project/delete">
+  <fieldset>
+    <div class="modal-head">
+      <h2><%= message('project_deletion.page', :params => resource_qualifier) -%></h2>
+    </div>
+    <div class="modal-body">
+      <div class="info">
+        <img src="<%= ApplicationController.root_context -%>/images/information.png" style="vertical-align: text-bottom"/>
+        <%= message('project_deletion.delete_resource_confirmation', :params => resource_qualifier) %>
+      </div>
+    </div>
+    <div class="modal-foot">
+      <span id="delete-project-loading-image" class="loading-image hidden"><%= image_tag 'loading.gif' %></span>
+      <input type="submit" value="<%= message('delete') -%>" id="delete-project-submit" onclick="return displayLoadingImage()"/>
+      <a href="#" onclick="return closeModalWindow()" id="delete-project-cancel"><%= message('cancel') -%></a>
+    </div>
+  </fieldset>
+</form>
+<script>
+  $j("#delete-project-form").modalForm({
+    success: function () {
+      $j.ajax({
+        url: "<%= ApplicationController.root_context-%>/project/delete/<%= h(@project.id) -%>",
+        success: function (request) {
+          window.location = '<%= url_for(:action => 'pending_deletion',:id => @project.id)-%>';
+        },
+        data: $j(this).serialize(),
+        type: 'delete'
+      });
+    }
+  });
+
+  function displayLoadingImage() {
+    $j('#delete-project-loading-image').removeClass("hidden");
+  }
+</script>
index fb694f6e3767fed9ba775c65386bef6d3543ae7f..a5c399ebbf94e9e77e812a940d1afe5b27a7e411 100644 (file)
@@ -1,31 +1,15 @@
 <%
-  if !@snapshot || @snapshot.root?
-    resource_qualifier = message('qualifier.' + @project.qualifier)
-    delete_resource_message = message('project_deletion.page', :params => resource_qualifier)
+   if !@snapshot || @snapshot.root?
+     resource_qualifier = message('qualifier.' + @project.qualifier)
+     delete_resource_message = message('project_deletion.page', :params => resource_qualifier)
 %>
-<h1 class="admin-page-title"><%= delete_resource_message -%></h1>
-<p class="admin-page-description"><%= message('project_deletion.page.description') -%></p>
-<br/>
-<div class="yui-g widget" id="widget_delete_project">
-  <div class="warning">
-      <form    onsubmit="
-                  $j.ajax({
-                            url:'<%= url_for(:action => 'delete',:id => @project.id)-%>',
-                            success:function(request)  {
-                                        window.location='<%= url_for(:action => 'pending_deletion',:id => @project.id)-%>';
-                                                      },
-                            data:$j(this).serialize(),
-                            type:'delete'
-                          });
-                  return false;"
-             method="delete"
-             action="<%= url_for(:action => 'delete',:id => @project.id)-%>">
-
-    <%= message('project_deletion.operation_cannot_be_undone') -%>
-    <br/>
-    <%= submit_tag delete_resource_message, :id => 'delete_resource', :class => 'action red-button',
-                   :confirm => message('project_deletion.delete_resource_confirmation', :params => resource_qualifier) %>
-    </form>
+  <h1 class="admin-page-title"><%= delete_resource_message -%></h1>
+  <p class="admin-page-description"><%= message('project_deletion.page.description') -%></p>
+  <div class="yui-g widget" id="widget_delete_project">
+    <div class="warning">
+      <%= message('project_deletion.operation_cannot_be_undone') -%><br/>
+      <a id="delete_resource" class="open-modal button button-red"
+         href="<%= ApplicationController.root_context -%>/project/delete_form/<%= h(@project.id) -%>"><%= delete_resource_message -%></a>
+    </div>
   </div>
-</div>
 <% end %>