app/assets/javascripts/admin/promotions.js in spree_promo-1.0.0.rc2 vs app/assets/javascripts/admin/promotions.js in spree_promo-1.0.0.rc3

- old
+ new

@@ -20,10 +20,12 @@ }; var initProductActions = function(){ + $("#add_product_name").product_autocomplete(); + $('.calculator-fields').each(function(){ var $fields_container = $(this); var $type_select = $fields_container.find('.type-select'); var $settings = $fields_container.find('.settings'); var $warning = $fields_container.find('.warning'); @@ -41,11 +43,10 @@ $settings.find('input').attr('disabled', 'disabled'); } }); }); - // // CreateLineItems Promotion Action // ( function(){ var hideOrShowItemTables = function(){ @@ -74,21 +75,21 @@ hideOrShowItemTables(); }); }; setupRemoveLineItems(); // Add line item to list - $(".promotion_action.create_line_items button.add").live('click',function(e){ + $(".promotion_action.create_line_items button.add").unbind('click').click(function(e){ var $container = $(this).parents('.promotion_action'); var product_name = $container.find("input[name='add_product_name']").val(); var variant_id = $container.find("input[name='add_variant_id']").val(); var quantity = $container.find("input[name='add_quantity']").val(); if(variant_id){ // Add to the table var newRow = "<tr><td>" + product_name + "</td><td>" + quantity + "</td><td><img src='/assets/admin/icons/cross.png' /></td></tr>"; $container.find('table').append(newRow); // Add to serialized string in hidden text field - var $hiddenField = $container.find("input[type='hidden']"); + var $hiddenField = $container.find(".line_items_string"); $hiddenField.val($hiddenField.val() + "," + variant_id + "x" + quantity); setupRemoveLineItems(); hideOrShowItemTables(); } return false; @@ -99,9 +100,17 @@ } $(document).ready(function() { initProductRuleSourceField(); initProductActions(); + + // toggle fields for specific events + $('#promotion_event_name').change(function() { + $('#promotion_code_field').toggle($('#promotion_event_name').val() == 'spree.checkout.coupon_code_added'); + $('#promotion_path_field').toggle($('#promotion_event_name').val() == 'spree.content.visited'); + }); + $('#promotion_event_name').change(); + });