Commit ebbd2aa42cb8a435c0da2ba277d7b462bbbf435c
Committed by
Victor Costa
1 parent
4eb56579
Exists in
staging
and in
42 other branches
Allow the display field of MainBlock to be edited.
Enable options to display the main block at all pages and all pages except in the homepage.
Showing
5 changed files
with
50 additions
and
16 deletions
Show diff stats
app/models/block.rb
@@ -40,7 +40,7 @@ class Block < ActiveRecord::Base | @@ -40,7 +40,7 @@ class Block < ActiveRecord::Base | ||
40 | if context[:article] | 40 | if context[:article] |
41 | return context[:article] != owner.home_page | 41 | return context[:article] != owner.home_page |
42 | else | 42 | else |
43 | - return context[:request_path] != '/' + owner.identifier | 43 | + return context[:request_path] != '/' + (owner.kind_of?(Profile) ? owner.identifier : '') |
44 | end | 44 | end |
45 | end | 45 | end |
46 | end | 46 | end |
@@ -153,4 +153,19 @@ class Block < ActiveRecord::Base | @@ -153,4 +153,19 @@ class Block < ActiveRecord::Base | ||
153 | } | 153 | } |
154 | end | 154 | end |
155 | 155 | ||
156 | + DISPLAY_OPTIONS = { | ||
157 | + 'always' => __('In all pages'), | ||
158 | + 'home_page_only' => __('Only in the homepage'), | ||
159 | + 'except_home_page' => __('In all pages, except in the homepage'), | ||
160 | + 'never' => __('Don\'t display'), | ||
161 | + } | ||
162 | + | ||
163 | + def display_options | ||
164 | + DISPLAY_OPTIONS.keys | ||
165 | + end | ||
166 | + | ||
167 | + def display_option_label(option) | ||
168 | + DISPLAY_OPTIONS[option] | ||
169 | + end | ||
170 | + | ||
156 | end | 171 | end |
app/models/main_block.rb
@@ -17,11 +17,15 @@ class MainBlock < Block | @@ -17,11 +17,15 @@ class MainBlock < Block | ||
17 | end | 17 | end |
18 | 18 | ||
19 | def editable? | 19 | def editable? |
20 | - false | 20 | + true |
21 | end | 21 | end |
22 | 22 | ||
23 | def cacheable? | 23 | def cacheable? |
24 | - false | 24 | + false |
25 | + end | ||
26 | + | ||
27 | + def display_options | ||
28 | + ['always', 'except_home_page'] | ||
25 | end | 29 | end |
26 | 30 | ||
27 | end | 31 | end |
app/views/box_organizer/edit.rhtml
@@ -9,17 +9,11 @@ | @@ -9,17 +9,11 @@ | ||
9 | 9 | ||
10 | <%= labelled_form_field _('Display this block:'), '' %> | 10 | <%= labelled_form_field _('Display this block:'), '' %> |
11 | <div style='margin-left: 10px'> | 11 | <div style='margin-left: 10px'> |
12 | - <%= radio_button(:block, :display, 'always') %> | ||
13 | - <%= label_tag('block_display_always', _('In all pages')) %> | ||
14 | - <br/> | ||
15 | - <%= radio_button(:block, :display, 'home_page_only') %> | ||
16 | - <%= label_tag('block_display_home_page_only', _('Only in the homepage')) %> | ||
17 | - <br/> | ||
18 | - <%= radio_button(:block, :display, 'except_home_page') %> | ||
19 | - <%= label_tag('block_display_except_home_page', _('In all pages, except in the homepage')) %> | ||
20 | - <br/> | ||
21 | - <%= radio_button(:block, :display, 'never') %> | ||
22 | - <%= label_tag('block_display_never', _("Don't display")) %> | 12 | + <% @block.display_options.each do |option| %> |
13 | + <%= radio_button(:block, :display, option) %> | ||
14 | + <%= label_tag("block_display_#{option}", _(@block.display_option_label(option))) %> | ||
15 | + <br/> | ||
16 | + <% end %> | ||
23 | </div> | 17 | </div> |
24 | 18 | ||
25 | <%= labelled_form_field(_('Show for:'), select(:block, :language, [ [ _('all languages'), 'all']] + environment.locales.map {|key, value| [value, key]} )) %> | 19 | <%= labelled_form_field(_('Show for:'), select(:block, :language, [ [ _('all languages'), 'all']] + environment.locales.map {|key, value| [value, key]} )) %> |
test/functional/profile_design_controller_test.rb
@@ -300,6 +300,27 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -300,6 +300,27 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
300 | assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | 300 | assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8) |
301 | end | 301 | end |
302 | 302 | ||
303 | + should 'not edit main block with never option' do | ||
304 | + get :edit, :profile => 'designtestuser', :id => @b4.id | ||
305 | + assert_no_tag :input, :attributes => { :type => 'radio', :value => 'never'} | ||
306 | + end | ||
307 | + | ||
308 | + should 'not edit main block with home_page_only option' do | ||
309 | + get :edit, :profile => 'designtestuser', :id => @b4.id | ||
310 | + assert_no_tag :input, :attributes => { :type => 'radio', :value => 'home_page_only'} | ||
311 | + end | ||
312 | + | ||
313 | + should 'edit main block with always option' do | ||
314 | + get :edit, :profile => 'designtestuser', :id => @b4.id | ||
315 | + assert_tag :input, :attributes => { :type => 'radio', :value => 'always'} | ||
316 | + end | ||
317 | + | ||
318 | + should 'edit main block with except_home_page option' do | ||
319 | + get :edit, :profile => 'designtestuser', :id => @b4.id | ||
320 | + assert_tag :input, :attributes => { :type => 'radio', :value => 'except_home_page'} | ||
321 | + end | ||
322 | + | ||
323 | + | ||
303 | ###################################################### | 324 | ###################################################### |
304 | # END - tests for BoxOrganizerController features | 325 | # END - tests for BoxOrganizerController features |
305 | ###################################################### | 326 | ###################################################### |
test/unit/main_block_test.rb
@@ -11,8 +11,8 @@ class MainBlockTest < ActiveSupport::TestCase | @@ -11,8 +11,8 @@ class MainBlockTest < ActiveSupport::TestCase | ||
11 | ok("MainBlock must not have a content") { MainBlock.new.content.blank? } | 11 | ok("MainBlock must not have a content") { MainBlock.new.content.blank? } |
12 | end | 12 | end |
13 | 13 | ||
14 | - should 'not be editable' do | ||
15 | - assert !MainBlock.new.editable? | 14 | + should 'be editable' do |
15 | + assert MainBlock.new.editable? | ||
16 | end | 16 | end |
17 | 17 | ||
18 | end | 18 | end |