Use AJAX/remote requests when deleting objects. Add delete button to
authorTom Clegg <tom@curoverse.com>
Mon, 3 Feb 2014 08:21:52 +0000 (00:21 -0800)
committerTom Clegg <tom@curoverse.com>
Mon, 3 Feb 2014 08:21:52 +0000 (00:21 -0800)
pipeline_instances index.

refs #1976

apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/views/application/_index.html.erb
apps/workbench/app/views/application/destroy.js.erb [new file with mode: 0644]
apps/workbench/app/views/pipeline_instances/index.html.erb

index 21941b266e6f13780da1e2ad4ad0d5e1b5a54826..6b9b6fcd7e5c96cc7c6064f5c2c9e6c2fe989771 100644 (file)
@@ -112,7 +112,12 @@ class ApplicationController < ActionController::Base
 
   def destroy
     if @object.destroy
-      redirect_to(params[:return_to] || :back)
+      respond_to do |f|
+        f.html {
+          redirect_to(params[:return_to] || :back)
+        }
+        f.js { render }
+      end
     else
       self.render_error status: 422
     end
index 02a1aa1a36be143a0e1c4472977eb3b62fd6be96..64b94c8a28ea14861c0dbe965210bb86c351b1ad 100644 (file)
@@ -31,7 +31,7 @@
       
   <tbody>
     <% @objects.each do |object| %>
-    <tr>
+    <tr data-object-uuid="<%= object.uuid %>">
       <% object.attributes_for_display.each do |attr, attrvalue| %>
       <% next if attr_blacklist.index(" "+attr) %>
       <td class="arv-object-<%= object.class.to_s %> arv-attr-<%= attr %>">
@@ -51,9 +51,8 @@
       <% end %>
       <td>
         <% if object.editable? %>
-        <%= link_to({action: 'destroy', id: object.uuid}, method: :delete, data: {confirm: "You are about to delete #{controller.model_class} #{object.uuid}.\n\nAre you sure?"}) do %>
+        <%= link_to({action: 'destroy', id: object.uuid}, method: :delete, remote: true, data: {confirm: "You are about to delete #{controller.model_class} #{object.uuid}.\n\nAre you sure?"}) do %>
         <i class="icon-trash"></i>
-        <!-- <%= object.inspect %> -->
         <% end %>
         <% end %>
       </td>
diff --git a/apps/workbench/app/views/application/destroy.js.erb b/apps/workbench/app/views/application/destroy.js.erb
new file mode 100644 (file)
index 0000000..05b2c3e
--- /dev/null
@@ -0,0 +1,3 @@
+$('[data-object-uuid=<%= @object.uuid %>]').hide('slow', function() {
+    $(this).remove();
+});
index 2789ca113badb96d2b33d1d84369be4420c28f4e..ad941daf5da8e33dd8f9a4cea8b8177c79f2da43 100644 (file)
@@ -21,6 +21,7 @@
        dependencies
       </th><th>
        created
+      </th><th>
       </th>
     </tr>
   </thead>
@@ -28,7 +29,7 @@
 
     <% @objects.sort_by { |ob| ob.created_at }.reverse.each do |ob| %>
 
-    <tr>
+    <tr data-object-uuid="<%= ob.uuid %>">
       <td>
         <%= check_box_tag 'uuids[]', ob.uuid, false %>
       </td><td>
         </small>
       </td><td>
         <%= ob.created_at %>
+      </td><td>
+        <% if ob.editable? %>
+        <%= link_to({action: 'destroy', id: ob.uuid}, method: :delete, remote: true, data: {confirm: "You are about to delete #{controller.model_class} #{ob.uuid}.\n\nAre you sure?"}) do %>
+        <i class="icon-trash"></i>
+        <% end %>
+        <% end %>
       </td>
     </tr>