Do not show "Adding new attribute failed" error message when loading of product screens is interrupted by page unload (#38815)
* Suppress "adding new attribute failed" error message on page unload * Only attempt to add empty attribute if page has attributes list
This commit is contained in:
parent
72a6f2b503
commit
6076458471
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Do not show "Adding new attribute failed" error message when loading of product screens is interrupted by page unload.
|
|
@ -1,5 +1,11 @@
|
|||
/*global woocommerce_admin_meta_boxes */
|
||||
jQuery( function ( $ ) {
|
||||
let isPageUnloading = false;
|
||||
|
||||
$( window ).on( 'beforeunload', function () {
|
||||
isPageUnloading = true;
|
||||
} );
|
||||
|
||||
// Scroll to first checked category
|
||||
// https://github.com/scribu/wp-category-checklist-tree/blob/d1c3c1f449e1144542efa17dde84a9f52ade1739/category-checklist-tree.php
|
||||
$( function () {
|
||||
|
@ -432,28 +438,27 @@ jQuery( function ( $ ) {
|
|||
} );
|
||||
} );
|
||||
|
||||
// Attribute Tables.
|
||||
|
||||
// Initial order.
|
||||
var woocommerce_attribute_items = $( '.product_attributes' )
|
||||
.find( '.woocommerce_attribute' )
|
||||
.get();
|
||||
// Set up attributes, if current page has the attributes list.
|
||||
const $product_attributes = $( '.product_attributes' );
|
||||
if ( $product_attributes.length === 1 ) {
|
||||
var woocommerce_attribute_items = $product_attributes.find( '.woocommerce_attribute' ).get();
|
||||
|
||||
// If the product has no attributes, add an empty attribute to be filled out by the user.
|
||||
$( function add_blank_custom_attribute_if_no_attributes() {
|
||||
if ( woocommerce_attribute_items.length === 0 ) {
|
||||
add_custom_attribute_to_list();
|
||||
}
|
||||
} );
|
||||
|
||||
// Sort the attributes by their position.
|
||||
woocommerce_attribute_items.sort( function ( a, b ) {
|
||||
var compA = parseInt( $( a ).attr( 'rel' ), 10 );
|
||||
var compB = parseInt( $( b ).attr( 'rel' ), 10 );
|
||||
return compA < compB ? -1 : compA > compB ? 1 : 0;
|
||||
} );
|
||||
|
||||
$( woocommerce_attribute_items ).each( function ( index, el ) {
|
||||
$( '.product_attributes' ).append( el );
|
||||
$product_attributes.append( el );
|
||||
} );
|
||||
}
|
||||
|
||||
function update_attribute_row_indexes() {
|
||||
$( '.product_attributes .woocommerce_attribute' ).each( function (
|
||||
|
@ -571,9 +576,13 @@ jQuery( function ( $ ) {
|
|||
disable_or_enable_fields();
|
||||
jQuery.maybe_disable_save_button();
|
||||
} catch ( error ) {
|
||||
alert(
|
||||
woocommerce_admin_meta_boxes.i18n_add_attribute_error_notice
|
||||
);
|
||||
if ( isPageUnloading ) {
|
||||
// If the page is unloading, the outstanding ajax fetch may fail in Firefox (and possible other browsers, too).
|
||||
// We don't want to show an error message in this case, because it was caused by the user leaving the page.
|
||||
return;
|
||||
}
|
||||
|
||||
alert( woocommerce_admin_meta_boxes.i18n_add_attribute_error_notice );
|
||||
throw error;
|
||||
} finally {
|
||||
unblock_attributes_tab_container();
|
||||
|
|
Loading…
Reference in New Issue