Commit ba59e8328b8b7e430b2d64e3801f682331a78d75
1 parent
52f7d6cb
Exists in
master
and in
27 other branches
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>
Showing
4 changed files
with
46 additions
and
8 deletions
Show diff stats
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/views/box_organizer/_highlights_block.html.erb
| ... | ... | @@ -4,8 +4,8 @@ |
| 4 | 4 | |
| 5 | 5 | <table class="noborder"><tbody id="highlights-data-table"> |
| 6 | 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 | 9 | <% end %> |
| 10 | 10 | </tbody></table> |
| 11 | 11 | ... | ... |
features/highlights_block.feature
| ... | ... | @@ -16,7 +16,7 @@ Feature: Edit Highlight Block |
| 16 | 16 | And I follow "Add a block" |
| 17 | 17 | And I choose "Highlights" |
| 18 | 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 | 20 | And I follow "New highlight" |
| 21 | 21 | And I fill in "block_images__address" with "/" |
| 22 | 22 | And I fill in "block_images__position" with "0" |
| ... | ... | @@ -24,3 +24,21 @@ Feature: Edit Highlight Block |
| 24 | 24 | And I press "Save" |
| 25 | 25 | And I follow "Edit" within ".highlights-block" |
| 26 | 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 | 45 | \ No newline at end of file | ... | ... |
public/javascripts/highlight_block.js
| 1 | 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 | 24 | jQuery(document).ready(function(){ |
| 7 | 25 | jQuery(".new-highlight-button").click(highlight_table_row); |
| 26 | + jQuery(".delete-highlight").on("confirm:complete", delete_highlight); | |
| 8 | 27 | }); | ... | ... |