From ba59e8328b8b7e430b2d64e3801f682331a78d75 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Mon, 4 Aug 2014 18:31:57 -0300 Subject: [PATCH] Highlight block delete highlight row --- app/helpers/block_helper.rb | 7 ++++--- app/views/box_organizer/_highlights_block.html.erb | 4 ++-- features/highlights_block.feature | 20 +++++++++++++++++++- public/javascripts/highlight_block.js | 23 +++++++++++++++++++++-- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/app/helpers/block_helper.rb b/app/helpers/block_helper.rb index 2d0ea06..55e1d94 100644 --- a/app/helpers/block_helper.rb +++ b/app/helpers/block_helper.rb @@ -6,19 +6,20 @@ module BlockHelper content_tag 'h3', content_tag('span', h(title)), :class => tag_class end - def highlights_block_config_image_fields(block, image={}) + def highlights_block_config_image_fields(block, image={}, row_number=nil) " - + #{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} #{text_field_tag 'block[images][][address]', image[:address], :class => 'highlight-address', :size => 20} #{text_field_tag 'block[images][][position]', image[:position], :class => 'highlight-position', :size => 1} - + + #{link_to '', '#', :class=>'button icon-button icon-delete delete-highlight', :confirm=>_('Are you sure you want to remove this highlight')} " end diff --git a/app/views/box_organizer/_highlights_block.html.erb b/app/views/box_organizer/_highlights_block.html.erb index 36cc6e3..2093f44 100644 --- a/app/views/box_organizer/_highlights_block.html.erb +++ b/app/views/box_organizer/_highlights_block.html.erb @@ -4,8 +4,8 @@ - <% for image in @block.images do %> - <%= highlights_block_config_image_fields @block, image %> + <% @block.images.each_with_index do |image, index| %> + <%= highlights_block_config_image_fields @block, image, index %> <% end %>
<%= _('Image') %><%= _('Address') %><%= _('Position') %>
diff --git a/features/highlights_block.feature b/features/highlights_block.feature index 74986ed..15ae21d 100644 --- a/features/highlights_block.feature +++ b/features/highlights_block.feature @@ -16,7 +16,7 @@ Feature: Edit Highlight Block And I follow "Add a block" And I choose "Highlights" And I press "Add" - And I follow "Edit" within ".highlights-block" + And I follow "Edit" within ".highlights-block"#Need to hover the mouse on the box And I follow "New highlight" And I fill in "block_images__address" with "/" And I fill in "block_images__position" with "0" @@ -24,3 +24,21 @@ Feature: Edit Highlight Block And I press "Save" And I follow "Edit" within ".highlights-block" Then I should see "Title" + + @selenium-fixme + Scenario: Remove one saved highlight + Given I follow "Control panel" + And I follow "Edit sideboxes" + And I follow "Add a block" + And I choose "Highlights" + And I press "Add" + And I follow "Edit" within ".highlights-block" + And I follow "New highlight" + And I fill in "block_images__address" with "/" + And I fill in "block_images__position" with "0" + And I fill in "block_images__title" with "test highlights"#Need to hover the mouse on the box + And I press "Save" + And I follow "Edit" within ".highlights-block" + And I follow "" within ".delete-highlight" + And I confirm the browser dialog + Then I should not see "Title" \ No newline at end of file diff --git a/public/javascripts/highlight_block.js b/public/javascripts/highlight_block.js index b0549e8..caf0f39 100644 --- a/public/javascripts/highlight_block.js +++ b/public/javascripts/highlight_block.js @@ -1,8 +1,27 @@ function highlight_table_row(evt) { - evt.preventDefault(); - jQuery("#highlights-data-table").append(jQuery(".highlight-table-row tbody").html()); + var row_number = parseInt(jQuery("#highlights-data-table tr").last().attr("data-row-number")); + var row_data = jQuery(".highlight-table-row tbody tr").clone(); + + row_data.attr("data-row-number", row_number+1 || 0); + jQuery("#highlights-data-table").append(row_data); + jQuery(".delete-highlight").on("confirm:complete", delete_highlight); + + return false; +} + +function delete_highlight(evt, answer) { + if(answer) { + var row_number = parseInt(jQuery(this).parent().parent().attr("data-row-number")); + + if(row_number != NaN) { + jQuery("#highlights-data-table tr[data-row-number="+row_number+"]").remove(); + } + } + + return false; } jQuery(document).ready(function(){ jQuery(".new-highlight-button").click(highlight_table_row); + jQuery(".delete-highlight").on("confirm:complete", delete_highlight); }); -- libgit2 0.21.2