woocommerce/assets/js/admin/settings-views-html-setting...

113 lines
2.6 KiB
JavaScript
Raw Normal View History

/* global htmlSettingsTaxLocalizeScript */
/**
* Used by woocommerce/includes/admin/settings/views/html-settings-tax.php
*/
(function($, data, wp){
var rowTemplate = wp.template( 'wc-tax-table-row' ),
$tbody = $('#rates');
$(function() {
$tbody.innerHTML = '';
$.each( data.rates, function ( id, rowData ) {
$tbody.append( rowTemplate( rowData ) );
} );
// Initialize autocomplete for countries.
$tbody.find( 'td.country input' ).autocomplete({
source: data.countries,
minLength: 3
});
// Initialize autocomplete for states.
$tbody.find( 'td.state input' ).autocomplete({
source: data.states,
minLength: 3
});
});
2015-08-07 15:42:49 +00:00
$('.wc_tax_rates .remove_tax_rates').click(function() {
if ( $tbody.find('tr.current').length > 0 ) {
var $current = $tbody.find('tr.current');
2015-08-07 15:42:49 +00:00
$current.find('input').val('');
$current.find('input.remove_tax_rate').val('1');
$current.each(function(){
if ( $(this).is('.new') ) {
$( this ).remove();
} else {
$( this ).hide();
}
2015-08-07 15:42:49 +00:00
});
} else {
window.alert( data.strings.no_rows_selected );
2015-08-07 15:42:49 +00:00
}
return false;
});
$('.wc_tax_rates .export').click(function() {
var csv_data = 'data:application/csv;charset=utf-8,' + data.strings.csv_data_cols.join(',') + '\n';
2015-08-07 15:42:49 +00:00
$('#rates tr:visible').each(function() {
2015-08-07 15:42:49 +00:00
var row = '';
$(this).find('td:not(.sort) input').each(function() {
var val = '';
2015-08-07 15:42:49 +00:00
if ( $(this).is('.checkbox') ) {
if ( $(this).is(':checked') ) {
2015-08-07 15:42:49 +00:00
val = 1;
} else {
val = 0;
}
} else {
val = $(this).val();
if ( ! val ) {
val = $( this ).attr( 'placeholder' );
}
2015-08-07 15:42:49 +00:00
}
row = row + val + ',';
});
2015-08-07 15:58:16 +00:00
row = row + data.current_class;
2015-08-07 15:42:49 +00:00
//row.substring( 0, row.length - 1 );
csv_data = csv_data + row + '\n';
2015-08-07 15:42:49 +00:00
});
$(this).attr( 'href', encodeURI( csv_data ) );
2015-08-07 15:42:49 +00:00
return true;
});
$('.wc_tax_rates .insert').click(function() {
var size = $tbody.find('tr').length;
2015-08-07 15:42:49 +00:00
var code = wp.template( 'wc-tax-table-row' )( {
tax_rate_id : 'new-' + size,
tax_rate_priority : 1,
tax_rate_shipping : 1,
newRow : true
2015-08-07 15:42:49 +00:00
} );
if ( $tbody.find('tr.current').length > 0 ) {
2015-08-07 15:42:49 +00:00
$tbody.find('tr.current').after( code );
} else {
$tbody.append( code );
}
$( 'td.country input' ).autocomplete({
source: data.countries,
2015-08-07 15:42:49 +00:00
minLength: 3
});
$( 'td.state input' ).autocomplete({
source: data.states,
2015-08-07 15:42:49 +00:00
minLength: 3
});
return false;
});
$('.wc_tax_rates td.postcode, .wc_tax_rates td.city').find('input').change(function() {
$(this).attr( 'name', $(this).attr( 'data-name' ) );
2015-08-07 15:42:49 +00:00
});
})(jQuery, htmlSettingsTaxLocalizeScript, wp);