Stop for change inputs when add a new variation on admin, closes #8874

This commit is contained in:
Claudio Sanches 2015-08-18 13:00:38 -03:00
parent c6ec8dfd26
commit b6b34255d2
2 changed files with 35 additions and 28 deletions

View File

@ -66,29 +66,36 @@ jQuery( function( $ ) {
/** /**
* Run actions when variations is loaded * Run actions when variations is loaded
*
* @param {Object} event
* @param {Int} needsUpdate
*/ */
variations_loaded: function() { variations_loaded: function( event, needsUpdate ) {
needsUpdate = needsUpdate || false;
var wrapper = $( '#woocommerce-product-data' ); var wrapper = $( '#woocommerce-product-data' );
// Show/hide downloadable, virtual and stock fields if ( ! needsUpdate ) {
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock', wrapper ).change(); // Show/hide downloadable, virtual and stock fields
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock', wrapper ).change();
// Open sale schedule fields when have some sale price date // Open sale schedule fields when have some sale price date
$( '.woocommerce_variation', wrapper ).each( function( index, el ) { $( '.woocommerce_variation', wrapper ).each( function( index, el ) {
var $el = $( el ), var $el = $( el ),
date_from = $( '.sale_price_dates_from', $el ).val(), date_from = $( '.sale_price_dates_from', $el ).val(),
date_to = $( '.sale_price_dates_to', $el ).val(); date_to = $( '.sale_price_dates_to', $el ).val();
if ( '' !== date_from || '' !== date_to ) { if ( '' !== date_from || '' !== date_to ) {
$( 'a.sale_schedule', $el ).click(); $( 'a.sale_schedule', $el ).click();
} }
}); });
// Remove variation-needs-update classes // Remove variation-needs-update classes
$( '.woocommerce_variations .variation-needs-update', wrapper ).removeClass( 'variation-needs-update' ); $( '.woocommerce_variations .variation-needs-update', wrapper ).removeClass( 'variation-needs-update' );
// Disable cancel and save buttons // Disable cancel and save buttons
$( 'button.cancel-variation-changes, button.save-variation-changes', wrapper ).attr( 'disabled', 'disabled' ); $( 'button.cancel-variation-changes, button.save-variation-changes', wrapper ).attr( 'disabled', 'disabled' );
}
// Init TipTip // Init TipTip
$( '#tiptip_holder' ).removeAttr( 'style' ); $( '#tiptip_holder' ).removeAttr( 'style' );
@ -119,16 +126,16 @@ jQuery( function( $ ) {
}); });
// Allow sorting // Allow sorting
jQuery( '.woocommerce_variations' ).sortable({ $( '.woocommerce_variations', wrapper ).sortable({
items : '.woocommerce_variation', items: '.woocommerce_variation',
cursor : 'move', cursor: 'move',
axis : 'y', axis: 'y',
handle : '.sort', handle: '.sort',
scrollSensitivity : 40, scrollSensitivity: 40,
forcePlaceholderSize: true, forcePlaceholderSize: true,
helper : 'clone', helper: 'clone',
opacity : 0.65, opacity: 0.65,
stop : function () { stop: function() {
wc_meta_boxes_product_variations_actions.variation_row_indexes(); wc_meta_boxes_product_variations_actions.variation_row_indexes();
} }
}); });
@ -139,12 +146,12 @@ jQuery( function( $ ) {
/** /**
* Run actions when added a variation * Run actions when added a variation
* *
* @param {Object} event [description] * @param {Object} event
* @param {Int} qty * @param {Int} qty
*/ */
variation_added: function( event, qty ) { variation_added: function( event, qty ) {
if ( 1 === qty ) { if ( 1 === qty ) {
wc_meta_boxes_product_variations_actions.variations_loaded(); wc_meta_boxes_product_variations_actions.variations_loaded( null, true );
} }
}, },

File diff suppressed because one or more lines are too long