2011-08-09 15:16:18 +00:00
|
|
|
jQuery( function($){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
// Type box
|
|
|
|
$('.type_box').appendTo( '#woocommerce-product-data h3.hndle span' );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
$(function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
// Prevent inputs in meta box headings opening/closing contents
|
|
|
|
$('#woocommerce-product-data h3.hndle').unbind('click.postboxes');
|
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
jQuery('#woocommerce-product-data').on('click', 'h3.hndle', function(event){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
// If the user clicks on some form input inside the h3 the box should not be toggled
|
2012-08-01 12:43:46 +00:00
|
|
|
if ( $(event.target).filter('input, option, label, select').length )
|
2012-07-22 12:50:45 +00:00
|
|
|
return;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
$('#woocommerce-product-data').toggleClass('closed');
|
|
|
|
});
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
// Catalog Visibility
|
|
|
|
$('#catalog-visibility .edit-catalog-visibility').click(function () {
|
|
|
|
if ($('#catalog-visibility-select').is(":hidden")) {
|
|
|
|
$('#catalog-visibility-select').slideDown('fast');
|
|
|
|
$(this).hide();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#catalog-visibility .save-post-visibility').click(function () {
|
|
|
|
$('#catalog-visibility-select').slideUp('fast');
|
|
|
|
$('#catalog-visibility .edit-catalog-visibility').show();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
var value = $('input[name=_visibility]:checked').val();
|
|
|
|
var label = $('input[name=_visibility]:checked').attr('data-label');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
if ( $('input[name=_featured]').is(':checked') ) {
|
|
|
|
label = label + ', ' + woocommerce_writepanel_params.featured_label
|
|
|
|
$('input[name=_featured]').attr('checked', 'checked');
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
$('#catalog-visibility-display').text( label );
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#catalog-visibility .cancel-post-visibility').click(function () {
|
|
|
|
$('#catalog-visibility-select').slideUp('fast');
|
|
|
|
$('#catalog-visibility .edit-catalog-visibility').show();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
var current_visibility = $('#current_visibilty').val();
|
|
|
|
var current_featured = $('#current_featured').val();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
$('input[name=_visibility]').removeAttr('checked');
|
|
|
|
$('input[name=_visibility][value=' + current_visibility + ']').attr('checked', 'checked');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
var label = $('input[name=_visibility]:checked').attr('data-label');
|
|
|
|
|
|
|
|
if ( current_featured == 'yes' ) {
|
|
|
|
label = label + ', ' + woocommerce_writepanel_params.featured_label
|
|
|
|
$('input[name=_featured]').attr('checked', 'checked');
|
|
|
|
} else {
|
|
|
|
$('input[name=_featured]').removeAttr('checked');
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-22 12:50:45 +00:00
|
|
|
$('#catalog-visibility-display').text( label );
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +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;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-06 15:46:53 +00:00
|
|
|
// Chosen selects
|
|
|
|
jQuery("select.chosen_select").chosen();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-06 15:46:53 +00:00
|
|
|
jQuery("select.chosen_select_nostd").chosen({
|
|
|
|
allow_single_deselect: 'true'
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-12 17:26:11 +00:00
|
|
|
// Ajax Chosen Product Selectors
|
2012-03-06 15:46:53 +00:00
|
|
|
jQuery("select.ajax_chosen_select_products").ajaxChosen({
|
|
|
|
method: 'GET',
|
|
|
|
url: woocommerce_writepanel_params.ajax_url,
|
|
|
|
dataType: 'json',
|
2012-07-31 17:26:25 +00:00
|
|
|
afterTypeDelay: 100,
|
2012-03-06 15:46:53 +00:00
|
|
|
data: {
|
|
|
|
action: 'woocommerce_json_search_products',
|
|
|
|
security: woocommerce_writepanel_params.search_products_nonce
|
|
|
|
}
|
|
|
|
}, function (data) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-06 15:46:53 +00:00
|
|
|
var terms = {};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-06 15:46:53 +00:00
|
|
|
$.each(data, function (i, val) {
|
|
|
|
terms[i] = val;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-06 15:46:53 +00:00
|
|
|
return terms;
|
2012-08-01 12:43:46 +00:00
|
|
|
});
|
|
|
|
|
2012-03-12 17:26:11 +00:00
|
|
|
jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({
|
|
|
|
method: 'GET',
|
|
|
|
url: woocommerce_writepanel_params.ajax_url,
|
|
|
|
dataType: 'json',
|
2012-03-13 12:18:15 +00:00
|
|
|
afterTypeDelay: 100,
|
2012-03-12 17:26:11 +00:00
|
|
|
data: {
|
|
|
|
action: 'woocommerce_json_search_products_and_variations',
|
2012-03-06 15:46:53 +00:00
|
|
|
security: woocommerce_writepanel_params.search_products_nonce
|
2012-03-12 17:26:11 +00:00
|
|
|
}
|
|
|
|
}, function (data) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-31 17:26:25 +00:00
|
|
|
var terms = {};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-31 17:26:25 +00:00
|
|
|
$.each(data, function (i, val) {
|
|
|
|
terms[i] = val;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-31 17:26:25 +00:00
|
|
|
return terms;
|
|
|
|
});
|
2012-03-06 15:46:53 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// ORDERS
|
2012-01-27 15:00:03 +00:00
|
|
|
jQuery('#woocommerce-order-actions input, #woocommerce-order-actions a').click(function(){
|
|
|
|
window.onbeforeunload = '';
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-28 13:06:58 +00:00
|
|
|
$('a.edit_address').click(function(event){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-25 19:31:06 +00:00
|
|
|
$(this).hide();
|
|
|
|
$(this).closest('.order_data').find('div.address').hide();
|
|
|
|
$(this).closest('.order_data').find('div.edit_address').show();
|
2012-02-28 13:06:58 +00:00
|
|
|
event.preventDefault();
|
2011-11-25 19:31:06 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
$('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 } });
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.calc_line_taxes);
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
if (answer) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
var $items = $('#order_items_list tr.item');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
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();
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
$items.each(function( idx ){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
var $row = $(this);
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_calc_line_taxes',
|
2012-01-22 02:36:46 +00:00
|
|
|
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(),
|
2012-01-13 21:25:39 +00:00
|
|
|
country: country,
|
|
|
|
state: state,
|
|
|
|
postcode: postcode,
|
|
|
|
security: woocommerce_writepanel_params.calc_totals_nonce
|
|
|
|
};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
$.post( woocommerce_writepanel_params.ajax_url, data, function(response) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
result = jQuery.parseJSON( response );
|
2012-01-22 02:36:46 +00:00
|
|
|
$row.find('input.line_subtotal_tax').val( result.line_subtotal_tax );
|
|
|
|
$row.find('input.line_tax').val( result.line_tax );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
if (idx == ($items.size() - 1)) {
|
|
|
|
$('.woocommerce_order_items_wrapper').unblock();
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$('.woocommerce_order_items_wrapper').unblock();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}).hover(function() {
|
2012-01-22 02:36:46 +00:00
|
|
|
$('#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax').css('background-color', '#d8c8d2');
|
2012-01-13 21:25:39 +00:00
|
|
|
}, function() {
|
2012-01-22 02:36:46 +00:00
|
|
|
$('#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax').css('background-color', '');
|
2012-01-13 21:25:39 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.calc_totals').live('click', function(){
|
2012-01-13 21:25:39 +00:00
|
|
|
// 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 } });
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.calc_totals);
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
if (answer) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
// Get row totals
|
2012-06-10 08:08:11 +00:00
|
|
|
var line_subtotals = 0;
|
|
|
|
var line_subtotal_taxes = 0;
|
|
|
|
var line_totals = 0;
|
|
|
|
var cart_discount = 0;
|
|
|
|
var cart_tax = 0;
|
2012-01-13 21:25:39 +00:00
|
|
|
var order_shipping = parseFloat( $('#_order_shipping').val() );
|
|
|
|
var order_shipping_tax = parseFloat( $('#_order_shipping_tax').val() );
|
|
|
|
var order_discount = parseFloat( $('#_order_discount').val() );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-06-10 08:08:11 +00:00
|
|
|
if ( ! order_shipping ) order_shipping = 0;
|
|
|
|
if ( ! order_shipping_tax ) order_shipping_tax = 0;
|
|
|
|
if ( ! order_discount ) order_discount = 0;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
$('#order_items_list tr.item').each(function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-22 02:36:46 +00:00
|
|
|
var line_subtotal = parseFloat( $(this).find('input.line_subtotal').val() );
|
|
|
|
var line_subtotal_tax = parseFloat( $(this).find('input.line_subtotal_tax').val() );
|
2012-06-10 08:08:11 +00:00
|
|
|
var line_total = parseFloat( $(this).find('input.line_total').val() );
|
|
|
|
var line_tax = parseFloat( $(this).find('input.line_tax').val() );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-06-10 08:08:11 +00:00
|
|
|
if ( ! line_subtotal ) line_subtotal = 0;
|
|
|
|
if ( ! line_subtotal_tax ) line_subtotal_tax = 0;
|
|
|
|
if ( ! line_total ) line_total = 0;
|
|
|
|
if ( ! line_tax ) line_tax = 0;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-22 02:36:46 +00:00
|
|
|
line_subtotals = parseFloat( line_subtotals + line_subtotal );
|
|
|
|
line_subtotal_taxes = parseFloat( line_subtotal_taxes + line_subtotal_tax );
|
|
|
|
line_totals = parseFloat( line_totals + line_total );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
if (woocommerce_writepanel_params.round_at_subtotal=='no') {
|
|
|
|
line_tax = parseFloat( line_tax.toFixed( 2 ) );
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-22 02:36:46 +00:00
|
|
|
cart_tax = parseFloat( cart_tax + line_tax );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
// Tax
|
|
|
|
if (woocommerce_writepanel_params.round_at_subtotal=='yes') {
|
|
|
|
cart_tax = parseFloat( cart_tax.toFixed( 2 ) );
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
// Cart discount
|
2012-01-22 02:36:46 +00:00
|
|
|
var cart_discount = ( (line_subtotals + line_subtotal_taxes) - (line_totals + cart_tax) );
|
|
|
|
if (cart_discount<0) cart_discount = 0;
|
2012-01-13 21:25:39 +00:00
|
|
|
cart_discount = cart_discount.toFixed( 2 );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
// Total
|
2012-01-22 02:36:46 +00:00
|
|
|
var order_total = line_totals + cart_tax + order_shipping + order_shipping_tax - order_discount;
|
2012-01-13 21:25:39 +00:00
|
|
|
order_total = order_total.toFixed( 2 );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
// Set fields
|
|
|
|
$('#_cart_discount').val( cart_discount );
|
|
|
|
$('#_order_tax').val( cart_tax );
|
|
|
|
$('#_order_total').val( order_total );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
// Since we currently cannot calc shipping from the backend, ditch the rows. They must be manually calculated.
|
2012-01-27 15:00:03 +00:00
|
|
|
$('#tax_rows').empty();
|
2012-01-13 21:25:39 +00:00
|
|
|
|
|
|
|
$('#woocommerce-order-totals').unblock();
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2012-01-13 21:25:39 +00:00
|
|
|
} else {
|
|
|
|
$('#woocommerce-order-totals').unblock();
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
2012-01-13 21:25:39 +00:00
|
|
|
}).hover(function() {
|
|
|
|
$('#woocommerce-order-totals .calculated').css('background-color', '#d8c8d2');
|
|
|
|
}, function() {
|
|
|
|
$('#woocommerce-order-totals .calculated').css('background-color', '');
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.add_shop_order_item').click(function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
var add_item_ids = $('select#add_item_id').val();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
if ( add_item_ids ) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
count = add_item_ids.length;
|
2012-08-01 12:43:46 +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 } });
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-10 16:51:37 +00:00
|
|
|
var size = $('table.woocommerce_order_items tbody tr.item').size();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
$.each( add_item_ids, function( index, value ) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_add_order_item',
|
|
|
|
item_to_add: value,
|
|
|
|
index: size,
|
|
|
|
security: woocommerce_writepanel_params.add_order_item_nonce
|
|
|
|
};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
$.post( woocommerce_writepanel_params.ajax_url, data, function(response) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
|
|
|
$('table.woocommerce_order_items tbody#order_items_list').append( response );
|
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
if (!--count) {
|
|
|
|
$('select#add_item_id, #add_item_id_chzn .chzn-choices').css('border-color', '').val('');
|
|
|
|
jQuery(".tips").tipTip({
|
|
|
|
'attribute' : 'data-tip',
|
|
|
|
'fadeIn' : 50,
|
2012-07-22 12:50:45 +00:00
|
|
|
'fadeOut' : 50,
|
|
|
|
'delay' : 200
|
2012-04-10 00:39:31 +00:00
|
|
|
});
|
|
|
|
$('select#add_item_id').trigger("liszt:updated");
|
|
|
|
$('table.woocommerce_order_items').unblock();
|
2012-08-01 12:43:46 +00:00
|
|
|
}
|
2012-04-10 00:39:31 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-07-10 16:51:37 +00:00
|
|
|
size++;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
2012-04-10 00:39:31 +00:00
|
|
|
$('select#add_item_id, #add_item_id_chzn .chzn-choices').css('border-color', 'red');
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('button.add_meta').live('click', function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var index = $(this).closest('tr.item').attr('rel');
|
2012-08-01 12:43:46 +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>');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-19 20:11:04 +00:00
|
|
|
return false;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +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;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$('button.load_customer_billing').live('click', function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.load_billing);
|
|
|
|
if (answer){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
// Get user ID to load data for
|
|
|
|
var user_id = $('#customer_user').val();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
if (!user_id) {
|
|
|
|
alert(woocommerce_writepanel_params.no_customer_selected);
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
var data = {
|
|
|
|
user_id: user_id,
|
|
|
|
type_to_load: 'billing',
|
|
|
|
action: 'woocommerce_get_customer_details',
|
|
|
|
security: woocommerce_writepanel_params.get_customer_details_nonce
|
|
|
|
};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$(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 } });
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_writepanel_params.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
|
|
|
var info = jQuery.parseJSON(response);
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
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 );
|
2012-07-11 15:22:18 +00:00
|
|
|
$('#_billing_country').val( info.billing_country );
|
2011-11-26 16:15:25 +00:00
|
|
|
$('input#_billing_state').val( info.billing_state );
|
|
|
|
$('input#_billing_email').val( info.billing_email );
|
|
|
|
$('input#_billing_phone').val( info.billing_phone );
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$('.edit_address').unblock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$('button.load_customer_shipping').live('click', function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.load_shipping);
|
|
|
|
if (answer){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
// Get user ID to load data for
|
|
|
|
var user_id = $('#customer_user').val();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
if (!user_id) {
|
|
|
|
alert(woocommerce_writepanel_params.no_customer_selected);
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
var data = {
|
|
|
|
user_id: user_id,
|
|
|
|
type_to_load: 'shipping',
|
|
|
|
action: 'woocommerce_get_customer_details',
|
|
|
|
security: woocommerce_writepanel_params.get_customer_details_nonce
|
|
|
|
};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$(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 } });
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_writepanel_params.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
|
|
|
var info = jQuery.parseJSON(response);
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
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 );
|
2012-07-11 15:22:18 +00:00
|
|
|
$('#_shipping_country').val( info.shipping_country );
|
2011-11-26 16:15:25 +00:00
|
|
|
$('input#_shipping_state').val( info.shipping_state );
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-26 16:15:25 +00:00
|
|
|
$('.edit_address').unblock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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() );
|
2012-08-01 12:43:46 +00:00
|
|
|
$('input#_shipping_state').val( $('input#_billing_state').val() );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-27 15:00:03 +00:00
|
|
|
$('a.add_tax_row').live('click', function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-27 15:00:03 +00:00
|
|
|
var size = $('#tax_rows .tax_row').size();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-27 15:00:03 +00:00
|
|
|
$('#tax_rows').append('<div class="tax_row">\
|
|
|
|
<p class="first">\
|
|
|
|
<label>' + woocommerce_writepanel_params.tax_label + '</label>\
|
|
|
|
<input type="text" name="_order_taxes_label[' + size + ']" placeholder="' + woocommerce_writepanel_params.tax_or_vat + '" />\
|
|
|
|
</p>\
|
|
|
|
<p class="last">\
|
|
|
|
<label>' + woocommerce_writepanel_params.compound_label + '\
|
|
|
|
<input type="checkbox" name="_order_taxes_compound[' + size + ']" /></label>\
|
|
|
|
</p>\
|
|
|
|
<p class="first">\
|
|
|
|
<label>' + woocommerce_writepanel_params.cart_tax_label + '</label>\
|
|
|
|
<input type="text" name="_order_taxes_cart[' + size + ']" placeholder="0.00" />\
|
|
|
|
</p>\
|
|
|
|
<p class="last">\
|
|
|
|
<label>' + woocommerce_writepanel_params.shipping_tax_label + '</label>\
|
|
|
|
<input type="text" name="_order_taxes_shipping[' + size + ']" placeholder="0.00" />\
|
|
|
|
</p>\
|
|
|
|
<a href="#" class="delete_tax_row">×</a>\
|
|
|
|
<div class="clear"></div>\
|
|
|
|
</div>');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-27 15:00:03 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-01-27 15:00:03 +00:00
|
|
|
$('a.delete_tax_row').live('click', function(){
|
|
|
|
$tax_row = $(this).closest('.tax_row');
|
|
|
|
$tax_row.find('input').val('');
|
|
|
|
$tax_row.hide();
|
2011-12-31 19:03:41 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// PRODUCT TYPE SPECIFIC OPTIONS
|
|
|
|
$('select#product-type').change(function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// Get value
|
2011-11-05 19:03:03 +00:00
|
|
|
var select_val = $(this).val();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-05-08 14:32:30 +00:00
|
|
|
$('.hide_if_grouped, .hide_if_external').show();
|
2011-11-08 16:15:36 +00:00
|
|
|
$('.show_if_simple, .show_if_variable, .show_if_grouped, .show_if_external').hide();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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
|
|
|
}
|
2012-08-01 12:43:46 +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
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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();
|
2012-01-13 21:25:39 +00:00
|
|
|
$('.hide_if_grouped').hide();
|
2011-11-05 19:03:03 +00:00
|
|
|
}
|
2012-08-01 12:43:46 +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();
|
2012-05-08 14:32:30 +00:00
|
|
|
$('.hide_if_external').hide();
|
2011-11-08 16:15:36 +00:00
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('ul.tabs li:visible').eq(0).find('a').click();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-10 17:11:11 +00:00
|
|
|
$('body').trigger('woocommerce-product-type-change', select_val, $(this) );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
}).change();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_downloadable').change(function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
$('.show_if_downloadable').hide();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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();
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-06 13:45:18 +00:00
|
|
|
if ($('.downloads_tab').is('.active')) $('ul.tabs li:visible').eq(0).find('a').click();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
}).change();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-12-24 16:57:36 +00:00
|
|
|
$('input#_virtual').change(function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-06 13:45:18 +00:00
|
|
|
$('.show_if_virtual').hide();
|
2011-12-24 15:32:18 +00:00
|
|
|
$('.hide_if_virtual').show();
|
2012-08-01 12:43:46 +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
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-06 13:45:18 +00:00
|
|
|
}).change();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-12-24 15:32:18 +00:00
|
|
|
$('.sale_schedule').click(function(){
|
|
|
|
$(this).hide();
|
|
|
|
$('.sale_price_dates_fields').show();
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-12-24 15:32:18 +00:00
|
|
|
$('.cancel_sale_schedule').click(function(){
|
|
|
|
$(this).closest('p').find('input').val('');
|
|
|
|
$('.sale_schedule').show();
|
|
|
|
$('.sale_price_dates_fields').hide();
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// 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
|
|
|
});
|
2012-08-01 12:43:46 +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
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-26 17:30:00 +00:00
|
|
|
$( ".date-picker-field" ).datepicker({
|
|
|
|
dateFormat: "yy-mm-dd",
|
|
|
|
numberOfMonths: 1,
|
|
|
|
showButtonPanel: true,
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-25 11:43:25 +00:00
|
|
|
// META BOXES
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-15 20:18:01 +00:00
|
|
|
jQuery('.expand_all').click(function(){
|
2012-06-14 09:36:39 +00:00
|
|
|
jQuery(this).closest('.wc-metaboxes-wrapper').find('.wc-metabox > table').show();
|
2012-02-15 20:18:01 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-15 20:18:01 +00:00
|
|
|
jQuery('.close_all').click(function(){
|
2012-06-14 09:36:39 +00:00
|
|
|
jQuery(this).closest('.wc-metaboxes-wrapper').find('.wc-metabox > table').hide();
|
2012-02-15 20:18:01 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-13 19:21:52 +00:00
|
|
|
// Open/close
|
2012-03-15 13:20:44 +00:00
|
|
|
jQuery('.wc-metaboxes-wrapper').on('click', '.wc-metabox h3', function(event){
|
|
|
|
// If the user clicks on some form input inside the h3, like a select list (for variations), the box should not be toggled
|
2012-03-20 14:59:04 +00:00
|
|
|
if ($(event.target).filter(':input, option').length) return;
|
2012-03-15 13:20:44 +00:00
|
|
|
|
2012-02-25 19:48:09 +00:00
|
|
|
jQuery(this).next('.wc-metabox-content').toggle();
|
2012-02-13 19:21:52 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-25 11:43:25 +00:00
|
|
|
jQuery('.wc-metabox.closed').each(function(){
|
2012-02-25 19:48:09 +00:00
|
|
|
jQuery(this).find('.wc-metabox-content').hide();
|
2012-02-13 19:21:52 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-25 11:43:25 +00:00
|
|
|
// ATTRIBUTE TABLES
|
|
|
|
|
2011-09-11 17:35:22 +00:00
|
|
|
// Multiselect attributes
|
2012-08-01 12:43:46 +00:00
|
|
|
$(".woocommerce_attributes select.multiselect").chosen();
|
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// Initial order
|
2012-02-13 19:21:52 +00:00
|
|
|
var woocommerce_attribute_items = $('.woocommerce_attributes').find('.woocommerce_attribute').get();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-13 19:21:52 +00:00
|
|
|
woocommerce_attribute_items.sort(function(a, b) {
|
|
|
|
var compA = parseInt($(a).attr('rel'));
|
|
|
|
var compB = parseInt($(b).attr('rel'));
|
2011-08-09 15:16:18 +00:00
|
|
|
return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
|
|
|
|
})
|
2012-02-13 19:21:52 +00:00
|
|
|
$(woocommerce_attribute_items).each( function(idx, itm) { $('.woocommerce_attributes').append(itm); } );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-03-13 13:26:20 +00:00
|
|
|
function attribute_row_indexes() {
|
2012-08-01 12:43:46 +00:00
|
|
|
$('.woocommerce_attributes .woocommerce_attribute').each(function(index, el){
|
|
|
|
$('.attribute_position', el).val( parseInt( $(el).index('.woocommerce_attributes .woocommerce_attribute') ) );
|
2012-02-13 19:21:52 +00:00
|
|
|
});
|
2011-08-09 15:16:18 +00:00
|
|
|
};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// Add rows
|
2012-02-13 19:21:52 +00:00
|
|
|
$('button.add_attribute').on('click', function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-13 19:21:52 +00:00
|
|
|
var size = $('.woocommerce_attributes .woocommerce_attribute').size();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-05 19:03:03 +00:00
|
|
|
var attribute_type = $('select.attribute_taxonomy').val();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
if (!attribute_type) {
|
2012-08-01 12:43:46 +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 = '';
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// Add custom attribute row
|
2012-03-04 12:42:24 +00:00
|
|
|
$('.woocommerce_attributes').append('<div class="woocommerce_attribute wc-metabox">\
|
2012-02-13 19:21:52 +00:00
|
|
|
<h3>\
|
|
|
|
<button type="button" class="remove_row button">' + woocommerce_writepanel_params.remove_label + '</button>\
|
|
|
|
<div class="handlediv" title="' + woocommerce_writepanel_params.click_to_toggle + '"></div>\
|
|
|
|
<strong class="attribute_name"></strong>\
|
|
|
|
</h3>\
|
|
|
|
<table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data">\
|
|
|
|
<tbody>\
|
|
|
|
<tr>\
|
|
|
|
<td class="attribute_name">\
|
|
|
|
<label>' + woocommerce_writepanel_params.name_label + ':</label>\
|
|
|
|
<input type="text" class="attribute_name" 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 rowspan="3">\
|
|
|
|
<label>' + woocommerce_writepanel_params.values_label + ':</label>\
|
2012-02-14 10:59:00 +00:00
|
|
|
<textarea name="attribute_values[' + size + ']" cols="5" rows="5" placeholder="' + woocommerce_writepanel_params.text_attribute_tip + '"></textarea>\
|
2012-02-13 19:21:52 +00:00
|
|
|
</td>\
|
|
|
|
</tr>\
|
|
|
|
<tr>\
|
|
|
|
<td>\
|
|
|
|
<label><input type="checkbox" class="checkbox" checked="checked" name="attribute_visibility[' + size + ']" value="1" /> ' + woocommerce_writepanel_params.visible_label + '</label>\
|
|
|
|
</td>\
|
|
|
|
</tr>\
|
|
|
|
<tr>\
|
|
|
|
<td>\
|
|
|
|
<div class="enable_variation show_if_variable" ' + enable_variation + '>\
|
|
|
|
<label><input type="checkbox" class="checkbox" name="attribute_variation[' + size + ']" value="1" /> ' + woocommerce_writepanel_params.used_for_variations_label + '</label>\
|
|
|
|
</div>\
|
|
|
|
</td>\
|
|
|
|
</tr>\
|
|
|
|
</tbody>\
|
|
|
|
</table>\
|
|
|
|
</div>');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
} else {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
// Reveal taxonomy row
|
2012-02-13 19:21:52 +00:00
|
|
|
var thisrow = $('.woocommerce_attributes .woocommerce_attribute.' + attribute_type);
|
|
|
|
$('.woocommerce_attributes').append( $(thisrow) );
|
|
|
|
$(thisrow).show().find('.woocommerce_attribute_data').show();
|
2012-03-13 13:26:20 +00:00
|
|
|
attribute_row_indexes();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-09 18:10:38 +00:00
|
|
|
$('select.attribute_taxonomy').val('');
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-13 19:21:52 +00:00
|
|
|
$('.woocommerce_attributes').on('blur', 'input.attribute_name', function(){
|
|
|
|
$(this).closest('.woocommerce_attribute').find('strong.attribute_name').text( $(this).val() );
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-13 19:21:52 +00:00
|
|
|
$('.woocommerce_attributes').on('click', 'button.select_all_attributes', function(){
|
|
|
|
$(this).closest('td').find('select option').attr("selected","selected");
|
|
|
|
$(this).closest('td').find('select').trigger("liszt:updated");
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-13 19:21:52 +00:00
|
|
|
$('.woocommerce_attributes').on('click', 'button.select_no_attributes', function(){
|
|
|
|
$(this).closest('td').find('select option').removeAttr("selected");
|
|
|
|
$(this).closest('td').find('select').trigger("liszt:updated");
|
2011-08-09 15:16:18 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
$('.woocommerce_attributes').on('click', 'button.remove_row', function() {
|
2012-02-12 16:29:32 +00:00
|
|
|
var answer = confirm(woocommerce_writepanel_params.remove_attribute);
|
2011-08-09 15:16:18 +00:00
|
|
|
if (answer){
|
2012-02-13 19:21:52 +00:00
|
|
|
var $parent = $(this).parent().parent();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-02-13 19:21:52 +00:00
|
|
|
if ($parent.is('.taxonomy')) {
|
|
|
|
$parent.find('select, input[type=text]').val('');
|
|
|
|
$parent.hide();
|
|
|
|
} else {
|
|
|
|
$parent.find('select, input[type=text]').val('');
|
|
|
|
$parent.hide();
|
2012-03-13 13:26:20 +00:00
|
|
|
attribute_row_indexes();
|
2012-02-13 19:21:52 +00:00
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-09-19 14:57:17 +00:00
|
|
|
// Attribute ordering
|
2012-02-13 19:21:52 +00:00
|
|
|
$('.woocommerce_attributes').sortable({
|
|
|
|
items:'.woocommerce_attribute',
|
2011-09-19 14:57:17 +00:00
|
|
|
cursor:'move',
|
|
|
|
axis:'y',
|
2012-02-13 19:21:52 +00:00
|
|
|
handle: 'h3',
|
2011-09-19 14:57:17 +00:00
|
|
|
scrollSensitivity:40,
|
2012-02-13 19:21:52 +00:00
|
|
|
forcePlaceholderSize: true,
|
|
|
|
helper: 'clone',
|
|
|
|
opacity: 0.65,
|
2012-02-25 11:43:25 +00:00
|
|
|
placeholder: 'wc-metabox-sortable-placeholder',
|
2011-09-19 14:57:17 +00:00
|
|
|
start:function(event,ui){
|
|
|
|
ui.item.css('background-color','#f6f6f6');
|
|
|
|
},
|
|
|
|
stop:function(event,ui){
|
|
|
|
ui.item.removeAttr('style');
|
2012-03-13 13:26:20 +00:00
|
|
|
attribute_row_indexes();
|
2011-09-19 14:57:17 +00:00
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
// Add a new attribute (via ajax)
|
|
|
|
$('.woocommerce_attributes').on('click', 'button.add_new_attribute', function() {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
$('.woocommerce_attributes').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
var attribute = $(this).attr('data-attribute');
|
|
|
|
var $wrapper = $(this).closest('.woocommerce_attribute_data');
|
|
|
|
var new_attribute_name = prompt( woocommerce_writepanel_params.new_attribute_prompt );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
if ( new_attribute_name ) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_add_new_attribute',
|
|
|
|
taxonomy: attribute,
|
|
|
|
term: new_attribute_name,
|
|
|
|
security: woocommerce_writepanel_params.add_attribute_nonce
|
|
|
|
};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
$.post( woocommerce_writepanel_params.ajax_url, data, function( response ) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
result = jQuery.parseJSON( response );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
if ( result.error ) {
|
|
|
|
// Error
|
|
|
|
alert( result.error );
|
|
|
|
} else if ( result.slug ) {
|
|
|
|
// Success
|
|
|
|
$wrapper.find('select.attribute_values').append('<option value="' + result.slug + '" selected="selected">' + result.name + '</option>');
|
|
|
|
$wrapper.find('select.attribute_values').trigger("liszt:updated");
|
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
$('.woocommerce_attributes').unblock();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-05-26 16:42:26 +00:00
|
|
|
} else {
|
|
|
|
$('.woocommerce_attributes').unblock();
|
2012-04-08 23:57:38 +00:00
|
|
|
}
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
return false;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-08 23:57:38 +00:00
|
|
|
});
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-09 23:06:17 +00:00
|
|
|
// Uploading files
|
|
|
|
var file_path_field;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-09 23:06:17 +00:00
|
|
|
window.send_to_editor_default = window.send_to_editor;
|
|
|
|
|
|
|
|
jQuery('.upload_file_button').live('click', function(){
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-09 23:06:17 +00:00
|
|
|
file_path_field = jQuery(this).parent().find('.file_path');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-09 23:06:17 +00:00
|
|
|
formfield = jQuery(file_path_field).attr('name');
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-09 23:06:17 +00:00
|
|
|
window.send_to_editor = window.send_to_download_url;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
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) {
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-09 23:06:17 +00:00
|
|
|
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;
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2011-11-09 23:06:17 +00:00
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
|
|
|
|
});
|