var initProductRuleSourceField = function(){ $products_source_field = jQuery('.products_rule_products_source_field input'); $products_source_field.click(function() { $rule_container = jQuery(this).parents('.promotion-rule'); if(this.checked){ if(this.value == 'manual'){ $rule_container.find('.products_rule_products').show(); $rule_container.find('.products_rule_product_group').hide(); } else { $rule_container.find('.products_rule_products').hide(); $rule_container.find('.products_rule_product_group').show(); } } }); $products_source_field.each(function() { $(this).triggerHandler('click'); }); }; var initProductActions = function(){ $('.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'); var originalType = $type_select.val(); $warning.hide(); $type_select.change(function(){ if( $(this).val() == originalType ){ $warning.hide(); $settings.show(); $settings.find('input').removeAttr('disabled'); } else { $warning.show(); $settings.hide(); $settings.find('input').attr('disabled', 'disabled'); } }); }); // // CreateLineItems Promotion Action // ( function(){ // Autocomplete product and populate variant select if($('.promotion_action.create_line_items ').is('*')){ $(".promotion_action.create_line_items input[name='add_product_name']").autocomplete("/admin/products.json?authenticity_token=" + $('meta[name=csrf-token]').attr("content"), { parse: prep_autocomplete_data, formatItem: function(item) { return format_autocomplete(item); } }).result(function(event, data, formatted) { if(data){ // $('#add_product_id').val(data.product.id); var url = "/admin/products/" + data.product.permalink + "/variants.json?authenticity_token=" + $('meta[name=csrf-token]').attr("content"); var $variant_select = $("select[name='add_line_item_variant_id']"); $variant_select.html(''); $.getJSON(url, {}, function(variants_data){ $.each(variants_data, function(){ $variant_select.append($("