Permalink
Browse files

Fix issue where removing a single line item from a promotion ended up

removing ALL the line items from it

Fixes #1274
  • Loading branch information...
radar committed Jun 4, 2012
1 parent eac66f6 commit c25de2997529909bc7ca9aa936a612f8587a72b1
@@ -40,19 +40,15 @@ var initProductActions = function(){
// Remove line item
var setupRemoveLineItems = function(){
- $(".promotion_action.create_line_items table img").unbind('click').click(function(){
- var $container = $(this).parents('.promotion_action');
- var $hiddenField = $container.find("input[type='hidden']");
- var $row = $(this).parents('tr');
- var index = $row.parents('table').find('tr').index($row.get(0));
- // Remove variant_id quantity pair from the string
- var items = _($hiddenField.val().split(',')).compact();
- items.splice(index - 1, 1);
- $hiddenField.val(items.join(','));
+ $(".remove_promotion_line_item").click(function(){
+ line_items_el = $($('.line_items_string')[0])
+ finder = RegExp($(this).data("variant-id") + "x\\d+")
+ line_items_el.val(line_items_el.val().replace(finder, ""))
$(this).parents('tr').remove();
hideOrShowItemTables();
});
};
+
setupRemoveLineItems();
// Add line item to list
$(".promotion_action.create_line_items button.add").unbind('click').click(function(e){
@@ -13,7 +13,7 @@
<%= item.quantity %>
</td>
<td>
- <%= image_tag 'admin/icons/cross.png' %>
+ <%= image_tag 'admin/icons/cross.png', :class => "remove_promotion_line_item", :data => { :variant_id => item.variant_id } %>
</td>
</tr>
<% end %>

0 comments on commit c25de29

Please sign in to comment.