Commit 84208b3af651bcf1514d4c55ad2ba752f8b10941

Authored by Eduardo Passos
Committed by Rodrigo Souto
1 parent 320f1f19

Add checkbox to open highlights block in a new window

Closes !511
app/helpers/block_helper.rb
... ... @@ -14,6 +14,7 @@ module BlockHelper
14 14 </td>
15 15 <td>#{text_field_tag 'block[images][][address]', image[:address], :class => 'highlight-address', :size => 20}</td>
16 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 18 </tr><tr class=\"image-title\" data-row-number='#{row_number}'>
18 19 <td colspan=\"3\"><label>#{
19 20 content_tag('span', _('Title')) +
... ...
app/models/highlights_block.rb
... ... @@ -15,6 +15,8 @@ class HighlightsBlock &lt; Block
15 15 if !Noosfero.root.nil? and !i[:address].start_with?(Noosfero.root + '/')
16 16 i[:address] = Noosfero.root + i[:address]
17 17 end
  18 + i[:new_window] = i[:new_window] == '1' ? true : false
  19 +
18 20 begin
19 21 file = UploadedFile.find(i[:image_id])
20 22 i[:image_src] = file.public_filename
... ...
app/views/blocks/highlights.html.erb
... ... @@ -3,7 +3,7 @@
3 3 <div class='highlights-border'>
4 4 <div class='highlights-container'>
5 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 7 <%= image_tag [Noosfero.root, img[:image_src]].join, alt: img[:title] %>
8 8 <p class="highlights-label"><%= img[:title] %></p>
9 9 </a>
... ...
app/views/box_organizer/_highlights_block.html.erb
... ... @@ -3,7 +3,7 @@
3 3 <strong><%= _('Highlights') %></strong>
4 4  
5 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 7 <% @block.images.each_with_index do |image, index| %>
8 8 <%= highlights_block_config_image_fields @block, image, index %>
9 9 <% end %>
... ...
test/unit/highlights_block_test.rb
... ... @@ -54,7 +54,19 @@ class HighlightsBlockTest &lt; ActiveSupport::TestCase
54 54 should 'remove images with blank fields' do
55 55 h = HighlightsBlock.new(:images => [{:image_id => 1, :address => '/address', :position => 1, :title => 'address'}, {:image_id => '', :address => '', :position => '', :title => ''}])
56 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 70 end
59 71  
60 72 should 'be able to update display setting' do
... ... @@ -84,7 +96,7 @@ class HighlightsBlockTest &lt; ActiveSupport::TestCase
84 96 block.save!
85 97 block.reload
86 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 100 end
89 101  
90 102 should 'list images in order' do
... ...