Commit 84208b3af651bcf1514d4c55ad2ba752f8b10941
Committed by
Rodrigo Souto
1 parent
320f1f19
Exists in
web_steps_improvements
and in
9 other branches
Add checkbox to open highlights block in a new window
Closes !511
Showing
5 changed files
with
19 additions
and
4 deletions
Show diff stats
app/helpers/block_helper.rb
@@ -14,6 +14,7 @@ module BlockHelper | @@ -14,6 +14,7 @@ module BlockHelper | ||
14 | </td> | 14 | </td> |
15 | <td>#{text_field_tag 'block[images][][address]', image[:address], :class => 'highlight-address', :size => 20}</td> | 15 | <td>#{text_field_tag 'block[images][][address]', image[:address], :class => 'highlight-address', :size => 20}</td> |
16 | <td>#{text_field_tag 'block[images][][position]', image[:position], :class => 'highlight-position', :size => 1}</td> | 16 | <td>#{text_field_tag 'block[images][][position]', image[:position], :class => 'highlight-position', :size => 1}</td> |
17 | + <td>#{check_box_tag 'block[images][][new_window]', '1', image[:new_window], :class => 'highlight-new_window', :size => 1}</td> | ||
17 | </tr><tr class=\"image-title\" data-row-number='#{row_number}'> | 18 | </tr><tr class=\"image-title\" data-row-number='#{row_number}'> |
18 | <td colspan=\"3\"><label>#{ | 19 | <td colspan=\"3\"><label>#{ |
19 | content_tag('span', _('Title')) + | 20 | content_tag('span', _('Title')) + |
app/models/highlights_block.rb
@@ -15,6 +15,8 @@ class HighlightsBlock < Block | @@ -15,6 +15,8 @@ class HighlightsBlock < Block | ||
15 | if !Noosfero.root.nil? and !i[:address].start_with?(Noosfero.root + '/') | 15 | if !Noosfero.root.nil? and !i[:address].start_with?(Noosfero.root + '/') |
16 | i[:address] = Noosfero.root + i[:address] | 16 | i[:address] = Noosfero.root + i[:address] |
17 | end | 17 | end |
18 | + i[:new_window] = i[:new_window] == '1' ? true : false | ||
19 | + | ||
18 | begin | 20 | begin |
19 | file = UploadedFile.find(i[:image_id]) | 21 | file = UploadedFile.find(i[:image_id]) |
20 | i[:image_src] = file.public_filename | 22 | i[:image_src] = file.public_filename |
app/views/blocks/highlights.html.erb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | <div class='highlights-border'> | 3 | <div class='highlights-border'> |
4 | <div class='highlights-container'> | 4 | <div class='highlights-container'> |
5 | <% block.featured_images.each do |img| %> | 5 | <% block.featured_images.each do |img| %> |
6 | - <a href="<%= img[:address] %>" title="<%= img[:title] %>" class="highlights-image-link"> | 6 | + <a href="<%= img[:address] %>" <%= 'target="_blank"' if img[:new_window] %> title="<%= img[:title] %>" class="highlights-image-link"> |
7 | <%= image_tag [Noosfero.root, img[:image_src]].join, alt: img[:title] %> | 7 | <%= image_tag [Noosfero.root, img[:image_src]].join, alt: img[:title] %> |
8 | <p class="highlights-label"><%= img[:title] %></p> | 8 | <p class="highlights-label"><%= img[:title] %></p> |
9 | </a> | 9 | </a> |
app/views/box_organizer/_highlights_block.html.erb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | <strong><%= _('Highlights') %></strong> | 3 | <strong><%= _('Highlights') %></strong> |
4 | 4 | ||
5 | <table class="noborder"><tbody id="highlights-data-table"> | 5 | <table class="noborder"><tbody id="highlights-data-table"> |
6 | - <tr><th><%= _('Image') %></th><th><%= _('Address') %></th><th><%= _('Position') %></th></tr> | 6 | + <tr><th><%= _('Image') %></th><th><%= _('Address') %></th><th><%= _('Position') %></th><th><%= _('New Window') %></th></tr> |
7 | <% @block.images.each_with_index do |image, index| %> | 7 | <% @block.images.each_with_index do |image, index| %> |
8 | <%= highlights_block_config_image_fields @block, image, index %> | 8 | <%= highlights_block_config_image_fields @block, image, index %> |
9 | <% end %> | 9 | <% end %> |
test/unit/highlights_block_test.rb
@@ -54,7 +54,19 @@ class HighlightsBlockTest < ActiveSupport::TestCase | @@ -54,7 +54,19 @@ class HighlightsBlockTest < ActiveSupport::TestCase | ||
54 | should 'remove images with blank fields' do | 54 | should 'remove images with blank fields' do |
55 | h = HighlightsBlock.new(:images => [{:image_id => 1, :address => '/address', :position => 1, :title => 'address'}, {:image_id => '', :address => '', :position => '', :title => ''}]) | 55 | h = HighlightsBlock.new(:images => [{:image_id => 1, :address => '/address', :position => 1, :title => 'address'}, {:image_id => '', :address => '', :position => '', :title => ''}]) |
56 | h.save! | 56 | h.save! |
57 | - assert_equal [{:image_id => 1, :address => '/address', :position => 1, :title => 'address', :image_src => nil}], h.images | 57 | + assert_equal [{:image_id => 1, :address => '/address', :position => 1, :title => 'address', :new_window => false, :image_src => nil}], h.images |
58 | + end | ||
59 | + | ||
60 | + should 'replace 1 and 0 by true and false in new_window attribute' do | ||
61 | + image1 = {:image_id => 1, :address => '/address-1', :position => 1, :title => 'address-1', :new_window => '0'} | ||
62 | + image2 = {:image_id => 2, :address => '/address-2', :position => 2, :title => 'address-2', :new_window => '1'} | ||
63 | + h = HighlightsBlock.new(:images => [image1, image2]) | ||
64 | + h.save! | ||
65 | + image1[:new_window] = false | ||
66 | + image1[:image_src] = nil | ||
67 | + image2[:new_window] = true | ||
68 | + image2[:image_src] = nil | ||
69 | + assert_equivalent [image1, image2], h.images | ||
58 | end | 70 | end |
59 | 71 | ||
60 | should 'be able to update display setting' do | 72 | should 'be able to update display setting' do |
@@ -84,7 +96,7 @@ class HighlightsBlockTest < ActiveSupport::TestCase | @@ -84,7 +96,7 @@ class HighlightsBlockTest < ActiveSupport::TestCase | ||
84 | block.save! | 96 | block.save! |
85 | block.reload | 97 | block.reload |
86 | assert_equal 2, block.images.count | 98 | assert_equal 2, block.images.count |
87 | - assert_equal [{:image_id => 1, :address => '/address', :position => 1, :title => 'address', :image_src => 'address'}], block.featured_images | 99 | + assert_equal [{:image_id => 1, :address => '/address', :position => 1, :title => 'address', :new_window => false, :image_src => 'address'}], block.featured_images |
88 | end | 100 | end |
89 | 101 | ||
90 | should 'list images in order' do | 102 | should 'list images in order' do |