api-keys.js
5 years ago
api-keys.min.js
2 years ago
backbone-modal.js
2 years ago
backbone-modal.min.js
2 years ago
marketplace-suggestions.js
10 months ago
marketplace-suggestions.min.js
10 months ago
meta-boxes-coupon.js
1 year ago
meta-boxes-coupon.min.js
1 year ago
meta-boxes-order.js
1 month ago
meta-boxes-order.min.js
1 month ago
meta-boxes-product-variation.js
1 year ago
meta-boxes-product-variation.min.js
1 year ago
meta-boxes-product.js
1 month ago
meta-boxes-product.min.js
1 month ago
meta-boxes.js
4 months ago
meta-boxes.min.js
4 months ago
network-orders.js
8 years ago
network-orders.min.js
2 years ago
order-attribution-admin.js
2 years ago
order-attribution-admin.min.js
2 years ago
product-editor.js
11 months ago
product-editor.min.js
11 months ago
product-ordering.js
3 months ago
product-ordering.min.js
3 months ago
quick-edit.js
1 year ago
quick-edit.min.js
1 year ago
reports.js
1 year ago
reports.min.js
1 year ago
settings-views-html-settings-tax.js
1 year ago
settings-views-html-settings-tax.min.js
1 year ago
settings.js
1 year ago
settings.min.js
1 year ago
system-status.js
3 months ago
system-status.min.js
3 months ago
term-ordering.js
3 months ago
term-ordering.min.js
3 months ago
users.js
5 years ago
users.min.js
2 years ago
variation-gallery.js
1 month ago
variation-gallery.min.js
1 month ago
wc-brands-enhanced-select.js
1 year ago
wc-brands-enhanced-select.min.js
1 year ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-customer-stock-notifications.js
10 months ago
wc-customer-stock-notifications.min.js
10 months ago
wc-enhanced-select.js
2 years ago
wc-enhanced-select.min.js
2 years ago
wc-orders.js
3 years ago
wc-orders.min.js
2 years ago
wc-product-export.js
1 year ago
wc-product-export.min.js
1 year ago
wc-product-import.js
3 years ago
wc-product-import.min.js
2 years ago
wc-recent-reviews-widget-async.js
4 months ago
wc-recent-reviews-widget-async.min.js
4 months ago
wc-setup.js
5 years ago
wc-setup.min.js
2 years ago
wc-shipping-classes.js
1 year ago
wc-shipping-classes.min.js
1 year ago
wc-shipping-providers.js
3 months ago
wc-shipping-providers.min.js
3 months ago
wc-shipping-zone-methods.js
5 months ago
wc-shipping-zone-methods.min.js
5 months ago
wc-shipping-zones.js
1 year ago
wc-shipping-zones.min.js
1 year ago
wc-status-widget-async.js
4 months ago
wc-status-widget-async.min.js
4 months ago
wc-status-widget.js
1 year ago
wc-status-widget.min.js
1 year ago
woocommerce_admin.js
1 month ago
woocommerce_admin.min.js
1 month ago
system-status.js
190 lines
| 1 | /* global jQuery, woocommerce_admin_system_status, wcSetClipboard, wcClearClipboard */ |
| 2 | jQuery( function ( $ ) { |
| 3 | /** |
| 4 | * Users country and state fields |
| 5 | */ |
| 6 | var wcSystemStatus = { |
| 7 | init: function () { |
| 8 | $( document.body ) |
| 9 | .on( |
| 10 | 'click', |
| 11 | 'a.help_tip, a.woocommerce-help-tip, woocommerce-product-type-tip', |
| 12 | this.preventTipTipClick |
| 13 | ) |
| 14 | .on( 'click', 'a.debug-report', this.generateReport ) |
| 15 | .on( 'click', '#copy-for-support', this.copyReport ) |
| 16 | .on( 'click', '#copy-for-github', this.copyGithubReport ) |
| 17 | .on( 'aftercopy', '#copy-for-support, #copy-for-github', this.copySuccess ) |
| 18 | .on( 'aftercopyfailure', '#copy-for-support, #copy-for-github', this.copyFail ) |
| 19 | .on( 'click', '#download-for-support', this.downloadReport ); |
| 20 | }, |
| 21 | |
| 22 | /** |
| 23 | * Prevent anchor behavior when click on TipTip. |
| 24 | * |
| 25 | * @return {Bool} |
| 26 | */ |
| 27 | preventTipTipClick: function() { |
| 28 | return false; |
| 29 | }, |
| 30 | |
| 31 | /** |
| 32 | * Generate system status report. |
| 33 | * |
| 34 | * @return {Bool} |
| 35 | */ |
| 36 | generateReport: function() { |
| 37 | var report = ''; |
| 38 | |
| 39 | $( '.wc_status_table thead, .wc_status_table tbody' ).each( function() { |
| 40 | if ( $( this ).is( 'thead' ) ) { |
| 41 | var label = $( this ).find( 'th:eq(0)' ).data( 'exportLabel' ) || $( this ).text(); |
| 42 | report = report + '\n### ' + label.trim() + ' ###\n\n'; |
| 43 | } else { |
| 44 | $( 'tr', $( this ) ).each( function() { |
| 45 | var label = $( this ).find( 'td:eq(0)' ).data( 'exportLabel' ) || $( this ).find( 'td:eq(0)' ).text(); |
| 46 | var the_name = label.trim().replace( /(<([^>]+)>)/ig, '' ); // Remove HTML. |
| 47 | |
| 48 | // Find value |
| 49 | var $value_html = $( this ).find( 'td:eq(2)' ).clone(); |
| 50 | $value_html.find( '.private' ).remove(); |
| 51 | $value_html.find( '.dashicons-yes' ).replaceWith( '✔' ); |
| 52 | $value_html.find( '.dashicons-no-alt, .dashicons-warning' ).replaceWith( '❌' ); |
| 53 | |
| 54 | // Format value |
| 55 | var the_value = $value_html.text().trim(); |
| 56 | var value_array = the_value.split( ', ' ); |
| 57 | |
| 58 | if ( value_array.length > 1 ) { |
| 59 | // If value have a list of plugins ','. |
| 60 | // Split to add new line. |
| 61 | var temp_line =''; |
| 62 | $.each( value_array, function( key, line ) { |
| 63 | temp_line = temp_line + line + '\n'; |
| 64 | }); |
| 65 | |
| 66 | the_value = temp_line; |
| 67 | } |
| 68 | |
| 69 | if ( the_name || the_value ) { |
| 70 | report = report + '' + the_name + ': ' + the_value + '\n'; |
| 71 | } else { |
| 72 | report = report + '\n'; |
| 73 | } |
| 74 | }); |
| 75 | } |
| 76 | }); |
| 77 | |
| 78 | try { |
| 79 | $( '#debug-report' ).slideDown(); |
| 80 | $( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).trigger( 'focus' ).trigger( 'select' ); |
| 81 | $( this ).fadeOut(); |
| 82 | return false; |
| 83 | } catch ( e ) { |
| 84 | /* jshint devel: true */ |
| 85 | console.log( e ); |
| 86 | } |
| 87 | |
| 88 | return false; |
| 89 | }, |
| 90 | |
| 91 | /** |
| 92 | * Copy for report. |
| 93 | * |
| 94 | * @param {Object} evt Copy event. |
| 95 | */ |
| 96 | copyReport: function( evt ) { |
| 97 | wcClearClipboard(); |
| 98 | wcSetClipboard( $( '#debug-report' ).find( 'textarea' ).val(), $( this ) ); |
| 99 | evt.preventDefault(); |
| 100 | }, |
| 101 | /** |
| 102 | * Apply redactions |
| 103 | */ |
| 104 | applyRedactions( report ) { |
| 105 | var redactions = [ |
| 106 | { |
| 107 | regex: /(WordPress address \(URL\):)[^\n]*/, |
| 108 | replacement: "$1 [Redacted]" |
| 109 | }, |
| 110 | { |
| 111 | regex: /(Site address \(URL\):)[^\n]*/, |
| 112 | replacement: "$1 [Redacted]" |
| 113 | }, |
| 114 | { |
| 115 | regex: /(### Database ###\n)([\s\S]*?)(\n### Post Type Counts ###)/, |
| 116 | replacement: "$1\n[REDACTED]\n$3" |
| 117 | } |
| 118 | ]; |
| 119 | |
| 120 | redactions.forEach( function( redaction ) { |
| 121 | report = report.replace( redaction.regex, redaction.replacement ); |
| 122 | }); |
| 123 | return report; |
| 124 | }, |
| 125 | /** |
| 126 | * Copy for GitHub report. |
| 127 | * |
| 128 | * @param {Object} event Copy event. |
| 129 | */ |
| 130 | copyGithubReport: function( event ) { |
| 131 | wcClearClipboard(); |
| 132 | var reportValue = $( '#debug-report' ).find( 'textarea' ).val(); |
| 133 | var redactedReport = wcSystemStatus.applyRedactions( reportValue ); |
| 134 | |
| 135 | var reportForGithub = '<details><summary>System Status Report</summary>\n\n``' + redactedReport + '``\n</details>'; |
| 136 | |
| 137 | wcSetClipboard( reportForGithub, $( this ) ); |
| 138 | event.preventDefault(); |
| 139 | }, |
| 140 | |
| 141 | /** |
| 142 | * Display a "Copied!" tip when success copying |
| 143 | */ |
| 144 | copySuccess: function( event ) { |
| 145 | $( event.target ).tipTip({ |
| 146 | 'attribute': 'data-tip', |
| 147 | 'activation': 'focus', |
| 148 | 'fadeIn': 50, |
| 149 | 'fadeOut': 50, |
| 150 | 'delay': 0 |
| 151 | }).trigger( 'focus' ); |
| 152 | }, |
| 153 | |
| 154 | /** |
| 155 | * Displays the copy error message when failure copying. |
| 156 | */ |
| 157 | copyFail: function() { |
| 158 | $( '.copy-error' ).removeClass( 'hidden' ); |
| 159 | $( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).trigger( 'select' ); |
| 160 | }, |
| 161 | |
| 162 | downloadReport: function() { |
| 163 | var ssr_text = new Blob( [ $( '#debug-report' ).find( 'textarea' ).val() ], { type: 'text/plain' } ); |
| 164 | |
| 165 | var domain = window.location.hostname; |
| 166 | var datetime = new Date().toISOString().slice( 0, 19 ).replace( /:/g, '-' ); |
| 167 | |
| 168 | var a = document.createElement( 'a' ); |
| 169 | a.download = 'SystemStatusReport_' + domain + '_' + datetime + '.txt'; |
| 170 | a.href = window.URL.createObjectURL( ssr_text ); |
| 171 | a.textContent = 'Download ready'; |
| 172 | a.style='display:none'; |
| 173 | a.click(); |
| 174 | a.remove(); |
| 175 | } |
| 176 | }; |
| 177 | |
| 178 | wcSystemStatus.init(); |
| 179 | |
| 180 | $( '.wc_status_table' ).on( 'click', '.run-tool .button', function( evt ) { |
| 181 | evt.stopImmediatePropagation(); |
| 182 | return window.confirm( woocommerce_admin_system_status.run_tool_confirmation ); |
| 183 | }); |
| 184 | |
| 185 | $( '#log-viewer-select' ).on( 'click', 'h2 a.page-title-action', function( evt ) { |
| 186 | evt.stopImmediatePropagation(); |
| 187 | return window.confirm( woocommerce_admin_system_status.delete_log_confirmation ); |
| 188 | }); |
| 189 | }); |
| 190 |