Commit ba59e8328b8b7e430b2d64e3801f682331a78d75

Authored by Fabio Teixeira
1 parent 52f7d6cb

Highlight block delete highlight row

(ActionItem3260)

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
app/helpers/block_helper.rb
@@ -6,19 +6,20 @@ module BlockHelper @@ -6,19 +6,20 @@ module BlockHelper
6 content_tag 'h3', content_tag('span', h(title)), :class => tag_class 6 content_tag 'h3', content_tag('span', h(title)), :class => tag_class
7 end 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 <td> 12 <td>
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} 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 </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 - </tr><tr class=\"image-title\"> 17 + </tr><tr class=\"image-title\" data-row-number='#{row_number}'>
18 <td colspan=\"3\"><label>#{ 18 <td colspan=\"3\"><label>#{
19 content_tag('span', _('Title')) + 19 content_tag('span', _('Title')) +
20 text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45) 20 text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45)
21 }</label></td> 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 </tr> 23 </tr>
23 " 24 "
24 end 25 end
app/views/box_organizer/_highlights_block.html.erb
@@ -4,8 +4,8 @@ @@ -4,8 +4,8 @@
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></tr>
7 - <% for image in @block.images do %>  
8 - <%= 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 %>
9 <% end %> 9 <% end %>
10 </tbody></table> 10 </tbody></table>
11 11
features/highlights_block.feature
@@ -16,7 +16,7 @@ Feature: Edit Highlight Block @@ -16,7 +16,7 @@ Feature: Edit Highlight Block
16 And I follow "Add a block" 16 And I follow "Add a block"
17 And I choose "Highlights" 17 And I choose "Highlights"
18 And I press "Add" 18 And I press "Add"
19 - And I follow "Edit" within ".highlights-block" 19 + And I follow "Edit" within ".highlights-block"#Need to hover the mouse on the box
20 And I follow "New highlight" 20 And I follow "New highlight"
21 And I fill in "block_images__address" with "/" 21 And I fill in "block_images__address" with "/"
22 And I fill in "block_images__position" with "0" 22 And I fill in "block_images__position" with "0"
@@ -24,3 +24,21 @@ Feature: Edit Highlight Block @@ -24,3 +24,21 @@ Feature: Edit Highlight Block
24 And I press "Save" 24 And I press "Save"
25 And I follow "Edit" within ".highlights-block" 25 And I follow "Edit" within ".highlights-block"
26 Then I should see "Title" 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"
27 \ No newline at end of file 45 \ No newline at end of file
public/javascripts/highlight_block.js
1 function highlight_table_row(evt) { 1 function highlight_table_row(evt) {
2 - evt.preventDefault();  
3 - jQuery("#highlights-data-table").append(jQuery(".highlight-table-row tbody").html()); 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;
4 } 22 }
5 23
6 jQuery(document).ready(function(){ 24 jQuery(document).ready(function(){
7 jQuery(".new-highlight-button").click(highlight_table_row); 25 jQuery(".new-highlight-button").click(highlight_table_row);
  26 + jQuery(".delete-highlight").on("confirm:complete", delete_highlight);
8 }); 27 });