From: Jan Provaznik <jprovazn(a)redhat.com>
https://www.aeolusproject.org/redmine/issues/2221
Used respond_with helper method, except multi_destroy action which
I think should be used only by web UI.
---
src/app/controllers/catalog_entries_controller.rb | 25 ++++++++++++--------
src/app/views/catalog_entries/show.haml | 2 +-
src/config/locales/en.yml | 1 +
src/features/catalog_entries.feature | 2 +-
4 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/app/controllers/catalog_entries_controller.rb
b/src/app/controllers/catalog_entries_controller.rb
index 4432691..f48ed8e 100644
--- a/src/app/controllers/catalog_entries_controller.rb
+++ b/src/app/controllers/catalog_entries_controller.rb
@@ -1,5 +1,9 @@
class CatalogEntriesController < ApplicationController
before_filter :require_user
+ respond_to :html
+ # I think multi_destroy action is required only by
+ # web UI, so don't bother about json response in this case
+ respond_to :json, :except => :multi_destroy
def top_section
:administer
@@ -10,18 +14,21 @@ class CatalogEntriesController < ApplicationController
save_breadcrumb(catalog_entries_path(:viewstate => @viewstate ? @viewstate.id :
nil))
@catalog_entries = CatalogEntry.list_for_user(current_user, Privilege::VIEW)
set_header
+ respond_with @catalog_entries
end
def new
@catalog_entry = CatalogEntry.new(params[:catalog_entry])
require_privilege(Privilege::CREATE, CatalogEntry)
load_catalogs
+ respond_with @catalog_entry
end
def show
@catalog_entry = CatalogEntry.find(params[:id])
require_privilege(Privilege::VIEW, @catalog_entry)
save_breadcrumb(catalog_entry_path(@catalog_entry), @catalog_entry.name)
+ respond_with @catalog_entry
end
def create
@@ -36,17 +43,17 @@ class CatalogEntriesController < ApplicationController
if @catalog_entry.save
flash[:notice] = 'Catalog entry added'
flash[:warning] = "Deployable url doesn't resolve valid XML file"
unless @catalog_entry.accessible_and_valid_deployable_xml?((a)catalog_entry.url)
- redirect_to catalog_entries_path
else
load_catalogs
- render :new
end
+ respond_with @catalog_entry
end
def edit
@catalog_entry = CatalogEntry.find(params[:id])
require_privilege(Privilege::MODIFY, @catalog_entry)
load_catalogs
+ respond_with @catalog_entry
end
def update
@@ -56,11 +63,10 @@ class CatalogEntriesController < ApplicationController
if @catalog_entry.update_attributes(params[:catalog_entry])
flash[:notice] = 'Catalog entry updated successfully!'
- redirect_to catalog_entries_url
else
load_catalogs
- render :action => 'edit'
end
+ respond_with @catalog_entry
end
def multi_destroy
@@ -72,13 +78,12 @@ class CatalogEntriesController < ApplicationController
end
def destroy
- catalog_entry = CatalogEntry.find(params[:id])
- require_privilege(Privilege::MODIFY, catalog_entry)
- catalog_entry.destroy
-
- respond_to do |format|
- format.html { redirect_to catalog_entries_path }
+ @catalog_entry = CatalogEntry.find(params[:id])
+ require_privilege(Privilege::MODIFY, @catalog_entry)
+ unless @catalog_entry.destroy
+ flash[:notice] = t('catalog_entries.destroy_failed', :count => 1)
end
+ respond_with @catalog_entry
end
private
diff --git a/src/app/views/catalog_entries/show.haml
b/src/app/views/catalog_entries/show.haml
index 2281236..5ce160b 100644
--- a/src/app/views/catalog_entries/show.haml
+++ b/src/app/views/catalog_entries/show.haml
@@ -5,7 +5,7 @@
= link_to 'New Catalog Entry', new_catalog_entry_url, :class =>
'button primary', :id => 'new_catalog_entry_button'
.button-group
= link_to 'Edit', edit_catalog_entry_path(@catalog_entry), :class =>
'button pill', :id => 'edit_button'
- = button_to "Delete", catalog_entry_path(@catalog_entry), :method =>
'delete', :confirm => "Are you sure you want to delete?", :class
=> 'button pill danger', :id => 'delete_button'
+ = button_to "Delete", catalog_entry_path(@catalog_entry), :method =>
'delete', :confirm => "Are you sure you want to delete?", :class
=> 'button pill danger', :id => 'entry_delete_button'
.corner
%section.content-section.user
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 03d2951..3344398 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -170,6 +170,7 @@ en:
catalog_entries: Catalog Entries
name: Name
url: URL
+ destroy_failed: Failed to destroy catalog entry
catalogs:
index:
name: Name
diff --git a/src/features/catalog_entries.feature b/src/features/catalog_entries.feature
index 3d4ee38..fa1916c 100644
--- a/src/features/catalog_entries.feature
+++ b/src/features/catalog_entries.feature
@@ -55,7 +55,7 @@ Feature: Manage Catalog Entries
Given a catalog entry "testdepl1" exists
And I am on the catalog entries page
When I follow "testdepl1"
- And I press "delete_button"
+ And I press "entry_delete_button"
Then there should be only 0 catalog entries
And I should be on the catalog entries page
And I should not see "testdepl1"
--
1.7.6.2