2011-08-09 15:16:18 +00:00
|
|
|
jQuery( function($){
|
2011-09-19 14:57:17 +00:00
|
|
|
|
|
|
|
// Prevent enter submitting post form
|
2011-11-05 19:03:03 +00:00
|
|
|
$("#upsell_product_data").bind("keypress", function(e) {
|
2011-09-28 12:34:41 +00:00
|
|
|
if (e.keyCode == 13) return false;
|
2011-09-19 14:57:17 +00:00
|
|
|
});
|
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// TABS
|
2011-11-05 19:03:03 +00:00
|
|
|
$('ul.tabs').show();
|
|
|
|
$('div.panel-wrap').each(function(){
|
|
|
|
$('div.panel:not(div.panel:first)', this).hide();
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
2011-11-05 19:03:03 +00:00
|
|
|
$('ul.tabs a').click(function(){
|
|
|
|
var panel_wrap = $(this).closest('div.panel-wrap');
|
|
|
|
$('ul.tabs li', panel_wrap).removeClass('active');
|
|
|
|
$(this).parent().addClass('active');
|
|
|
|
$('div.panel', panel_wrap).hide();
|
|
|
|
$( $(this).attr('href') ).show();
|
2011-08-09 15:16:18 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// ORDERS
|
2011-11-25 19:31:06 +00:00
|
|
|
$('a.edit_address').click(function(){
|
|
|
|
|
|
|
|
$(this).hide();
|
|
|
|
$(this).closest('.order_data').find('div.address').hide();
|
|
|
|
$(this).closest('.order_data').find('div.edit_address').show();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// Chosen selects
|
|
|
|
jQuery("select.chosen_select").chosen();
|
|
|
|
|
|
|
|
jQuery("select.chosen_select_nostd").chosen({
|
|
|
|
allow_single_deselect: 'true'
|
|
|
|
});
|
|
|
|
|
2011-12-30 14:00:41 +00:00
|
|
|
$('#order_items_list .remove_row').live('click', function(){
|
2011-09-19 10:30:23 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.remove_item_notice);
|
2011-08-09 15:16:18 +00:00
|
|
|
if (answer){
|
2011-11-05 19:03:03 +00:00
|
|
|
$(this).closest('tr.item').hide();
|
|
|
|
$('input', $(this).closest('tr.item')).val('');
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.calc_totals').live('click', function(){
|
2011-09-19 10:30:23 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.cart_total);
|
2011-08-09 15:16:18 +00:00
|
|
|
if (answer){
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var item_count = $('#order_items_list tr.item').size();
|
2011-08-09 15:16:18 +00:00
|
|
|
var subtotal = 0;
|
2011-11-05 19:03:03 +00:00
|
|
|
var discount = $('input#_order_discount').val();
|
|
|
|
var shipping = $('input#_order_shipping').val();
|
|
|
|
var shipping_tax = parseFloat($('input#_order_shipping_tax').val());
|
2011-08-09 15:16:18 +00:00
|
|
|
var tax = 0;
|
|
|
|
var itemTotal = 0;
|
2011-11-25 22:13:01 +00:00
|
|
|
var subtotal = 0;
|
2011-08-09 15:16:18 +00:00
|
|
|
var total = 0;
|
2011-11-25 22:13:01 +00:00
|
|
|
var cart_discount = 0;
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
if (!discount) discount = 0;
|
|
|
|
if (!shipping) shipping = 0;
|
|
|
|
if (!shipping_tax) shipping_tax = 0;
|
|
|
|
|
|
|
|
// Items
|
|
|
|
if (item_count>0) {
|
|
|
|
for (i=0; i<item_count; i++) {
|
|
|
|
|
2011-11-25 22:13:01 +00:00
|
|
|
itemCost = $('input[name^=item_cost]:eq(' + i + ')').val();
|
|
|
|
itemQty = parseInt($('input[name^=item_quantity]:eq(' + i + ')').val());
|
2011-11-30 00:30:25 +00:00
|
|
|
itemBase = $('input[name^=base_item_cost]:eq(' + i + ')').val();
|
2011-11-25 22:13:01 +00:00
|
|
|
itemTax = $('input[name^=item_tax_rate]:eq(' + i + ')').val();
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-25 22:13:01 +00:00
|
|
|
if (!itemCost) itemCost = 0;
|
|
|
|
if (!itemTax) itemTax = 0;
|
|
|
|
if (!itemQty) itemQty = 0;
|
2011-11-30 00:30:25 +00:00
|
|
|
if (!itemBase) itemBase = 0;
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-25 22:13:01 +00:00
|
|
|
totalItemTax = 0;
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-25 22:13:01 +00:00
|
|
|
// Calculate tax and discounts
|
2011-08-09 15:16:18 +00:00
|
|
|
if (itemTax && itemTax>0) {
|
|
|
|
|
2011-11-25 22:13:01 +00:00
|
|
|
if (woocommerce_writepanel_params.prices_include_tax == 'yes') {
|
|
|
|
|
|
|
|
taxRate = ( itemTax/100 ) + 1;
|
|
|
|
|
2011-11-30 00:30:25 +00:00
|
|
|
itemDiscount = (( itemBase * itemQty ) * taxRate) - (( itemCost * itemQty ) * taxRate);
|
2011-11-25 22:13:01 +00:00
|
|
|
|
2011-11-30 00:30:25 +00:00
|
|
|
// Tax worked out backwards
|
|
|
|
totalItemTax = (itemCost * itemQty) * ( itemTax/100 );
|
2011-11-25 22:13:01 +00:00
|
|
|
|
2011-11-30 00:30:25 +00:00
|
|
|
discounted_price = (itemCost * itemQty) * taxRate;
|
2011-11-25 22:13:01 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
if (woocommerce_writepanel_params.round_at_subtotal == 'no') {
|
|
|
|
totalItemTax = totalItemTax * 100;
|
|
|
|
totalItemTax = totalItemTax.toFixed(2);
|
|
|
|
totalItemTax = Math.round( totalItemTax ) / 100;
|
|
|
|
}
|
2011-11-25 22:13:01 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
taxRate = ( itemTax/100 );
|
2011-11-30 00:30:25 +00:00
|
|
|
|
|
|
|
itemDiscount = ( itemBase * itemQty ) - ( itemCost * itemQty );
|
2011-11-25 22:13:01 +00:00
|
|
|
|
2011-11-30 00:30:25 +00:00
|
|
|
// Tax worked out forwards
|
|
|
|
totalItemTax = (itemCost * itemQty) * taxRate;
|
2011-11-26 16:15:25 +00:00
|
|
|
|
2011-11-30 00:30:25 +00:00
|
|
|
discounted_price = (itemCost * itemQty) + totalItemTax;
|
2011-11-25 22:13:01 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
if (woocommerce_writepanel_params.round_at_subtotal == 'no') {
|
|
|
|
totalItemTax = totalItemTax * 100;
|
|
|
|
totalItemTax = totalItemTax.toFixed(2);
|
|
|
|
totalItemTax = Math.round( totalItemTax ) / 100;
|
|
|
|
}
|
2011-11-25 22:13:01 +00:00
|
|
|
|
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
|
2011-11-25 22:13:01 +00:00
|
|
|
} else {
|
2011-11-30 00:30:25 +00:00
|
|
|
itemDiscount = ( itemBase * itemQty ) - ( itemCost * itemQty );
|
|
|
|
discounted_price = ( itemCost * itemQty );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:30:25 +00:00
|
|
|
subtotal = subtotal + parseFloat( (itemBase * itemQty) );
|
|
|
|
|
|
|
|
cart_discount = cart_discount + parseFloat( itemDiscount );
|
|
|
|
|
2011-11-25 22:13:01 +00:00
|
|
|
totalItemCost = parseFloat( discounted_price );
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
itemTotal = itemTotal + parseFloat( totalItemCost );
|
2011-11-25 22:13:01 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
tax = tax + parseFloat( totalItemTax );
|
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-26 20:15:21 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
if (woocommerce_writepanel_params.round_at_subtotal == 'yes') {
|
|
|
|
|
|
|
|
tax = tax * 100;
|
|
|
|
tax = tax.toFixed(2);
|
|
|
|
tax = Math.round( tax ) / 100;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:30:25 +00:00
|
|
|
total = parseFloat(itemTotal) - parseFloat(discount) + parseFloat(shipping) + parseFloat(shipping_tax);
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-26 20:15:21 +00:00
|
|
|
// Rounding
|
|
|
|
subtotal = subtotal * 100;
|
|
|
|
subtotal = subtotal.toFixed(2);
|
|
|
|
subtotal = Math.round( subtotal ) / 100;
|
|
|
|
|
|
|
|
total = total * 100;
|
|
|
|
total = total.toFixed(2);
|
|
|
|
total = Math.round( total ) / 100;
|
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
if (total < 0 ) total = 0;
|
2011-11-25 22:13:01 +00:00
|
|
|
|
|
|
|
$('input#_cart_discount').val( cart_discount.toFixed(2) );
|
2011-11-05 19:03:03 +00:00
|
|
|
$('input#_order_subtotal').val( subtotal.toFixed(2) );
|
|
|
|
$('input#_order_tax').val( tax.toFixed(2) );
|
|
|
|
$('input#_order_shipping_tax').val( shipping_tax.toFixed(2) );
|
|
|
|
$('input#_order_total').val( total.toFixed(2) );
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.add_shop_order_item').click(function(){
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var add_item_id = $('select.add_item_id').val();
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-08-12 10:22:07 +00:00
|
|
|
if (add_item_id) {
|
2011-08-19 20:11:04 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('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: 0.6 } });
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var size = $('table.woocommerce_order_items tbody tr.item').size();
|
2011-08-19 20:11:04 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
var data = {
|
2011-08-10 17:11:11 +00:00
|
|
|
action: 'woocommerce_add_order_item',
|
2011-11-05 19:03:03 +00:00
|
|
|
item_to_add: $('select.add_item_id').val(),
|
2011-08-19 20:11:04 +00:00
|
|
|
index: size,
|
2011-09-19 10:30:23 +00:00
|
|
|
security: woocommerce_writepanel_params.add_order_item_nonce
|
2011-08-09 15:16:18 +00:00
|
|
|
};
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$.post( woocommerce_writepanel_params.ajax_url, data, function(response) {
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('table.woocommerce_order_items tbody#order_items_list').append( response );
|
|
|
|
$('table.woocommerce_order_items').unblock();
|
|
|
|
$('select.add_item_id').css('border-color', '').val('');
|
2011-11-26 16:41:48 +00:00
|
|
|
jQuery(".tips").tipTip({
|
|
|
|
'attribute' : 'tip',
|
|
|
|
'fadeIn' : 50,
|
|
|
|
'fadeOut' : 50
|
|
|
|
});
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
2011-11-05 19:03:03 +00:00
|
|
|
$('select.add_item_id').css('border-color', 'red');
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.add_meta').live('click', function(){
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var index = $(this).closest('tr.item').attr('rel');
|
2011-08-19 20:11:04 +00:00
|
|
|
|
2011-12-30 14:00:41 +00:00
|
|
|
$(this).closest('table.meta').find('.meta_items').append('<tr><td><input type="text" name="meta_name[' + index + '][]" placeholder="' + woocommerce_writepanel_params.meta_name + '" /></td><td><input type="text" name="meta_value[' + index + '][]" placeholder="' + woocommerce_writepanel_params.meta_value + '" /></td><td width="1%"><button class="remove_meta button">×</button></td></tr>');
|
2011-08-19 20:11:04 +00:00
|
|
|
|
|
|
|
return false;
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.remove_meta').live('click', function(){
|
2011-08-19 20:11:04 +00:00
|
|
|
var answer = confirm("Remove this meta key?")
|
|
|
|
if (answer){
|
2011-11-05 19:03:03 +00:00
|
|
|
$(this).closest('tr').remove();
|
2011-08-19 20:11:04 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$('button.load_customer_billing').live('click', function(){
|
|
|
|
|
|
|
|
var answer = confirm(woocommerce_writepanel_params.load_billing);
|
|
|
|
if (answer){
|
|
|
|
|
|
|
|
// Get user ID to load data for
|
|
|
|
var user_id = $('#customer_user').val();
|
|
|
|
|
|
|
|
if (!user_id) {
|
|
|
|
alert(woocommerce_writepanel_params.no_customer_selected);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
user_id: user_id,
|
|
|
|
type_to_load: 'billing',
|
|
|
|
action: 'woocommerce_get_customer_details',
|
|
|
|
security: woocommerce_writepanel_params.get_customer_details_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
$(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: 0.6 } });
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_writepanel_params.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
|
|
|
var info = jQuery.parseJSON(response);
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
$('input#_billing_first_name').val( info.billing_first_name );
|
|
|
|
$('input#_billing_last_name').val( info.billing_last_name );
|
|
|
|
$('input#_billing_company').val( info.billing_company );
|
|
|
|
$('input#_billing_address_1').val( info.billing_address_1 );
|
|
|
|
$('input#_billing_address_2').val( info.billing_address_2 );
|
|
|
|
$('input#_billing_city').val( info.billing_city );
|
|
|
|
$('input#_billing_postcode').val( info.billing_postcode );
|
|
|
|
$('input#_billing_country').val( info.billing_country );
|
|
|
|
$('input#_billing_state').val( info.billing_state );
|
|
|
|
$('input#_billing_email').val( info.billing_email );
|
|
|
|
$('input#_billing_phone').val( info.billing_phone );
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.edit_address').unblock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('button.load_customer_shipping').live('click', function(){
|
|
|
|
|
|
|
|
var answer = confirm(woocommerce_writepanel_params.load_shipping);
|
|
|
|
if (answer){
|
|
|
|
|
|
|
|
// Get user ID to load data for
|
|
|
|
var user_id = $('#customer_user').val();
|
|
|
|
|
|
|
|
if (!user_id) {
|
|
|
|
alert(woocommerce_writepanel_params.no_customer_selected);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
user_id: user_id,
|
|
|
|
type_to_load: 'shipping',
|
|
|
|
action: 'woocommerce_get_customer_details',
|
|
|
|
security: woocommerce_writepanel_params.get_customer_details_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
$(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: 0.6 } });
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_writepanel_params.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
|
|
|
var info = jQuery.parseJSON(response);
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
$('input#_shipping_first_name').val( info.shipping_first_name );
|
|
|
|
$('input#_shipping_last_name').val( info.shipping_last_name );
|
|
|
|
$('input#_shipping_company').val( info.shipping_company );
|
|
|
|
$('input#_shipping_address_1').val( info.shipping_address_1 );
|
|
|
|
$('input#_shipping_address_2').val( info.shipping_address_2 );
|
|
|
|
$('input#_shipping_city').val( info.shipping_city );
|
|
|
|
$('input#_shipping_postcode').val( info.shipping_postcode );
|
|
|
|
$('input#_shipping_country').val( info.shipping_country );
|
|
|
|
$('input#_shipping_state').val( info.shipping_state );
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.edit_address').unblock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.billing-same-as-shipping').live('click', function(){
|
2011-09-19 10:30:23 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.copy_billing);
|
2011-08-09 15:16:18 +00:00
|
|
|
if (answer){
|
2011-11-26 16:15:25 +00:00
|
|
|
$('input#_shipping_first_name').val( $('input#_billing_first_name').val() );
|
|
|
|
$('input#_shipping_last_name').val( $('input#_billing_last_name').val() );
|
|
|
|
$('input#_shipping_company').val( $('input#_billing_company').val() );
|
|
|
|
$('input#_shipping_address_1').val( $('input#_billing_address_1').val() );
|
|
|
|
$('input#_shipping_address_2').val( $('input#_billing_address_2').val() );
|
|
|
|
$('input#_shipping_city').val( $('input#_billing_city').val() );
|
|
|
|
$('input#_shipping_postcode').val( $('input#_billing_postcode').val() );
|
|
|
|
$('input#_shipping_country').val( $('input#_billing_country').val() );
|
|
|
|
$('input#_shipping_state').val( $('input#_billing_state').val() );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-12-31 19:03:41 +00:00
|
|
|
$('button.add_tax_row').live('click', function(){
|
|
|
|
$('ul.tax_rows').append('<li class="left"><input type="text" name="_order_taxes_label[]" placeholder="' + woocommerce_writepanel_params.tax_label + '" class="calculated" /></li><li class="right"><input type="text" name="_order_taxes_total[]" placeholder="0.00" class="calculated" /><input type="hidden" name="_order_taxes_compound[]" value="0" /></li>');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// PRODUCT TYPE SPECIFIC OPTIONS
|
|
|
|
$('select#product-type').change(function(){
|
|
|
|
|
|
|
|
// Get value
|
2011-11-05 19:03:03 +00:00
|
|
|
var select_val = $(this).val();
|
|
|
|
|
2011-11-08 16:15:36 +00:00
|
|
|
$('.show_if_simple, .show_if_variable, .show_if_grouped, .show_if_external').hide();
|
2011-11-05 19:03:03 +00:00
|
|
|
|
|
|
|
if (select_val=='simple') {
|
|
|
|
$('.show_if_simple').show();
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_manage_stock').change();
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
else if (select_val=='variable') {
|
|
|
|
$('.show_if_variable').show();
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_manage_stock').change();
|
|
|
|
$('input#_downloadable').prop('checked', false).change();
|
|
|
|
$('input#_virtual').removeAttr('checked').change();
|
2011-11-05 19:03:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (select_val=='grouped') {
|
|
|
|
$('.show_if_grouped').show();
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_downloadable').prop('checked', false).change();
|
|
|
|
$('input#_virtual').removeAttr('checked').change();
|
2011-11-05 19:03:03 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 16:15:36 +00:00
|
|
|
else if (select_val=='external') {
|
|
|
|
$('.show_if_external').show();
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_downloadable').prop('checked', false).change();
|
|
|
|
$('input#_virtual').removeAttr('checked').change();
|
2011-11-08 16:15:36 +00:00
|
|
|
}
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('ul.tabs li:visible').eq(0).find('a').click();
|
|
|
|
|
2011-08-10 17:11:11 +00:00
|
|
|
$('body').trigger('woocommerce-product-type-change', select_val, $(this) );
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
}).change();
|
2011-11-05 19:03:03 +00:00
|
|
|
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_downloadable').change(function(){
|
2011-11-05 19:03:03 +00:00
|
|
|
|
|
|
|
$('.show_if_downloadable').hide();
|
|
|
|
|
2011-12-24 16:57:36 +00:00
|
|
|
if ($('input#_downloadable').is(':checked')) {
|
2011-11-05 19:03:03 +00:00
|
|
|
$('.show_if_downloadable').show();
|
|
|
|
}
|
|
|
|
|
2011-11-06 13:45:18 +00:00
|
|
|
if ($('.downloads_tab').is('.active')) $('ul.tabs li:visible').eq(0).find('a').click();
|
2011-11-05 19:03:03 +00:00
|
|
|
|
|
|
|
}).change();
|
|
|
|
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_virtual').change(function(){
|
2011-11-06 13:45:18 +00:00
|
|
|
|
|
|
|
$('.show_if_virtual').hide();
|
2011-12-24 15:32:18 +00:00
|
|
|
$('.hide_if_virtual').show();
|
2011-11-06 13:45:18 +00:00
|
|
|
|
2011-12-24 16:57:36 +00:00
|
|
|
if ($('input#_virtual').is(':checked')) {
|
2011-11-06 13:45:18 +00:00
|
|
|
$('.show_if_virtual').show();
|
2011-12-24 15:32:18 +00:00
|
|
|
$('.hide_if_virtual').hide();
|
2011-11-06 13:45:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}).change();
|
2011-12-24 15:32:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Sale price schedule
|
|
|
|
var sale_schedule_set = false;
|
|
|
|
$('.sale_price_dates_fields input').each(function(){
|
|
|
|
if ($(this).val()!='') sale_schedule_set = true;
|
|
|
|
});
|
|
|
|
if (sale_schedule_set) {
|
|
|
|
$('.sale_schedule').hide();
|
|
|
|
$('.sale_price_dates_fields').show();
|
|
|
|
} else {
|
|
|
|
$('.sale_schedule').show();
|
|
|
|
$('.sale_price_dates_fields').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.sale_schedule').click(function(){
|
|
|
|
$(this).hide();
|
|
|
|
$('.sale_price_dates_fields').show();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cancel_sale_schedule').click(function(){
|
|
|
|
$(this).closest('p').find('input').val('');
|
|
|
|
$('.sale_schedule').show();
|
|
|
|
$('.sale_price_dates_fields').hide();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
// STOCK OPTIONS
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_manage_stock').change(function(){
|
2011-11-05 19:03:03 +00:00
|
|
|
if ($(this).is(':checked')) $('div.stock_fields').show();
|
|
|
|
else $('div.stock_fields').hide();
|
2011-08-09 15:16:18 +00:00
|
|
|
}).change();
|
|
|
|
|
|
|
|
|
|
|
|
// DATE PICKER FIELDS
|
2011-12-24 17:21:39 +00:00
|
|
|
var dates = $( "#_sale_price_dates_from, #_sale_price_dates_to" ).datepicker({
|
2011-09-19 10:30:23 +00:00
|
|
|
defaultDate: "",
|
|
|
|
dateFormat: "yy-mm-dd",
|
|
|
|
numberOfMonths: 1,
|
|
|
|
showButtonPanel: true,
|
|
|
|
showOn: "button",
|
|
|
|
buttonImage: woocommerce_writepanel_params.calendar_image,
|
|
|
|
buttonImageOnly: true,
|
|
|
|
onSelect: function( selectedDate ) {
|
2011-12-24 17:21:39 +00:00
|
|
|
var option = this.id == "_sale_price_dates_from" ? "minDate" : "maxDate",
|
2011-11-05 19:03:03 +00:00
|
|
|
instance = $( this ).data( "datepicker" ),
|
|
|
|
date = $.datepicker.parseDate(
|
2011-09-19 10:30:23 +00:00
|
|
|
instance.settings.dateFormat ||
|
2011-11-05 19:03:03 +00:00
|
|
|
$.datepicker._defaults.dateFormat,
|
2011-09-19 10:30:23 +00:00
|
|
|
selectedDate, instance.settings );
|
|
|
|
dates.not( this ).datepicker( "option", option, date );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2011-09-19 10:30:23 +00:00
|
|
|
});
|
2011-09-20 15:05:07 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$( ".date-picker" ).datepicker({
|
2011-09-20 15:05:07 +00:00
|
|
|
dateFormat: "yy-mm-dd",
|
|
|
|
numberOfMonths: 1,
|
|
|
|
showButtonPanel: true,
|
|
|
|
showOn: "button",
|
|
|
|
buttonImage: woocommerce_writepanel_params.calendar_image,
|
|
|
|
buttonImageOnly: true
|
|
|
|
});
|
2011-09-19 10:30:23 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
// ATTRIBUTE TABLES
|
2011-09-11 17:35:22 +00:00
|
|
|
|
|
|
|
// Multiselect attributes
|
2011-11-23 17:28:58 +00:00
|
|
|
$("#attributes_list select.multiselect").chosen();
|
2011-09-11 17:35:22 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// Initial order
|
2011-11-05 19:03:03 +00:00
|
|
|
var woocommerce_attributes_table_items = $('#attributes_list').children('tr').get();
|
2011-08-10 17:11:11 +00:00
|
|
|
woocommerce_attributes_table_items.sort(function(a, b) {
|
2011-11-05 19:03:03 +00:00
|
|
|
var compA = $(a).attr('rel');
|
|
|
|
var compB = $(b).attr('rel');
|
2011-08-09 15:16:18 +00:00
|
|
|
return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
|
|
|
|
})
|
2011-11-05 19:03:03 +00:00
|
|
|
$(woocommerce_attributes_table_items).each( function(idx, itm) { $('#attributes_list').append(itm); } );
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
// Show
|
|
|
|
function show_attribute_table() {
|
2011-11-05 19:03:03 +00:00
|
|
|
$('table.woocommerce_attributes, table.woocommerce_variable_attributes').each(function(){
|
|
|
|
if ($('tbody tr', this).size()==0)
|
|
|
|
$(this).parent().hide();
|
2011-08-09 15:16:18 +00:00
|
|
|
else
|
2011-11-05 19:03:03 +00:00
|
|
|
$(this).parent().show();
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
show_attribute_table();
|
|
|
|
|
|
|
|
function row_indexes() {
|
2011-11-05 19:03:03 +00:00
|
|
|
$('#attributes_list tr').each(function(index, el){ $('.attribute_position', el).val( parseInt( $(el).index('#attributes_list tr') ) ); });
|
2011-08-09 15:16:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add rows
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.add_attribute').click(function(){
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var size = $('table.woocommerce_attributes tbody tr').size();
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var attribute_type = $('select.attribute_taxonomy').val();
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
if (!attribute_type) {
|
2011-09-11 13:28:15 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var product_type = $('select#product-type').val();
|
2011-09-11 13:28:15 +00:00
|
|
|
if (product_type!='variable') enable_variation = 'style="display:none;"'; else enable_variation = '';
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
// Add custom attribute row
|
2011-11-07 14:13:04 +00:00
|
|
|
$('table.woocommerce_attributes tbody').append('<tr><td class="handle"></td><td><input type="text" name="attribute_names[' + size + ']" /><input type="hidden" name="attribute_is_taxonomy[' + size + ']" value="0" /><input type="hidden" name="attribute_position[' + size + ']" class="attribute_position" value="' + size + '" /></td><td><input type="text" name="attribute_values[' + size + ']" /></td><td class="center"><input type="checkbox" checked="checked" name="attribute_visibility[' + size + ']" value="1" /></td><td class="center enable_variation" ' + enable_variation + '><input type="checkbox" name="attribute_variation[' + size + ']" value="1" /></td><td class="center"><button type="button" class="remove_row button">×</button></td></tr>');
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Reveal taxonomy row
|
2011-11-05 19:03:03 +00:00
|
|
|
var thisrow = $('table.woocommerce_attributes tbody tr.' + attribute_type);
|
|
|
|
$('table.woocommerce_attributes tbody').append( $(thisrow) );
|
|
|
|
$(thisrow).show();
|
2011-08-09 15:16:18 +00:00
|
|
|
row_indexes();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
show_attribute_table();
|
|
|
|
});
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.hide_row').live('click', function(){
|
2011-08-09 15:16:18 +00:00
|
|
|
var answer = confirm("Remove this attribute?")
|
|
|
|
if (answer){
|
2011-11-05 19:03:03 +00:00
|
|
|
$(this).parent().parent().find('select, input[type=text]').val('');
|
|
|
|
$(this).parent().parent().hide();
|
2011-08-09 15:16:18 +00:00
|
|
|
show_attribute_table();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('#attributes_list button.remove_row').live('click', function(){
|
2011-08-09 15:16:18 +00:00
|
|
|
var answer = confirm("Remove this attribute?")
|
|
|
|
if (answer){
|
2011-11-05 19:03:03 +00:00
|
|
|
$(this).parent().parent().remove();
|
2011-08-09 15:16:18 +00:00
|
|
|
show_attribute_table();
|
|
|
|
row_indexes();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-09-19 14:57:17 +00:00
|
|
|
// Attribute ordering
|
2011-11-05 19:03:03 +00:00
|
|
|
$('table.woocommerce_attributes tbody').sortable({
|
2011-09-19 14:57:17 +00:00
|
|
|
items:'tr',
|
|
|
|
cursor:'move',
|
|
|
|
axis:'y',
|
2011-11-07 14:13:04 +00:00
|
|
|
handle: '.handle',
|
2011-09-19 14:57:17 +00:00
|
|
|
scrollSensitivity:40,
|
|
|
|
helper:function(e,ui){
|
|
|
|
ui.children().each(function(){
|
2011-11-05 19:03:03 +00:00
|
|
|
$(this).width($(this).width());
|
2011-09-19 14:57:17 +00:00
|
|
|
});
|
2011-11-07 14:13:04 +00:00
|
|
|
ui.css('left', '0');
|
2011-09-19 14:57:17 +00:00
|
|
|
return ui;
|
|
|
|
},
|
|
|
|
start:function(event,ui){
|
|
|
|
ui.item.css('background-color','#f6f6f6');
|
|
|
|
},
|
|
|
|
stop:function(event,ui){
|
|
|
|
ui.item.removeAttr('style');
|
|
|
|
row_indexes();
|
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
|
|
|
|
2011-09-19 14:57:17 +00:00
|
|
|
|
|
|
|
|
2011-08-11 10:51:33 +00:00
|
|
|
// Cross sells/Up sells
|
2011-11-05 19:03:03 +00:00
|
|
|
$('.multi_select_products button').live('click', function(){
|
|
|
|
|
|
|
|
var wrapper = $(this).parent().parent().parent().parent();
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var button = $(this);
|
|
|
|
var button_parent = button.parent().parent();
|
|
|
|
|
|
|
|
if (button_parent.is('.multi_select_products_target_upsell') || button_parent.is('.multi_select_products_target_crosssell')) {
|
|
|
|
button.parent().remove();
|
2011-08-11 10:51:33 +00:00
|
|
|
} else {
|
2011-11-05 19:03:03 +00:00
|
|
|
if (button.is('.add_upsell')) {
|
|
|
|
var target = $('.multi_select_products_target_upsell', $(wrapper));
|
|
|
|
var product_id_field_name = 'upsell_ids[]';
|
|
|
|
} else {
|
|
|
|
var target = $('.multi_select_products_target_crosssell', $(wrapper));
|
|
|
|
var product_id_field_name = 'crosssell_ids[]';
|
|
|
|
}
|
|
|
|
|
|
|
|
var exists = $('li[rel=' + button.parent().attr('rel') + ']', target);
|
|
|
|
|
|
|
|
if ($(exists).size()>0) return false;
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var cloned_item = button.parent().clone();
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-11-06 13:45:18 +00:00
|
|
|
cloned_item.find('button:eq(0)').html('×');
|
2011-11-05 19:03:03 +00:00
|
|
|
cloned_item.find('button:eq(1)').remove();
|
|
|
|
cloned_item.find('input').val( button.parent().attr('rel') );
|
|
|
|
cloned_item.find('.product_id').attr('name', product_id_field_name);
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
cloned_item.appendTo(target);
|
2011-08-11 10:51:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-19 14:57:17 +00:00
|
|
|
var xhr;
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('.multi_select_products #product_search').bind('keyup click', function(){
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('.multi_select_products_source').addClass('loading');
|
|
|
|
$('.multi_select_products_source li:not(.product_search)').remove();
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-09-19 14:57:17 +00:00
|
|
|
if (xhr) xhr.abort();
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var search = $(this).val();
|
2011-08-11 10:51:33 +00:00
|
|
|
var input = this;
|
2011-11-05 19:03:03 +00:00
|
|
|
var name = $(this).attr('rel');
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-09-19 14:57:17 +00:00
|
|
|
if (search.length<3) {
|
2011-11-05 19:03:03 +00:00
|
|
|
$('.multi_select_products_source').removeClass('loading');
|
2011-09-19 14:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-08-11 10:51:33 +00:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
name: name,
|
2011-09-19 14:57:17 +00:00
|
|
|
search: encodeURI(search),
|
2011-08-11 10:51:33 +00:00
|
|
|
action: 'woocommerce_upsell_crosssell_search_products',
|
2011-09-19 10:30:23 +00:00
|
|
|
security: woocommerce_writepanel_params.upsell_crosssell_search_products_nonce
|
2011-08-11 10:51:33 +00:00
|
|
|
};
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
xhr = $.ajax({
|
2011-09-19 14:57:17 +00:00
|
|
|
url: woocommerce_writepanel_params.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
2011-08-11 10:51:33 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('.multi_select_products_source').removeClass('loading');
|
|
|
|
$('.multi_select_products_source li:not(.product_search)').remove();
|
|
|
|
$(input).parent().parent().append( response );
|
2011-09-19 14:57:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2011-08-11 10:51:33 +00:00
|
|
|
|
|
|
|
});
|
2011-11-09 23:06:17 +00:00
|
|
|
|
|
|
|
// Uploading files
|
|
|
|
var file_path_field;
|
|
|
|
|
|
|
|
window.send_to_editor_default = window.send_to_editor;
|
|
|
|
|
|
|
|
jQuery('.upload_file_button').live('click', function(){
|
|
|
|
|
|
|
|
file_path_field = jQuery(this).parent().find('.file_path');
|
|
|
|
|
|
|
|
formfield = jQuery(file_path_field).attr('name');
|
|
|
|
|
|
|
|
window.send_to_editor = window.send_to_download_url;
|
|
|
|
|
2011-11-17 00:49:20 +00:00
|
|
|
tb_show('', 'media-upload.php?post_id=' + woocommerce_writepanel_params.post_id + '&type=downloadable_product&from=wc01&TB_iframe=true');
|
2011-11-09 23:06:17 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
window.send_to_download_url = function(html) {
|
|
|
|
|
|
|
|
file_url = jQuery(html).attr('href');
|
|
|
|
if (file_url) {
|
|
|
|
jQuery(file_path_field).val(file_url);
|
|
|
|
}
|
|
|
|
tb_remove();
|
|
|
|
window.send_to_editor = window.send_to_editor_default;
|
|
|
|
|
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
});
|