Commit 548e53dd5df2595055a0429f61452308890a8d31

Authored by AntonioTerceiro
1 parent 7cf76645

ActionItem615: enhancing sidebox manipulation

    * Added more options to move blocks: a button for "move this block
      to the oposite side".
    * Added help button for each block.
      + Wrote help for all blocks, plus enhancing the existing help in
      some blocks.
    * Adapted tests to the new bahaviour and added some tests.

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2463 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/box_organizer_controller.rb
@@ -38,18 +38,22 @@ class BoxOrganizerController < ApplicationController @@ -38,18 +38,22 @@ class BoxOrganizerController < ApplicationController
38 @block.save! 38 @block.save!
39 39
40 @target_box.reload 40 @target_box.reload
  41 +
  42 + unless request.xhr?
  43 + redirect_to :action => 'index'
  44 + end
41 end 45 end
42 46
43 def move_block_down 47 def move_block_down
44 @block = boxes_holder.blocks.find(params[:id]) 48 @block = boxes_holder.blocks.find(params[:id])
45 @block.move_lower 49 @block.move_lower
46 - redirect_to :back 50 + redirect_to :action => 'index'
47 end 51 end
48 52
49 def move_block_up 53 def move_block_up
50 @block = boxes_holder.blocks.find(params[:id]) 54 @block = boxes_holder.blocks.find(params[:id])
51 @block.move_higher 55 @block.move_higher
52 - redirect_to :back 56 + redirect_to :action => 'index'
53 end 57 end
54 58
55 def add_block 59 def add_block
app/helpers/boxes_helper.rb
@@ -131,15 +131,30 @@ module BoxesHelper @@ -131,15 +131,30 @@ module BoxesHelper
131 131
132 def block_edit_buttons(block) 132 def block_edit_buttons(block)
133 buttons = [] 133 buttons = []
  134 + nowhere = 'javascript: return false;'
134 135
135 - if !block.first?  
136 - buttons << icon_button(:up, _('Move block up'), { :action => 'move_block_up', :id => block.id }, { :method => 'post' }) 136 + if block.first?
  137 + buttons << icon_button('up-disabled', _("Can't move up anymore."), nowhere)
  138 + else
  139 + buttons << icon_button('up', _('Move block up'), { :action => 'move_block_up', :id => block.id }, { :method => 'post' })
137 end 140 end
138 141
139 - if !block.last? 142 + if block.last?
  143 + buttons << icon_button('down-disabled', _("Can't move down anymore."), nowhere)
  144 + else
140 buttons << icon_button(:down, _('Move block down'), { :action => 'move_block_down' ,:id => block.id }, { :method => 'post'}) 145 buttons << icon_button(:down, _('Move block down'), { :action => 'move_block_down' ,:id => block.id }, { :method => 'post'})
141 end 146 end
142 147
  148 + # move to opposite side
  149 + # FIXME too much hardcoded stuff
  150 + if profile.layout_template == 'default'
  151 + if block.box.position == 2 # area 2, left side => move to right side
  152 + buttons << icon_button('right', _('Move to the opposite side'), { :action => 'move_block', :target => 'end-of-box-' + profile.boxes[2].id.to_s, :id => block.id }, :method => 'post' )
  153 + elsif block.box.position == 3 # area 3, right side => move to left side
  154 + buttons << icon_button('left', _('Move to the opposite side'), { :action => 'move_block', :target => 'end-of-box-' + profile.boxes[1].id.to_s, :id => block.id }, :method => 'post' )
  155 + end
  156 + end
  157 +
143 if block.editable? 158 if block.editable?
144 buttons << lightbox_icon_button(:edit, _('Edit'), { :action => 'edit', :id => block.id }) 159 buttons << lightbox_icon_button(:edit, _('Edit'), { :action => 'edit', :id => block.id })
145 end 160 end
@@ -148,6 +163,10 @@ module BoxesHelper @@ -148,6 +163,10 @@ module BoxesHelper
148 buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post'}) 163 buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post'})
149 end 164 end
150 165
  166 + if block.respond_to?(:help)
  167 + buttons << thickbox_inline_popup_icon(:help, _('Help on this block'), "help-on-box-#{block.id}") << content_tag('div', content_tag('h2', _('Help')) + content_tag('div', block.help, :style => 'margin-bottom: 1em;') + thickbox_close_button(_('Close')), :style => 'display: none;', :id => "help-on-box-#{block.id}")
  168 + end
  169 +
151 content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar') 170 content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar')
152 end 171 end
153 172
app/helpers/thickbox_helper.rb
@@ -2,6 +2,9 @@ module ThickboxHelper @@ -2,6 +2,9 @@ module ThickboxHelper
2 def thickbox_inline_popup_link(title, id, options = {}) 2 def thickbox_inline_popup_link(title, id, options = {})
3 link_to(title, "#TB_inline?height=300&width=500&inlineId=#{id}&modal=true", {:class => 'thickbox'}.merge(options)) 3 link_to(title, "#TB_inline?height=300&width=500&inlineId=#{id}&modal=true", {:class => 'thickbox'}.merge(options))
4 end 4 end
  5 + def thickbox_inline_popup_icon(type, title, id, options = {})
  6 + icon_button(type, title, "#TB_inline?height=300&width=500&inlineId=#{id}&modal=true", {:class => "thickbox"}.merge(options))
  7 + end
5 def thickbox_close_button(title) 8 def thickbox_close_button(title)
6 button_to_function(:close, title, 'tb_remove();') 9 button_to_function(:close, title, 'tb_remove();')
7 end 10 end
app/models/article_block.rb
@@ -4,6 +4,10 @@ class ArticleBlock &lt; Block @@ -4,6 +4,10 @@ class ArticleBlock &lt; Block
4 _('Display one of your contents.') 4 _('Display one of your contents.')
5 end 5 end
6 6
  7 + def help
  8 + _('This block displays one of your articles. You can edit the block to select which one of your articles is going to be displayed in the block.')
  9 + end
  10 +
7 def content 11 def content
8 article ? article.to_html : _('Article not selected yet.') 12 article ? article.to_html : _('Article not selected yet.')
9 end 13 end
app/models/communities_block.rb
@@ -9,7 +9,7 @@ class CommunitiesBlock &lt; ProfileListBlock @@ -9,7 +9,7 @@ class CommunitiesBlock &lt; ProfileListBlock
9 end 9 end
10 10
11 def help 11 def help
12 - __('The communities in which the user is a member') 12 + __('This block displays the communities in which the user is a member.')
13 end 13 end
14 14
15 def footer 15 def footer
app/models/enterprises_block.rb
@@ -5,7 +5,7 @@ class EnterprisesBlock &lt; ProfileListBlock @@ -5,7 +5,7 @@ class EnterprisesBlock &lt; ProfileListBlock
5 end 5 end
6 6
7 def help 7 def help
8 - __('The enterprises where this user works.') 8 + __('This block displays the enterprises where this user works.')
9 end 9 end
10 10
11 def self.description 11 def self.description
app/models/environment_statistics_block.rb
@@ -8,6 +8,10 @@ class EnvironmentStatisticsBlock &lt; Block @@ -8,6 +8,10 @@ class EnvironmentStatisticsBlock &lt; Block
8 _('Statistics for %s') % owner.name 8 _('Statistics for %s') % owner.name
9 end 9 end
10 10
  11 + def help
  12 + _('This block presents some statistics about your environment.')
  13 + end
  14 +
11 def content 15 def content
12 users = owner.people.count(:conditions => { :public_profile => true }) 16 users = owner.people.count(:conditions => { :public_profile => true })
13 enterprises = owner.enterprises.count(:conditions => { :public_profile => true }) 17 enterprises = owner.enterprises.count(:conditions => { :public_profile => true })
app/models/favorite_enterprises_block.rb
@@ -5,7 +5,7 @@ class FavoriteEnterprisesBlock &lt; ProfileListBlock @@ -5,7 +5,7 @@ class FavoriteEnterprisesBlock &lt; ProfileListBlock
5 end 5 end
6 6
7 def help 7 def help
8 - __('This user\'s favorite enterprises.') 8 + __('This block lists the favorite enterprises of the user.')
9 end 9 end
10 10
11 def self.description 11 def self.description
app/models/friends_block.rb
@@ -8,6 +8,10 @@ class FriendsBlock &lt; ProfileListBlock @@ -8,6 +8,10 @@ class FriendsBlock &lt; ProfileListBlock
8 __('Friends') 8 __('Friends')
9 end 9 end
10 10
  11 + def help
  12 + _('This block displays your friends.')
  13 + end
  14 +
11 def footer 15 def footer
12 owner_id = owner.identifier 16 owner_id = owner.identifier
13 lambda do 17 lambda do
app/models/link_list_block.rb
@@ -9,6 +9,10 @@ class LinkListBlock &lt; Block @@ -9,6 +9,10 @@ class LinkListBlock &lt; Block
9 def self.description 9 def self.description
10 _('Display a list of links.') 10 _('Display a list of links.')
11 end 11 end
  12 +
  13 + def help
  14 + _('This block can be used to create a menu of links. You can add, remove and update the links as you wish.')
  15 + end
12 16
13 def content 17 def content
14 block_title(title) + 18 block_title(title) +
app/models/login_block.rb
@@ -4,6 +4,10 @@ class LoginBlock &lt; Block @@ -4,6 +4,10 @@ class LoginBlock &lt; Block
4 _('A login box for your users.') 4 _('A login box for your users.')
5 end 5 end
6 6
  7 + def help
  8 + _('This block presents a login/logout block.')
  9 + end
  10 +
7 def content 11 def content
8 lambda do 12 lambda do
9 if logged_in? 13 if logged_in?
app/models/main_block.rb
@@ -4,6 +4,10 @@ class MainBlock &lt; Block @@ -4,6 +4,10 @@ class MainBlock &lt; Block
4 _('Block for main content (i.e. your articles, photos, etc)') 4 _('Block for main content (i.e. your articles, photos, etc)')
5 end 5 end
6 6
  7 + def help
  8 + _('This block presents the main content of your pages.')
  9 + end
  10 +
7 def content 11 def content
8 nil 12 nil
9 end 13 end
app/models/members_block.rb
@@ -8,6 +8,10 @@ class MembersBlock &lt; ProfileListBlock @@ -8,6 +8,10 @@ class MembersBlock &lt; ProfileListBlock
8 _('Members') 8 _('Members')
9 end 9 end
10 10
  11 + def help
  12 + _('This block presents the members of a collective.')
  13 + end
  14 +
11 def footer 15 def footer
12 profile = self.owner 16 profile = self.owner
13 lambda do 17 lambda do
app/models/my_network_block.rb
@@ -10,6 +10,10 @@ class MyNetworkBlock &lt; Block @@ -10,6 +10,10 @@ class MyNetworkBlock &lt; Block
10 _('My network') 10 _('My network')
11 end 11 end
12 12
  13 + def help
  14 + _('This block displays some info about your networking.')
  15 + end
  16 +
13 def content 17 def content
14 block_title(title) + 18 block_title(title) +
15 content_tag( 19 content_tag(
app/models/people_block.rb
@@ -12,6 +12,10 @@ class PeopleBlock &lt; ProfileListBlock @@ -12,6 +12,10 @@ class PeopleBlock &lt; ProfileListBlock
12 _('A block displays random people') 12 _('A block displays random people')
13 end 13 end
14 14
  15 + def help
  16 + _('This block presents a list of people.')
  17 + end
  18 +
15 def profile_finder 19 def profile_finder
16 @profile_finder ||= PeopleBlock::Finder.new(self) 20 @profile_finder ||= PeopleBlock::Finder.new(self)
17 end 21 end
app/models/products_block.rb
@@ -12,6 +12,10 @@ class ProductsBlock &lt; Block @@ -12,6 +12,10 @@ class ProductsBlock &lt; Block
12 _('Products') 12 _('Products')
13 end 13 end
14 14
  15 + def help
  16 + _('This block presents a list of your products.')
  17 + end
  18 +
15 def content 19 def content
16 block_title(title) + 20 block_title(title) +
17 content_tag( 21 content_tag(
app/models/recent_documents_block.rb
@@ -8,6 +8,10 @@ class RecentDocumentsBlock &lt; Block @@ -8,6 +8,10 @@ class RecentDocumentsBlock &lt; Block
8 _('Recent content') 8 _('Recent content')
9 end 9 end
10 10
  11 + def help
  12 + _('This block lists your recent content.')
  13 + end
  14 +
11 settings_items :limit 15 settings_items :limit
12 16
13 include ActionController::UrlWriter 17 include ActionController::UrlWriter
app/models/sellers_search_block.rb
@@ -12,6 +12,10 @@ class SellersSearchBlock &lt; Block @@ -12,6 +12,10 @@ class SellersSearchBlock &lt; Block
12 _('Search for sellers') 12 _('Search for sellers')
13 end 13 end
14 14
  15 + def help
  16 + _('This block presents a search engine for products.')
  17 + end
  18 +
15 def content 19 def content
16 title = self.title 20 title = self.title
17 lambda do 21 lambda do
app/models/tags_block.rb
@@ -13,8 +13,8 @@ class TagsBlock &lt; Block @@ -13,8 +13,8 @@ class TagsBlock &lt; Block
13 end 13 end
14 14
15 def help 15 def help
16 - _('The tag is created when you add some one to your article. <p/>  
17 - Try to add some tags to some articles and see your tag cloud to grow.') 16 + _("Tags are created when you add some of them one to your contents. <p/>
  17 + Try to add some tags to some articles and you'l see your tag cloud growing.")
18 end 18 end
19 19
20 def content 20 def content
test/functional/profile_design_controller_test.rb
@@ -78,8 +78,6 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase @@ -78,8 +78,6 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
78 def test_should_move_block_to_the_end_of_another_block 78 def test_should_move_block_to_the_end_of_another_block
79 get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}" 79 get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}"
80 80
81 - assert_response :success  
82 -  
83 @b1.reload 81 @b1.reload
84 @box2.reload 82 @box2.reload
85 83
@@ -92,8 +90,6 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase @@ -92,8 +90,6 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
92 # block 4 is in box 2 90 # block 4 is in box 2
93 get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}" 91 get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}"
94 92
95 - assert_response :success  
96 -  
97 @b1.reload 93 @b1.reload
98 @b4.reload 94 @b4.reload
99 95
@@ -105,7 +101,6 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase @@ -105,7 +101,6 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
105 def test_block_can_be_moved_up 101 def test_block_can_be_moved_up
106 get :move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}" 102 get :move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}"
107 103
108 - assert_response :success  
109 @b4.reload 104 @b4.reload
110 @b3.reload 105 @b3.reload
111 106
@@ -125,6 +120,16 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase @@ -125,6 +120,16 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
125 assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position} 120 assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position}
126 end 121 end
127 122
  123 + def test_move_block_should_redirect_when_not_called_via_ajax
  124 + get :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
  125 + assert_redirected_to :action => 'index'
  126 + end
  127 +
  128 + def test_move_block_should_render_when_called_via_ajax
  129 + xml_http_request :get, :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
  130 + assert_template 'move_block'
  131 + end
  132 +
128 def test_should_be_able_to_move_block_directly_down 133 def test_should_be_able_to_move_block_directly_down
129 post :move_block_down, :profile => 'designtestuser', :id => @b1.id 134 post :move_block_down, :profile => 'designtestuser', :id => @b1.id
130 assert_response :redirect 135 assert_response :redirect