Commit 203c5675deeb660e8ac95bbcce896cd9e0a52403

Authored by Antonio Terceiro
2 parents 1aa6a909 ba59e832

Merge branch 'new_highlight' into 'master'

New highlight

First commit for "#3243: HighlightsBlock edit mode is not creating image fields"
http://noosfero.org/Development/ActionItem3243

Second commit for "#3260: Remove a highlight item from the list"
http://noosfero.org/Development/ActionItem3260

See merge request !290
app/helpers/block_helper.rb
... ... @@ -6,19 +6,20 @@ module BlockHelper
6 6 content_tag 'h3', content_tag('span', h(title)), :class => tag_class
7 7 end
8 8  
9   - def highlights_block_config_image_fields(block, image={})
  9 + def highlights_block_config_image_fields(block, image={}, row_number=nil)
10 10 "
11   - <tr class=\"image-data-line\">
  11 + <tr class=\"image-data-line\" data-row-number='#{row_number}'>
12 12 <td>
13 13 #{select_tag 'block[images][][image_id]', content_tag(:option) + option_groups_from_collection_for_select(block.folder_choices, :images, :name, :id, :name, image[:image_id].to_i).html_safe}
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   - </tr><tr class=\"image-title\">
  17 + </tr><tr class=\"image-title\" data-row-number='#{row_number}'>
18 18 <td colspan=\"3\"><label>#{
19 19 content_tag('span', _('Title')) +
20 20 text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45)
21 21 }</label></td>
  22 + <td>#{link_to '', '#', :class=>'button icon-button icon-delete delete-highlight', :confirm=>_('Are you sure you want to remove this highlight')}</td>
22 23 </tr>
23 24 "
24 25 end
... ...
app/models/highlights_block.rb
1 1 class HighlightsBlock < Block
2 2  
3   - attr_accessible :images
  3 + attr_accessible :images, :interval, :shuffle, :navigation
4 4  
5 5 settings_items :images, :type => Array, :default => []
6 6 settings_items :interval, :type => 'integer', :default => 4
... ...
app/views/box_organizer/_highlights_block.html.erb
  1 +<%= javascript_include_tag "highlight_block" %>
  2 +
1 3 <strong><%= _('Highlights') %></strong>
2 4  
3 5 <table class="noborder"><tbody id="highlights-data-table">
4 6 <tr><th><%= _('Image') %></th><th><%= _('Address') %></th><th><%= _('Position') %></th></tr>
5   - <% for image in @block.images do %>
6   - <%= highlights_block_config_image_fields @block, image %>
  7 + <% @block.images.each_with_index do |image, index| %>
  8 + <%= highlights_block_config_image_fields @block, image, index %>
7 9 <% end %>
8 10 </tbody></table>
9 11  
10   -<%= link_to_function(_('New highlight'), nil, :class => 'button icon-add with-text') do |page|
11   - page.insert_html :bottom, 'highlights-data-table', highlights_block_config_image_fields(@block)
12   -end %>
  12 +<table class="hidden highlight-table-row">
  13 + <tbody>
  14 + <%= highlights_block_config_image_fields(@block) %>
  15 + </tbody>
  16 +</table>
  17 +
  18 +<%= link_to(_('New highlight'), '#', :class => 'button icon-add with-text new-highlight-button')%>
13 19  
14 20 <%= labelled_form_field _('Image transition:'), select('block', 'interval', [[_('No automatic transition'), 0]] + [1, 2, 3, 4, 5, 10, 20, 30, 60].map {|item| [n_('Every 1 second', 'Every %d seconds', item) % item, item]}) %>
15 21  
... ...
features/highlights_block.feature 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +Feature: Edit Highlight Block
  2 + As a user
  3 + I want to edit the highlight block
  4 +
  5 + Background:
  6 + Given I am on the homepage
  7 + And the following users
  8 + | login | name |
  9 + | jose | Jose Silva |
  10 + And I am logged in as "jose"
  11 +
  12 + @selenium
  13 + Scenario: Add new highlight
  14 + Given I follow "Control panel"
  15 + And I follow "Edit sideboxes"
  16 + And I follow "Add a block"
  17 + And I choose "Highlights"
  18 + And I press "Add"
  19 + And I follow "Edit" within ".highlights-block"#Need to hover the mouse on the box
  20 + And I follow "New highlight"
  21 + And I fill in "block_images__address" with "/"
  22 + And I fill in "block_images__position" with "0"
  23 + And I fill in "block_images__title" with "test highlights"
  24 + And I press "Save"
  25 + And I follow "Edit" within ".highlights-block"
  26 + Then I should see "Title"
  27 +
  28 + @selenium-fixme
  29 + Scenario: Remove one saved highlight
  30 + Given I follow "Control panel"
  31 + And I follow "Edit sideboxes"
  32 + And I follow "Add a block"
  33 + And I choose "Highlights"
  34 + And I press "Add"
  35 + And I follow "Edit" within ".highlights-block"
  36 + And I follow "New highlight"
  37 + And I fill in "block_images__address" with "/"
  38 + And I fill in "block_images__position" with "0"
  39 + And I fill in "block_images__title" with "test highlights"#Need to hover the mouse on the box
  40 + And I press "Save"
  41 + And I follow "Edit" within ".highlights-block"
  42 + And I follow "" within ".delete-highlight"
  43 + And I confirm the browser dialog
  44 + Then I should not see "Title"
0 45 \ No newline at end of file
... ...
public/javascripts/highlight_block.js 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +function highlight_table_row(evt) {
  2 + var row_number = parseInt(jQuery("#highlights-data-table tr").last().attr("data-row-number"));
  3 + var row_data = jQuery(".highlight-table-row tbody tr").clone();
  4 +
  5 + row_data.attr("data-row-number", row_number+1 || 0);
  6 + jQuery("#highlights-data-table").append(row_data);
  7 + jQuery(".delete-highlight").on("confirm:complete", delete_highlight);
  8 +
  9 + return false;
  10 +}
  11 +
  12 +function delete_highlight(evt, answer) {
  13 + if(answer) {
  14 + var row_number = parseInt(jQuery(this).parent().parent().attr("data-row-number"));
  15 +
  16 + if(row_number != NaN) {
  17 + jQuery("#highlights-data-table tr[data-row-number="+row_number+"]").remove();
  18 + }
  19 + }
  20 +
  21 + return false;
  22 +}
  23 +
  24 +jQuery(document).ready(function(){
  25 + jQuery(".new-highlight-button").click(highlight_table_row);
  26 + jQuery(".delete-highlight").on("confirm:complete", delete_highlight);
  27 +});
... ...