diff --git a/assets/js/admin/write-panels.js b/assets/js/admin/write-panels.js index bd7b099e7d6..f10e8884191 100644 --- a/assets/js/admin/write-panels.js +++ b/assets/js/admin/write-panels.js @@ -45,13 +45,11 @@ jQuery( function($){ }); - - - $('button.calc_line_costs').live('click', function(){ + $('button.calc_line_taxes').live('click', function(){ // Block write panel $('.woocommerce_order_items_wrapper').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); - var answer = confirm(woocommerce_writepanel_params.calc_line_cost); + var answer = confirm(woocommerce_writepanel_params.calc_line_taxes); if (answer) { @@ -67,77 +65,16 @@ jQuery( function($){ var postcode = $('#_billing_postcode').val(); } - $items.each(function( idx ){ - - var $row = $(this); - - var data = { - action: 'woocommerce_calc_line_cost', - unit_cost: $row.find('.cost input').val(), - unit_tax: $row.find('.tax input').val(), - quantity: $row.find('.quantity input').val(), - tax_class: $row.find('.tax_class select').val(), - tax_status: $row.find('.tax_status select').val(), - country: country, - state: state, - postcode: postcode, - security: woocommerce_writepanel_params.calc_totals_nonce - }; - - $.post( woocommerce_writepanel_params.ajax_url, data, function(response) { - - result = jQuery.parseJSON( response ); - $row.find('.line_cost input').val( result.cost ); - $row.find('.line_tax input').val( result.tax ); - - if (idx == ($items.size() - 1)) { - $('.woocommerce_order_items_wrapper').unblock(); - } - - }); - - }); - - } else { - $('.woocommerce_order_items_wrapper').unblock(); - } - return false; - }).hover(function() { - $('#order_items_list .line_cost input, #order_items_list .line_tax input').css('background-color', '#d8c8d2'); - }, function() { - $('#order_items_list .line_cost input, #order_items_list .line_tax input').css('background-color', ''); - }); - - $('button.calc_line_taxes').live('click', function(){ - // Block write panel - $('.woocommerce_order_items_wrapper').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); - - var answer = confirm(woocommerce_writepanel_params.calc_line_taxes); - - if (answer) { - - var $items = $('#order_items_list tr.item'); - - var country = $('#_shipping_country').val(); - if (country) { - var state = $('#_shipping_state').val(); - var postcode = $('#_shipping_postcode').val(); - } else { - country = $('#_billing_country').val(); - var state = $('#_billing_state').val(); - var postcode = $('#_billing_postcode').val(); - } - $items.each(function( idx ){ var $row = $(this); var data = { action: 'woocommerce_calc_line_taxes', - unit_cost: $row.find('.cost input').val(), - line_cost: $row.find('.line_cost input').val(), - tax_class: $row.find('.tax_class select').val(), - tax_status: $row.find('.tax_status select').val(), + item_id: $row.find('input.item_id').val(), + line_subtotal: $row.find('input.line_subtotal').val(), + line_total: $row.find('input.line_total').val(), + tax_class: $row.find('select.tax_class').val(), country: country, state: state, postcode: postcode, @@ -147,8 +84,8 @@ jQuery( function($){ $.post( woocommerce_writepanel_params.ajax_url, data, function(response) { result = jQuery.parseJSON( response ); - $row.find('.tax input').val( result.unit ); - $row.find('.line_tax input').val( result.line ); + $row.find('input.line_subtotal_tax').val( result.line_subtotal_tax ); + $row.find('input.line_tax').val( result.line_tax ); if (idx == ($items.size() - 1)) { $('.woocommerce_order_items_wrapper').unblock(); @@ -163,11 +100,12 @@ jQuery( function($){ } return false; }).hover(function() { - $('#order_items_list .line_tax input, #order_items_list .tax input').css('background-color', '#d8c8d2'); + $('#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax').css('background-color', '#d8c8d2'); }, function() { - $('#order_items_list .line_tax input, #order_items_list .tax input').css('background-color', ''); + $('#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax').css('background-color', ''); }); + $('button.calc_totals').live('click', function(){ // Block write panel $('#woocommerce-order-totals').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); @@ -177,9 +115,10 @@ jQuery( function($){ if (answer) { // Get row totals - var unit_costs = 0; - var unit_taxes = 0; - var line_costs = 0; + var line_subtotals = 0; + var line_subtotal_taxes = 0; + var line_totals = 0; + var cart_discount = 0; var cart_tax = 0; var order_shipping = parseFloat( $('#_order_shipping').val() ); var order_shipping_tax = parseFloat( $('#_order_shipping_tax').val() ); @@ -191,22 +130,20 @@ jQuery( function($){ $('#order_items_list tr.item').each(function(){ - var unit_cost = parseFloat( $(this).find('.cost input').val() ); - var unit_tax = parseFloat( $(this).find('.tax input').val() ); - var quantity = parseInt( $(this).find('.quantity input').val() ); - var line_cost = parseFloat( $(this).find('.line_cost input').val() ); - var line_tax = parseFloat( $(this).find('.line_tax input').val() ); + var line_subtotal = parseFloat( $(this).find('input.line_subtotal').val() ); + var line_subtotal_tax = parseFloat( $(this).find('input.line_subtotal_tax').val() ); + var line_total = parseFloat( $(this).find('input.line_total').val() ); + var line_tax = parseFloat( $(this).find('input.line_tax').val() ); - unit_costs = unit_costs + parseFloat( unit_cost * quantity ); - unit_taxes = unit_taxes + parseFloat( unit_tax * quantity ); - - line_costs = line_costs + line_cost; + line_subtotals = parseFloat( line_subtotals + line_subtotal ); + line_subtotal_taxes = parseFloat( line_subtotal_taxes + line_subtotal_tax ); + line_totals = parseFloat( line_totals + line_total ); if (woocommerce_writepanel_params.round_at_subtotal=='no') { line_tax = parseFloat( line_tax.toFixed( 2 ) ); } - cart_tax = cart_tax + line_tax; + cart_tax = parseFloat( cart_tax + line_tax ); }); @@ -216,11 +153,12 @@ jQuery( function($){ } // Cart discount - var cart_discount = ( (unit_costs + unit_taxes) - (line_costs + cart_tax) ); + var cart_discount = ( (line_subtotals + line_subtotal_taxes) - (line_totals + cart_tax) ); + if (cart_discount<0) cart_discount = 0; cart_discount = cart_discount.toFixed( 2 ); // Total - var order_total = line_costs + cart_tax + order_shipping + order_shipping_tax - order_discount; + var order_total = line_totals + cart_tax + order_shipping + order_shipping_tax - order_discount; order_total = order_total.toFixed( 2 ); // Set fields diff --git a/assets/js/admin/write-panels.min.js b/assets/js/admin/write-panels.min.js index 96abf8dde68..12db9750491 100644 --- a/assets/js/admin/write-panels.min.js +++ b/assets/js/admin/write-panels.min.js @@ -1 +1 @@ -jQuery(function(a){function e(){a("table.woocommerce_attributes, table.woocommerce_variable_attributes").each(function(){a("tbody tr",this).size()==0?a(this).parent().hide():a(this).parent().show()})}function f(){a("#attributes_list tr").each(function(b,c){a(".attribute_position",c).val(parseInt(a(c).index("#attributes_list tr")))})}a("#upsell_product_data").bind("keypress",function(a){if(a.keyCode==13)return!1});a("ul.tabs").show();a("div.panel-wrap").each(function(){a("div.panel:not(div.panel:first)",this).hide()});a("ul.tabs a").click(function(){var b=a(this).closest("div.panel-wrap");a("ul.tabs li",b).removeClass("active");a(this).parent().addClass("active");a("div.panel",b).hide();a(a(this).attr("href")).show();return!1});a("a.edit_address").click(function(){a(this).hide();a(this).closest(".order_data").find("div.address").hide();a(this).closest(".order_data").find("div.edit_address").show()});jQuery("select.chosen_select").chosen();jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"});a("#order_items_list .remove_row").live("click",function(){var b=confirm(woocommerce_writepanel_params.remove_item_notice);if(b){a(this).closest("tr.item").hide();a("input",a(this).closest("tr.item")).val("")}return!1});a("button.calc_line_costs").live("click",function(){a(".woocommerce_order_items_wrapper").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=confirm(woocommerce_writepanel_params.calc_line_cost);if(b){var c=a("#order_items_list tr.item"),d=a("#_shipping_country").val();if(d)var e=a("#_shipping_state").val(),f=a("#_shipping_postcode").val();else{d=a("#_billing_country").val();var e=a("#_billing_state").val(),f=a("#_billing_postcode").val()}c.each(function(b){var g=a(this),h={action:"woocommerce_calc_line_cost",unit_cost:g.find(".cost input").val(),unit_tax:g.find(".tax input").val(),quantity:g.find(".quantity input").val(),tax_class:g.find(".tax_class select").val(),tax_status:g.find(".tax_status select").val(),country:d,state:e,postcode:f,security:woocommerce_writepanel_params.calc_totals_nonce};a.post(woocommerce_writepanel_params.ajax_url,h,function(d){result=jQuery.parseJSON(d);g.find(".line_cost input").val(result.cost);g.find(".line_tax input").val(result.tax);b==c.size()-1&&a(".woocommerce_order_items_wrapper").unblock()})})}else a(".woocommerce_order_items_wrapper").unblock();return!1}).hover(function(){a("#order_items_list .line_cost input, #order_items_list .line_tax input").css("background-color","#d8c8d2")},function(){a("#order_items_list .line_cost input, #order_items_list .line_tax input").css("background-color","")});a("button.calc_line_taxes").live("click",function(){a(".woocommerce_order_items_wrapper").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=confirm(woocommerce_writepanel_params.calc_line_taxes);if(b){var c=a("#order_items_list tr.item"),d=a("#_shipping_country").val();if(d)var e=a("#_shipping_state").val(),f=a("#_shipping_postcode").val();else{d=a("#_billing_country").val();var e=a("#_billing_state").val(),f=a("#_billing_postcode").val()}c.each(function(b){var g=a(this),h={action:"woocommerce_calc_line_taxes",unit_cost:g.find(".cost input").val(),line_cost:g.find(".line_cost input").val(),tax_class:g.find(".tax_class select").val(),tax_status:g.find(".tax_status select").val(),country:d,state:e,postcode:f,security:woocommerce_writepanel_params.calc_totals_nonce};a.post(woocommerce_writepanel_params.ajax_url,h,function(d){result=jQuery.parseJSON(d);g.find(".tax input").val(result.unit);g.find(".line_tax input").val(result.line);b==c.size()-1&&a(".woocommerce_order_items_wrapper").unblock()})})}else a(".woocommerce_order_items_wrapper").unblock();return!1}).hover(function(){a("#order_items_list .line_tax input, #order_items_list .tax input").css("background-color","#d8c8d2")},function(){a("#order_items_list .line_tax input, #order_items_list .tax input").css("background-color","")});a("button.calc_totals").live("click",function(){a("#woocommerce-order-totals").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=confirm(woocommerce_writepanel_params.calc_totals);if(b){var c=0,d=0,e=0,f=0,g=parseFloat(a("#_order_shipping").val()),h=parseFloat(a("#_order_shipping_tax").val()),i=parseFloat(a("#_order_discount").val());g||(g=0);h||(h=0);i||(i=0);a("#order_items_list tr.item").each(function(){var b=parseFloat(a(this).find(".cost input").val()),g=parseFloat(a(this).find(".tax input").val()),h=parseInt(a(this).find(".quantity input").val()),i=parseFloat(a(this).find(".line_cost input").val()),j=parseFloat(a(this).find(".line_tax input").val());c+=parseFloat(b*h);d+=parseFloat(g*h);e+=i;woocommerce_writepanel_params.round_at_subtotal=="no"&&(j=parseFloat(j.toFixed(2)));f+=j});woocommerce_writepanel_params.round_at_subtotal=="yes"&&(f=parseFloat(f.toFixed(2)));var j=c+d-(e+f);j=j.toFixed(2);var k=e+f+g+h-i;k=k.toFixed(2);a("#_cart_discount").val(j);a("#_order_tax").val(f);a("#_order_total").val(k);a("ul.tax_rows").empty();a("#woocommerce-order-totals").unblock()}else a("#woocommerce-order-totals").unblock();return!1}).hover(function(){a("#woocommerce-order-totals .calculated").css("background-color","#d8c8d2")},function(){a("#woocommerce-order-totals .calculated").css("background-color","")});a("button.add_shop_order_item").click(function(){var b=a("select.add_item_id").val();if(b){a("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var c=a("table.woocommerce_order_items tbody tr.item").size(),d={action:"woocommerce_add_order_item",item_to_add:a("select.add_item_id").val(),index:c,security:woocommerce_writepanel_params.add_order_item_nonce};a.post(woocommerce_writepanel_params.ajax_url,d,function(b){a("table.woocommerce_order_items tbody#order_items_list").append(b);a("table.woocommerce_order_items").unblock();a("select.add_item_id").css("border-color","").val("");jQuery(".tips").tipTip({attribute:"tip",fadeIn:50,fadeOut:50})})}else a("select.add_item_id").css("border-color","red")});a("button.add_meta").live("click",function(){var b=a(this).closest("tr.item").attr("rel");a(this).closest("table.meta").find(".meta_items").append('');return!1});a("button.remove_meta").live("click",function(){var b=confirm("Remove this meta key?");b&&a(this).closest("tr").remove();return!1});a("button.load_customer_billing").live("click",function(){var b=confirm(woocommerce_writepanel_params.load_billing);if(b){var c=a("#customer_user").val();if(!c){alert(woocommerce_writepanel_params.no_customer_selected);return!1}var d={user_id:c,type_to_load:"billing",action:"woocommerce_get_customer_details",security:woocommerce_writepanel_params.get_customer_details_nonce};a(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});a.ajax({url:woocommerce_writepanel_params.ajax_url,data:d,type:"POST",success:function(b){var c=jQuery.parseJSON(b);if(c){a("input#_billing_first_name").val(c.billing_first_name);a("input#_billing_last_name").val(c.billing_last_name);a("input#_billing_company").val(c.billing_company);a("input#_billing_address_1").val(c.billing_address_1);a("input#_billing_address_2").val(c.billing_address_2);a("input#_billing_city").val(c.billing_city);a("input#_billing_postcode").val(c.billing_postcode);a("input#_billing_country").val(c.billing_country);a("input#_billing_state").val(c.billing_state);a("input#_billing_email").val(c.billing_email);a("input#_billing_phone").val(c.billing_phone)}a(".edit_address").unblock()}})}return!1});a("button.load_customer_shipping").live("click",function(){var b=confirm(woocommerce_writepanel_params.load_shipping);if(b){var c=a("#customer_user").val();if(!c){alert(woocommerce_writepanel_params.no_customer_selected);return!1}var d={user_id:c,type_to_load:"shipping",action:"woocommerce_get_customer_details",security:woocommerce_writepanel_params.get_customer_details_nonce};a(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});a.ajax({url:woocommerce_writepanel_params.ajax_url,data:d,type:"POST",success:function(b){var c=jQuery.parseJSON(b);if(c){a("input#_shipping_first_name").val(c.shipping_first_name);a("input#_shipping_last_name").val(c.shipping_last_name);a("input#_shipping_company").val(c.shipping_company);a("input#_shipping_address_1").val(c.shipping_address_1);a("input#_shipping_address_2").val(c.shipping_address_2);a("input#_shipping_city").val(c.shipping_city);a("input#_shipping_postcode").val(c.shipping_postcode);a("input#_shipping_country").val(c.shipping_country);a("input#_shipping_state").val(c.shipping_state)}a(".edit_address").unblock()}})}return!1});a("button.billing-same-as-shipping").live("click",function(){var b=confirm(woocommerce_writepanel_params.copy_billing);if(b){a("input#_shipping_first_name").val(a("input#_billing_first_name").val());a("input#_shipping_last_name").val(a("input#_billing_last_name").val());a("input#_shipping_company").val(a("input#_billing_company").val());a("input#_shipping_address_1").val(a("input#_billing_address_1").val());a("input#_shipping_address_2").val(a("input#_billing_address_2").val());a("input#_shipping_city").val(a("input#_billing_city").val());a("input#_shipping_postcode").val(a("input#_billing_postcode").val());a("input#_shipping_country").val(a("input#_billing_country").val());a("input#_shipping_state").val(a("input#_billing_state").val())}return!1});a("button.add_tax_row").live("click",function(){a("ul.tax_rows").append('
  • ');return!1});a("select#product-type").change(function(){var b=a(this).val();a(".hide_if_grouped").show();a(".show_if_simple, .show_if_variable, .show_if_grouped, .show_if_external").hide();if(b=="simple"){a(".show_if_simple").show();a("input#_manage_stock").change()}else if(b=="variable"){a(".show_if_variable").show();a("input#_manage_stock").change();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change()}else if(b=="grouped"){a(".show_if_grouped").show();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change();a(".hide_if_grouped").hide()}else if(b=="external"){a(".show_if_external").show();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change()}a("ul.tabs li:visible").eq(0).find("a").click();a("body").trigger("woocommerce-product-type-change",b,a(this))}).change();a("input#_downloadable").change(function(){a(".show_if_downloadable").hide();a("input#_downloadable").is(":checked")&&a(".show_if_downloadable").show();a(".downloads_tab").is(".active")&&a("ul.tabs li:visible").eq(0).find("a").click()}).change();a("input#_virtual").change(function(){a(".show_if_virtual").hide();a(".hide_if_virtual").show();if(a("input#_virtual").is(":checked")){a(".show_if_virtual").show();a(".hide_if_virtual").hide()}}).change();var b=!1;a(".sale_price_dates_fields input").each(function(){a(this).val()!=""&&(b=!0)});if(b){a(".sale_schedule").hide();a(".sale_price_dates_fields").show()}else{a(".sale_schedule").show();a(".sale_price_dates_fields").hide()}a(".sale_schedule").click(function(){a(this).hide();a(".sale_price_dates_fields").show();return!1});a(".cancel_sale_schedule").click(function(){a(this).closest("p").find("input").val("");a(".sale_schedule").show();a(".sale_price_dates_fields").hide();return!1});a("input#_manage_stock").change(function(){a(this).is(":checked")?a("div.stock_fields").show():a("div.stock_fields").hide()}).change();var c=a("#_sale_price_dates_from, #_sale_price_dates_to").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:!0,onSelect:function(b){var d=this.id=="_sale_price_dates_from"?"minDate":"maxDate",e=a(this).data("datepicker"),f=a.datepicker.parseDate(e.settings.dateFormat||a.datepicker._defaults.dateFormat,b,e.settings);c.not(this).datepicker("option",d,f)}});a(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:!0});a("#attributes_list select.multiselect").chosen();var d=a("#attributes_list").children("tr").get();d.sort(function(b,c){var d=a(b).attr("rel"),e=a(c).attr("rel");return de?1:0});a(d).each(function(b,c){a("#attributes_list").append(c)});e();a("button.add_attribute").click(function(){var b=a("table.woocommerce_attributes tbody tr").size(),c=a("select.attribute_taxonomy").val();if(!c){var d=a("select#product-type").val();d!="variable"?enable_variation='style="display:none;"':enable_variation="";a("table.woocommerce_attributes tbody").append('')}else{var g=a("table.woocommerce_attributes tbody tr."+c);a("table.woocommerce_attributes tbody").append(a(g));a(g).show();f()}e()});a("button.hide_row").live("click",function(){var b=confirm("Remove this attribute?");if(b){a(this).parent().parent().find("select, input[type=text]").val("");a(this).parent().parent().hide();e()}return!1});a("#attributes_list button.remove_row").live("click",function(){var b=confirm("Remove this attribute?");if(b){a(this).parent().parent().remove();e();f()}return!1});a("table.woocommerce_attributes tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:".handle",scrollSensitivity:40,helper:function(b,c){c.children().each(function(){a(this).width(a(this).width())});c.css("left","0");return c},start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style");f()}});a(".multi_select_products button").live("click",function(){var b=a(this).parent().parent().parent().parent(),c=a(this),d=c.parent().parent();if(d.is(".multi_select_products_target_upsell")||d.is(".multi_select_products_target_crosssell"))c.parent().remove();else{if(c.is(".add_upsell"))var e=a(".multi_select_products_target_upsell",a(b)),f="upsell_ids[]";else var e=a(".multi_select_products_target_crosssell",a(b)),f="crosssell_ids[]";var g=a("li[rel="+c.parent().attr("rel")+"]",e);if(a(g).size()>0)return!1;var h=c.parent().clone();h.find("button:eq(0)").html("×");h.find("button:eq(1)").remove();h.find("input").val(c.parent().attr("rel"));h.find(".product_id").attr("name",f);h.appendTo(e)}});var g;a(".multi_select_products #product_search").bind("keyup click",function(){a(".multi_select_products_source").addClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();g&&g.abort();var b=a(this).val(),c=this,d=a(this).attr("rel");if(b.length<3){a(".multi_select_products_source").removeClass("loading");return}var e={name:d,search:encodeURI(b),action:"woocommerce_upsell_crosssell_search_products",security:woocommerce_writepanel_params.upsell_crosssell_search_products_nonce};g=a.ajax({url:woocommerce_writepanel_params.ajax_url,data:e,type:"POST",success:function(b){a(".multi_select_products_source").removeClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();a(c).parent().parent().append(b)}})});var h;window.send_to_editor_default=window.send_to_editor;jQuery(".upload_file_button").live("click",function(){h=jQuery(this).parent().find(".file_path");formfield=jQuery(h).attr("name");window.send_to_editor=window.send_to_download_url;tb_show("","media-upload.php?post_id="+woocommerce_writepanel_params.post_id+"&type=downloadable_product&from=wc01&TB_iframe=true");return!1});window.send_to_download_url=function(a){file_url=jQuery(a).attr("href");file_url&&jQuery(h).val(file_url);tb_remove();window.send_to_editor=window.send_to_editor_default}}); \ No newline at end of file +jQuery(function(a){function e(){a("table.woocommerce_attributes, table.woocommerce_variable_attributes").each(function(){a("tbody tr",this).size()==0?a(this).parent().hide():a(this).parent().show()})}function f(){a("#attributes_list tr").each(function(b,c){a(".attribute_position",c).val(parseInt(a(c).index("#attributes_list tr")))})}a("#upsell_product_data").bind("keypress",function(a){if(a.keyCode==13)return!1});a("ul.tabs").show();a("div.panel-wrap").each(function(){a("div.panel:not(div.panel:first)",this).hide()});a("ul.tabs a").click(function(){var b=a(this).closest("div.panel-wrap");a("ul.tabs li",b).removeClass("active");a(this).parent().addClass("active");a("div.panel",b).hide();a(a(this).attr("href")).show();return!1});a("a.edit_address").click(function(){a(this).hide();a(this).closest(".order_data").find("div.address").hide();a(this).closest(".order_data").find("div.edit_address").show()});jQuery("select.chosen_select").chosen();jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"});a("#order_items_list .remove_row").live("click",function(){var b=confirm(woocommerce_writepanel_params.remove_item_notice);if(b){a(this).closest("tr.item").hide();a("input",a(this).closest("tr.item")).val("")}return!1});a("button.calc_line_taxes").live("click",function(){a(".woocommerce_order_items_wrapper").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=confirm(woocommerce_writepanel_params.calc_line_taxes);if(b){var c=a("#order_items_list tr.item"),d=a("#_shipping_country").val();if(d)var e=a("#_shipping_state").val(),f=a("#_shipping_postcode").val();else{d=a("#_billing_country").val();var e=a("#_billing_state").val(),f=a("#_billing_postcode").val()}c.each(function(b){var g=a(this),h={action:"woocommerce_calc_line_taxes",item_id:g.find("input.item_id").val(),line_subtotal:g.find("input.line_subtotal").val(),line_total:g.find("input.line_total").val(),tax_class:g.find("select.tax_class").val(),country:d,state:e,postcode:f,security:woocommerce_writepanel_params.calc_totals_nonce};a.post(woocommerce_writepanel_params.ajax_url,h,function(d){result=jQuery.parseJSON(d);g.find("input.line_subtotal_tax").val(result.line_subtotal_tax);g.find("input.line_tax").val(result.line_tax);b==c.size()-1&&a(".woocommerce_order_items_wrapper").unblock()})})}else a(".woocommerce_order_items_wrapper").unblock();return!1}).hover(function(){a("#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax").css("background-color","#d8c8d2")},function(){a("#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax").css("background-color","")});a("button.calc_totals").live("click",function(){a("#woocommerce-order-totals").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=confirm(woocommerce_writepanel_params.calc_totals);if(b){var c=0,d=0,e=0,f=0,g=0,h=parseFloat(a("#_order_shipping").val()),i=parseFloat(a("#_order_shipping_tax").val()),j=parseFloat(a("#_order_discount").val());h||(h=0);i||(i=0);j||(j=0);a("#order_items_list tr.item").each(function(){var b=parseFloat(a(this).find("input.line_subtotal").val()),f=parseFloat(a(this).find("input.line_subtotal_tax").val()),h=parseFloat(a(this).find("input.line_total").val()),i=parseFloat(a(this).find("input.line_tax").val());c=parseFloat(c+b);d=parseFloat(d+f);e=parseFloat(e+h);woocommerce_writepanel_params.round_at_subtotal=="no"&&(i=parseFloat(i.toFixed(2)));g=parseFloat(g+i)});woocommerce_writepanel_params.round_at_subtotal=="yes"&&(g=parseFloat(g.toFixed(2)));var f=c+d-(e+g);f<0&&(f=0);f=f.toFixed(2);var k=e+g+h+i-j;k=k.toFixed(2);a("#_cart_discount").val(f);a("#_order_tax").val(g);a("#_order_total").val(k);a("ul.tax_rows").empty();a("#woocommerce-order-totals").unblock()}else a("#woocommerce-order-totals").unblock();return!1}).hover(function(){a("#woocommerce-order-totals .calculated").css("background-color","#d8c8d2")},function(){a("#woocommerce-order-totals .calculated").css("background-color","")});a("button.add_shop_order_item").click(function(){var b=a("select.add_item_id").val();if(b){a("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var c=a("table.woocommerce_order_items tbody tr.item").size(),d={action:"woocommerce_add_order_item",item_to_add:a("select.add_item_id").val(),index:c,security:woocommerce_writepanel_params.add_order_item_nonce};a.post(woocommerce_writepanel_params.ajax_url,d,function(b){a("table.woocommerce_order_items tbody#order_items_list").append(b);a("table.woocommerce_order_items").unblock();a("select.add_item_id").css("border-color","").val("");jQuery(".tips").tipTip({attribute:"tip",fadeIn:50,fadeOut:50})})}else a("select.add_item_id").css("border-color","red")});a("button.add_meta").live("click",function(){var b=a(this).closest("tr.item").attr("rel");a(this).closest("table.meta").find(".meta_items").append('');return!1});a("button.remove_meta").live("click",function(){var b=confirm("Remove this meta key?");b&&a(this).closest("tr").remove();return!1});a("button.load_customer_billing").live("click",function(){var b=confirm(woocommerce_writepanel_params.load_billing);if(b){var c=a("#customer_user").val();if(!c){alert(woocommerce_writepanel_params.no_customer_selected);return!1}var d={user_id:c,type_to_load:"billing",action:"woocommerce_get_customer_details",security:woocommerce_writepanel_params.get_customer_details_nonce};a(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});a.ajax({url:woocommerce_writepanel_params.ajax_url,data:d,type:"POST",success:function(b){var c=jQuery.parseJSON(b);if(c){a("input#_billing_first_name").val(c.billing_first_name);a("input#_billing_last_name").val(c.billing_last_name);a("input#_billing_company").val(c.billing_company);a("input#_billing_address_1").val(c.billing_address_1);a("input#_billing_address_2").val(c.billing_address_2);a("input#_billing_city").val(c.billing_city);a("input#_billing_postcode").val(c.billing_postcode);a("input#_billing_country").val(c.billing_country);a("input#_billing_state").val(c.billing_state);a("input#_billing_email").val(c.billing_email);a("input#_billing_phone").val(c.billing_phone)}a(".edit_address").unblock()}})}return!1});a("button.load_customer_shipping").live("click",function(){var b=confirm(woocommerce_writepanel_params.load_shipping);if(b){var c=a("#customer_user").val();if(!c){alert(woocommerce_writepanel_params.no_customer_selected);return!1}var d={user_id:c,type_to_load:"shipping",action:"woocommerce_get_customer_details",security:woocommerce_writepanel_params.get_customer_details_nonce};a(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});a.ajax({url:woocommerce_writepanel_params.ajax_url,data:d,type:"POST",success:function(b){var c=jQuery.parseJSON(b);if(c){a("input#_shipping_first_name").val(c.shipping_first_name);a("input#_shipping_last_name").val(c.shipping_last_name);a("input#_shipping_company").val(c.shipping_company);a("input#_shipping_address_1").val(c.shipping_address_1);a("input#_shipping_address_2").val(c.shipping_address_2);a("input#_shipping_city").val(c.shipping_city);a("input#_shipping_postcode").val(c.shipping_postcode);a("input#_shipping_country").val(c.shipping_country);a("input#_shipping_state").val(c.shipping_state)}a(".edit_address").unblock()}})}return!1});a("button.billing-same-as-shipping").live("click",function(){var b=confirm(woocommerce_writepanel_params.copy_billing);if(b){a("input#_shipping_first_name").val(a("input#_billing_first_name").val());a("input#_shipping_last_name").val(a("input#_billing_last_name").val());a("input#_shipping_company").val(a("input#_billing_company").val());a("input#_shipping_address_1").val(a("input#_billing_address_1").val());a("input#_shipping_address_2").val(a("input#_billing_address_2").val());a("input#_shipping_city").val(a("input#_billing_city").val());a("input#_shipping_postcode").val(a("input#_billing_postcode").val());a("input#_shipping_country").val(a("input#_billing_country").val());a("input#_shipping_state").val(a("input#_billing_state").val())}return!1});a("button.add_tax_row").live("click",function(){a("ul.tax_rows").append('
  • ');return!1});a("select#product-type").change(function(){var b=a(this).val();a(".hide_if_grouped").show();a(".show_if_simple, .show_if_variable, .show_if_grouped, .show_if_external").hide();if(b=="simple"){a(".show_if_simple").show();a("input#_manage_stock").change()}else if(b=="variable"){a(".show_if_variable").show();a("input#_manage_stock").change();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change()}else if(b=="grouped"){a(".show_if_grouped").show();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change();a(".hide_if_grouped").hide()}else if(b=="external"){a(".show_if_external").show();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change()}a("ul.tabs li:visible").eq(0).find("a").click();a("body").trigger("woocommerce-product-type-change",b,a(this))}).change();a("input#_downloadable").change(function(){a(".show_if_downloadable").hide();a("input#_downloadable").is(":checked")&&a(".show_if_downloadable").show();a(".downloads_tab").is(".active")&&a("ul.tabs li:visible").eq(0).find("a").click()}).change();a("input#_virtual").change(function(){a(".show_if_virtual").hide();a(".hide_if_virtual").show();if(a("input#_virtual").is(":checked")){a(".show_if_virtual").show();a(".hide_if_virtual").hide()}}).change();var b=!1;a(".sale_price_dates_fields input").each(function(){a(this).val()!=""&&(b=!0)});if(b){a(".sale_schedule").hide();a(".sale_price_dates_fields").show()}else{a(".sale_schedule").show();a(".sale_price_dates_fields").hide()}a(".sale_schedule").click(function(){a(this).hide();a(".sale_price_dates_fields").show();return!1});a(".cancel_sale_schedule").click(function(){a(this).closest("p").find("input").val("");a(".sale_schedule").show();a(".sale_price_dates_fields").hide();return!1});a("input#_manage_stock").change(function(){a(this).is(":checked")?a("div.stock_fields").show():a("div.stock_fields").hide()}).change();var c=a("#_sale_price_dates_from, #_sale_price_dates_to").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:!0,onSelect:function(b){var d=this.id=="_sale_price_dates_from"?"minDate":"maxDate",e=a(this).data("datepicker"),f=a.datepicker.parseDate(e.settings.dateFormat||a.datepicker._defaults.dateFormat,b,e.settings);c.not(this).datepicker("option",d,f)}});a(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:!0});a("#attributes_list select.multiselect").chosen();var d=a("#attributes_list").children("tr").get();d.sort(function(b,c){var d=a(b).attr("rel"),e=a(c).attr("rel");return de?1:0});a(d).each(function(b,c){a("#attributes_list").append(c)});e();a("button.add_attribute").click(function(){var b=a("table.woocommerce_attributes tbody tr").size(),c=a("select.attribute_taxonomy").val();if(!c){var d=a("select#product-type").val();d!="variable"?enable_variation='style="display:none;"':enable_variation="";a("table.woocommerce_attributes tbody").append('')}else{var g=a("table.woocommerce_attributes tbody tr."+c);a("table.woocommerce_attributes tbody").append(a(g));a(g).show();f()}e()});a("button.hide_row").live("click",function(){var b=confirm("Remove this attribute?");if(b){a(this).parent().parent().find("select, input[type=text]").val("");a(this).parent().parent().hide();e()}return!1});a("#attributes_list button.remove_row").live("click",function(){var b=confirm("Remove this attribute?");if(b){a(this).parent().parent().remove();e();f()}return!1});a("table.woocommerce_attributes tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:".handle",scrollSensitivity:40,helper:function(b,c){c.children().each(function(){a(this).width(a(this).width())});c.css("left","0");return c},start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style");f()}});a(".multi_select_products button").live("click",function(){var b=a(this).parent().parent().parent().parent(),c=a(this),d=c.parent().parent();if(d.is(".multi_select_products_target_upsell")||d.is(".multi_select_products_target_crosssell"))c.parent().remove();else{if(c.is(".add_upsell"))var e=a(".multi_select_products_target_upsell",a(b)),f="upsell_ids[]";else var e=a(".multi_select_products_target_crosssell",a(b)),f="crosssell_ids[]";var g=a("li[rel="+c.parent().attr("rel")+"]",e);if(a(g).size()>0)return!1;var h=c.parent().clone();h.find("button:eq(0)").html("×");h.find("button:eq(1)").remove();h.find("input").val(c.parent().attr("rel"));h.find(".product_id").attr("name",f);h.appendTo(e)}});var g;a(".multi_select_products #product_search").bind("keyup click",function(){a(".multi_select_products_source").addClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();g&&g.abort();var b=a(this).val(),c=this,d=a(this).attr("rel");if(b.length<3){a(".multi_select_products_source").removeClass("loading");return}var e={name:d,search:encodeURI(b),action:"woocommerce_upsell_crosssell_search_products",security:woocommerce_writepanel_params.upsell_crosssell_search_products_nonce};g=a.ajax({url:woocommerce_writepanel_params.ajax_url,data:e,type:"POST",success:function(b){a(".multi_select_products_source").removeClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();a(c).parent().parent().append(b)}})});var h;window.send_to_editor_default=window.send_to_editor;jQuery(".upload_file_button").live("click",function(){h=jQuery(this).parent().find(".file_path");formfield=jQuery(h).attr("name");window.send_to_editor=window.send_to_download_url;tb_show("","media-upload.php?post_id="+woocommerce_writepanel_params.post_id+"&type=downloadable_product&from=wc01&TB_iframe=true");return!1});window.send_to_download_url=function(a){file_url=jQuery(a).attr("href");file_url&&jQuery(h).val(file_url);tb_remove();window.send_to_editor=window.send_to_editor_default}}); \ No newline at end of file