Commit 548e53dd5df2595055a0429f61452308890a8d31
1 parent
7cf76645
Exists in
master
and in
29 other branches
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
Showing
20 changed files
with
94 additions
and
15 deletions
Show diff stats
app/controllers/box_organizer_controller.rb
... | ... | @@ -38,18 +38,22 @@ class BoxOrganizerController < ApplicationController |
38 | 38 | @block.save! |
39 | 39 | |
40 | 40 | @target_box.reload |
41 | + | |
42 | + unless request.xhr? | |
43 | + redirect_to :action => 'index' | |
44 | + end | |
41 | 45 | end |
42 | 46 | |
43 | 47 | def move_block_down |
44 | 48 | @block = boxes_holder.blocks.find(params[:id]) |
45 | 49 | @block.move_lower |
46 | - redirect_to :back | |
50 | + redirect_to :action => 'index' | |
47 | 51 | end |
48 | 52 | |
49 | 53 | def move_block_up |
50 | 54 | @block = boxes_holder.blocks.find(params[:id]) |
51 | 55 | @block.move_higher |
52 | - redirect_to :back | |
56 | + redirect_to :action => 'index' | |
53 | 57 | end |
54 | 58 | |
55 | 59 | def add_block | ... | ... |
app/helpers/boxes_helper.rb
... | ... | @@ -131,15 +131,30 @@ module BoxesHelper |
131 | 131 | |
132 | 132 | def block_edit_buttons(block) |
133 | 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 | 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 | 145 | buttons << icon_button(:down, _('Move block down'), { :action => 'move_block_down' ,:id => block.id }, { :method => 'post'}) |
141 | 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 | 158 | if block.editable? |
144 | 159 | buttons << lightbox_icon_button(:edit, _('Edit'), { :action => 'edit', :id => block.id }) |
145 | 160 | end |
... | ... | @@ -148,6 +163,10 @@ module BoxesHelper |
148 | 163 | buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post'}) |
149 | 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 | 170 | content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar') |
152 | 171 | end |
153 | 172 | ... | ... |
app/helpers/thickbox_helper.rb
... | ... | @@ -2,6 +2,9 @@ module ThickboxHelper |
2 | 2 | def thickbox_inline_popup_link(title, id, options = {}) |
3 | 3 | link_to(title, "#TB_inline?height=300&width=500&inlineId=#{id}&modal=true", {:class => 'thickbox'}.merge(options)) |
4 | 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 | 8 | def thickbox_close_button(title) |
6 | 9 | button_to_function(:close, title, 'tb_remove();') |
7 | 10 | end | ... | ... |
app/models/article_block.rb
... | ... | @@ -4,6 +4,10 @@ class ArticleBlock < Block |
4 | 4 | _('Display one of your contents.') |
5 | 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 | 11 | def content |
8 | 12 | article ? article.to_html : _('Article not selected yet.') |
9 | 13 | end | ... | ... |
app/models/communities_block.rb
app/models/enterprises_block.rb
app/models/environment_statistics_block.rb
... | ... | @@ -8,6 +8,10 @@ class EnvironmentStatisticsBlock < Block |
8 | 8 | _('Statistics for %s') % owner.name |
9 | 9 | end |
10 | 10 | |
11 | + def help | |
12 | + _('This block presents some statistics about your environment.') | |
13 | + end | |
14 | + | |
11 | 15 | def content |
12 | 16 | users = owner.people.count(:conditions => { :public_profile => true }) |
13 | 17 | enterprises = owner.enterprises.count(:conditions => { :public_profile => true }) | ... | ... |
app/models/favorite_enterprises_block.rb
app/models/friends_block.rb
app/models/link_list_block.rb
... | ... | @@ -9,6 +9,10 @@ class LinkListBlock < Block |
9 | 9 | def self.description |
10 | 10 | _('Display a list of links.') |
11 | 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 | 17 | def content |
14 | 18 | block_title(title) + | ... | ... |
app/models/login_block.rb
app/models/main_block.rb
app/models/members_block.rb
app/models/my_network_block.rb
app/models/people_block.rb
app/models/products_block.rb
app/models/recent_documents_block.rb
app/models/sellers_search_block.rb
app/models/tags_block.rb
... | ... | @@ -13,8 +13,8 @@ class TagsBlock < Block |
13 | 13 | end |
14 | 14 | |
15 | 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 | 18 | end |
19 | 19 | |
20 | 20 | def content | ... | ... |
test/functional/profile_design_controller_test.rb
... | ... | @@ -78,8 +78,6 @@ class ProfileDesignControllerTest < Test::Unit::TestCase |
78 | 78 | def test_should_move_block_to_the_end_of_another_block |
79 | 79 | get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}" |
80 | 80 | |
81 | - assert_response :success | |
82 | - | |
83 | 81 | @b1.reload |
84 | 82 | @box2.reload |
85 | 83 | |
... | ... | @@ -92,8 +90,6 @@ class ProfileDesignControllerTest < Test::Unit::TestCase |
92 | 90 | # block 4 is in box 2 |
93 | 91 | get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}" |
94 | 92 | |
95 | - assert_response :success | |
96 | - | |
97 | 93 | @b1.reload |
98 | 94 | @b4.reload |
99 | 95 | |
... | ... | @@ -105,7 +101,6 @@ class ProfileDesignControllerTest < Test::Unit::TestCase |
105 | 101 | def test_block_can_be_moved_up |
106 | 102 | get :move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}" |
107 | 103 | |
108 | - assert_response :success | |
109 | 104 | @b4.reload |
110 | 105 | @b3.reload |
111 | 106 | |
... | ... | @@ -125,6 +120,16 @@ class ProfileDesignControllerTest < Test::Unit::TestCase |
125 | 120 | assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position} |
126 | 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 | 133 | def test_should_be_able_to_move_block_directly_down |
129 | 134 | post :move_block_down, :profile => 'designtestuser', :id => @b1.id |
130 | 135 | assert_response :redirect | ... | ... |