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 206 @article = profile.articles.find(params[:id])
207 207 if request.post?
208 208 @article.destroy
  209 + session[:notice] = _("\"#{@article.name}\" was removed.")
209 210 redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent
210 211 end
211 212 end
... ...
app/helpers/application_helper.rb
... ... @@ -1327,4 +1327,11 @@ module ApplicationHelper
1327 1327 end
1328 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 1337 end
... ...
app/helpers/cms_helper.rb
... ... @@ -49,12 +49,6 @@ module CmsHelper
49 49 end
50 50  
51 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 53 end
60 54 end
... ...
app/views/content_viewer/_article_toolbar.rhtml
... ... @@ -8,8 +8,10 @@
8 8 <% if !(profile.kind_of?(Enterprise) && environment.enabled?('disable_cms')) %>
9 9 <% if @page != profile.home_page && !@page.has_posts? %>
10 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 15 <% end %>
14 16 <% if !environment.enabled?('disable_cms') && !@page.folder? %>
15 17 <% if profile.kind_of?(Person) %>
... ...
test/functional/cms_controller_test.rb
... ... @@ -902,9 +902,8 @@ class CmsControllerTest &lt; Test::Unit::TestCase
902 902  
903 903 should 'offer confirmation to remove article' do
904 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 907 end
909 908  
910 909 should 'display notify comments option' do
... ...
test/unit/cms_helper_test.rb
... ... @@ -82,8 +82,9 @@ class CmsHelperTest &lt; Test::Unit::TestCase
82 82  
83 83 should 'display delete_button to folder' do
84 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 88 expects(:button_without_text).with(:delete, 'Delete', {:action => 'destroy', :id => folder.id}, :method => :post, :confirm => confirm_message)
88 89  
89 90 result = display_delete_button(folder)
... ... @@ -91,8 +92,9 @@ class CmsHelperTest &lt; Test::Unit::TestCase
91 92  
92 93 should 'display delete_button to article' do
93 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 98 expects(:button_without_text).with(:delete, 'Delete', {:action => 'destroy', :id => article.id}, :method => :post, :confirm => confirm_message)
97 99  
98 100 result = display_delete_button(article)
... ...