Commit fbfc620fffe1344174aa25345adcb42b5620f0e6

Authored by Larissa Reis
Committed by Rodrigo Souto
1 parent 7d22740a

Including article name in delete confirmation message

  * Included alert confirmation to delete link on content viewer and
    cms.
  * Removed the destroy page, since it was useless.

Pair-programmed with: Rodrigo Souto <rodrigo@colivre.coop.br>

(ActionItem1524)
app/controllers/my_profile/cms_controller.rb
@@ -206,6 +206,7 @@ class CmsController &lt; MyProfileController @@ -206,6 +206,7 @@ class CmsController &lt; MyProfileController
206 @article = profile.articles.find(params[:id]) 206 @article = profile.articles.find(params[:id])
207 if request.post? 207 if request.post?
208 @article.destroy 208 @article.destroy
  209 + session[:notice] = _("\"#{@article.name}\" was removed.")
209 redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent 210 redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent
210 end 211 end
211 end 212 end
app/helpers/application_helper.rb
@@ -1327,4 +1327,11 @@ module ApplicationHelper @@ -1327,4 +1327,11 @@ module ApplicationHelper
1327 end 1327 end
1328 end 1328 end
1329 1329
  1330 + def delete_article_message(article)
  1331 + if article.folder?
  1332 + _("Are you sure that you want to remove the folder \"#{article.name}\"? Note that all the items inside it will also be removed!")
  1333 + else
  1334 + _("Are you sure that you want to remove the item \"#{article.name}\"?")
  1335 + end
  1336 + end
1330 end 1337 end
app/helpers/cms_helper.rb
@@ -49,12 +49,6 @@ module CmsHelper @@ -49,12 +49,6 @@ module CmsHelper
49 end 49 end
50 50
51 def display_delete_button(article) 51 def display_delete_button(article)
52 - confirm_message = if article.folder?  
53 - _('Are you sure that you want to remove this folder? Note that all the items inside it will also be removed!')  
54 - else  
55 - _('Are you sure that you want to remove this item?')  
56 - end  
57 -  
58 - button_without_text :delete, _('Delete'), { :action => 'destroy', :id => article.id }, :method => :post, :confirm => confirm_message 52 + button_without_text :delete, _('Delete'), { :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article)
59 end 53 end
60 end 54 end
app/views/content_viewer/_article_toolbar.rhtml
@@ -8,8 +8,10 @@ @@ -8,8 +8,10 @@
8 <% if !(profile.kind_of?(Enterprise) && environment.enabled?('disable_cms')) %> 8 <% if !(profile.kind_of?(Enterprise) && environment.enabled?('disable_cms')) %>
9 <% if @page != profile.home_page && !@page.has_posts? %> 9 <% if @page != profile.home_page && !@page.has_posts? %>
10 <%= link_to content_tag( 'span', _('Delete') ), 10 <%= link_to content_tag( 'span', _('Delete') ),
11 - profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page }),  
12 - :class => 'button with-text icon-delete' %> 11 + profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}),
  12 + :method => :post,
  13 + :class => 'button with-text icon-delete',
  14 + :confirm => delete_article_message(@page) %>
13 <% end %> 15 <% end %>
14 <% if !environment.enabled?('disable_cms') && !@page.folder? %> 16 <% if !environment.enabled?('disable_cms') && !@page.folder? %>
15 <% if profile.kind_of?(Person) %> 17 <% if profile.kind_of?(Person) %>
test/functional/cms_controller_test.rb
@@ -902,9 +902,8 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -902,9 +902,8 @@ class CmsControllerTest &lt; Test::Unit::TestCase
902 902
903 should 'offer confirmation to remove article' do 903 should 'offer confirmation to remove article' do
904 a = profile.articles.create!(:name => 'my-article') 904 a = profile.articles.create!(:name => 'my-article')
905 - get :destroy, :profile => profile.identifier, :id => a.id  
906 - assert_response :success  
907 - assert_tag :tag => 'input', :attributes => {:type => 'submit', :value => 'Yes, I want.' } 905 + post :destroy, :profile => profile.identifier, :id => a.id
  906 + assert_response :redirect
908 end 907 end
909 908
910 should 'display notify comments option' do 909 should 'display notify comments option' do
test/unit/cms_helper_test.rb
@@ -82,8 +82,9 @@ class CmsHelperTest &lt; Test::Unit::TestCase @@ -82,8 +82,9 @@ class CmsHelperTest &lt; Test::Unit::TestCase
82 82
83 should 'display delete_button to folder' do 83 should 'display delete_button to folder' do
84 profile = fast_create(Profile) 84 profile = fast_create(Profile)
85 - folder = fast_create(Folder, :name => 'My folder', :profile_id => profile.id)  
86 - confirm_message = 'Are you sure that you want to remove this folder? Note that all the items inside it will also be removed!' 85 + name = 'My folder'
  86 + folder = fast_create(Folder, :name => name, :profile_id => profile.id)
  87 + confirm_message = "Are you sure that you want to remove the folder \"#{name}\"? Note that all the items inside it will also be removed!"
87 expects(:button_without_text).with(:delete, 'Delete', {:action => 'destroy', :id => folder.id}, :method => :post, :confirm => confirm_message) 88 expects(:button_without_text).with(:delete, 'Delete', {:action => 'destroy', :id => folder.id}, :method => :post, :confirm => confirm_message)
88 89
89 result = display_delete_button(folder) 90 result = display_delete_button(folder)
@@ -91,8 +92,9 @@ class CmsHelperTest &lt; Test::Unit::TestCase @@ -91,8 +92,9 @@ class CmsHelperTest &lt; Test::Unit::TestCase
91 92
92 should 'display delete_button to article' do 93 should 'display delete_button to article' do
93 profile = fast_create(Profile) 94 profile = fast_create(Profile)
94 - article = fast_create(TinyMceArticle, :name => 'My article', :profile_id => profile.id)  
95 - confirm_message = 'Are you sure that you want to remove this item?' 95 + name = 'My article'
  96 + article = fast_create(TinyMceArticle, :name => name, :profile_id => profile.id)
  97 + confirm_message = "Are you sure that you want to remove the item \"#{name}\"?"
96 expects(:button_without_text).with(:delete, 'Delete', {:action => 'destroy', :id => article.id}, :method => :post, :confirm => confirm_message) 98 expects(:button_without_text).with(:delete, 'Delete', {:action => 'destroy', :id => article.id}, :method => :post, :confirm => confirm_message)
97 99
98 result = display_delete_button(article) 100 result = display_delete_button(article)