2017-09-21 20:09:36 +00:00
|
|
|
/* global jQuery, woocommerce_admin_system_status, wcSetClipboard, wcClearClipboard */
|
2016-11-09 11:36:14 +00:00
|
|
|
jQuery( function ( $ ) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Users country and state fields
|
|
|
|
*/
|
|
|
|
var wcSystemStatus = {
|
|
|
|
init: function() {
|
|
|
|
$( document.body )
|
|
|
|
.on( 'click', 'a.help_tip, a.woocommerce-help-tip', this.preventTipTipClick )
|
|
|
|
.on( 'click', 'a.debug-report', this.generateReport )
|
2017-09-21 20:09:36 +00:00
|
|
|
.on( 'click', '#copy-for-support', this.copyReport )
|
|
|
|
.on( 'aftercopy', '#copy-for-support', this.copySuccess )
|
|
|
|
.on( 'aftercopyfailure', '#copy-for-support', this.copyFail );
|
2016-11-09 11:36:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevent anchor behavior when click on TipTip.
|
|
|
|
*
|
|
|
|
* @return {Bool}
|
|
|
|
*/
|
|
|
|
preventTipTipClick: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate system status report.
|
|
|
|
*
|
|
|
|
* @return {Bool}
|
|
|
|
*/
|
|
|
|
generateReport: function() {
|
|
|
|
var report = '';
|
|
|
|
|
|
|
|
$( '.wc_status_table thead, .wc_status_table tbody' ).each( function() {
|
|
|
|
if ( $( this ).is( 'thead' ) ) {
|
|
|
|
var label = $( this ).find( 'th:eq(0)' ).data( 'export-label' ) || $( this ).text();
|
2021-01-07 22:15:15 +00:00
|
|
|
report = report + '\n### ' + label.trim() + ' ###\n\n';
|
2016-11-09 11:36:14 +00:00
|
|
|
} else {
|
|
|
|
$( 'tr', $( this ) ).each( function() {
|
|
|
|
var label = $( this ).find( 'td:eq(0)' ).data( 'export-label' ) || $( this ).find( 'td:eq(0)' ).text();
|
2021-01-07 22:15:15 +00:00
|
|
|
var the_name = label.trim().replace( /(<([^>]+)>)/ig, '' ); // Remove HTML.
|
2016-11-09 11:36:14 +00:00
|
|
|
|
|
|
|
// Find value
|
|
|
|
var $value_html = $( this ).find( 'td:eq(2)' ).clone();
|
|
|
|
$value_html.find( '.private' ).remove();
|
|
|
|
$value_html.find( '.dashicons-yes' ).replaceWith( '✔' );
|
|
|
|
$value_html.find( '.dashicons-no-alt, .dashicons-warning' ).replaceWith( '❌' );
|
|
|
|
|
|
|
|
// Format value
|
2021-01-07 22:15:15 +00:00
|
|
|
var the_value = $value_html.text().trim();
|
2016-11-09 11:36:14 +00:00
|
|
|
var value_array = the_value.split( ', ' );
|
|
|
|
|
|
|
|
if ( value_array.length > 1 ) {
|
|
|
|
// If value have a list of plugins ','.
|
|
|
|
// Split to add new line.
|
|
|
|
var temp_line ='';
|
|
|
|
$.each( value_array, function( key, line ) {
|
|
|
|
temp_line = temp_line + line + '\n';
|
|
|
|
});
|
|
|
|
|
|
|
|
the_value = temp_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
report = report + '' + the_name + ': ' + the_value + '\n';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
$( '#debug-report' ).slideDown();
|
2021-02-04 17:17:18 +00:00
|
|
|
$( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).trigger( 'focus' ).trigger( 'select' );
|
2016-11-09 11:36:14 +00:00
|
|
|
$( this ).fadeOut();
|
|
|
|
return false;
|
|
|
|
} catch ( e ) {
|
|
|
|
/* jshint devel: true */
|
|
|
|
console.log( e );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy for report.
|
|
|
|
*
|
|
|
|
* @param {Object} evt Copy event.
|
|
|
|
*/
|
|
|
|
copyReport: function( evt ) {
|
2017-09-21 20:09:36 +00:00
|
|
|
wcClearClipboard();
|
|
|
|
wcSetClipboard( $( '#debug-report' ).find( 'textarea' ).val(), $( this ) );
|
2016-11-09 11:36:14 +00:00
|
|
|
evt.preventDefault();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2017-09-21 20:09:36 +00:00
|
|
|
* Display a "Copied!" tip when success copying
|
2016-11-09 11:36:14 +00:00
|
|
|
*/
|
2017-09-21 20:09:36 +00:00
|
|
|
copySuccess: function() {
|
|
|
|
$( '#copy-for-support' ).tipTip({
|
|
|
|
'attribute': 'data-tip',
|
|
|
|
'activation': 'focus',
|
|
|
|
'fadeIn': 50,
|
|
|
|
'fadeOut': 50,
|
|
|
|
'delay': 0
|
2021-02-04 17:17:18 +00:00
|
|
|
}).trigger( 'focus' );
|
2017-09-21 20:09:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the copy error message when failure copying.
|
|
|
|
*/
|
|
|
|
copyFail: function() {
|
|
|
|
$( '.copy-error' ).removeClass( 'hidden' );
|
2021-02-04 17:17:18 +00:00
|
|
|
$( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).trigger( 'select' );
|
2016-11-09 11:36:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wcSystemStatus.init();
|
2017-04-25 21:10:47 +00:00
|
|
|
|
2020-06-01 21:56:38 +00:00
|
|
|
$( '.wc_status_table' ).on( 'click', '.run-tool .button', function( evt ) {
|
|
|
|
evt.stopImmediatePropagation();
|
|
|
|
return window.confirm( woocommerce_admin_system_status.run_tool_confirmation );
|
|
|
|
});
|
|
|
|
|
2017-04-26 01:45:42 +00:00
|
|
|
$( '#log-viewer-select' ).on( 'click', 'h2 a.page-title-action', function( evt ) {
|
|
|
|
evt.stopImmediatePropagation();
|
|
|
|
return window.confirm( woocommerce_admin_system_status.delete_log_confirmation );
|
2017-04-25 21:10:47 +00:00
|
|
|
});
|
2016-11-09 11:36:14 +00:00
|
|
|
});
|