api-keys.js
5 years ago
api-keys.min.js
3 years ago
backbone-modal.js
2 years ago
backbone-modal.min.js
2 years ago
marketplace-suggestions.js
1 year ago
marketplace-suggestions.min.js
1 year ago
meta-boxes-coupon.js
1 year ago
meta-boxes-coupon.min.js
1 year ago
meta-boxes-order.js
2 months ago
meta-boxes-order.min.js
2 months ago
meta-boxes-product-variation.js
1 month ago
meta-boxes-product-variation.min.js
1 month ago
meta-boxes-product.js
1 month ago
meta-boxes-product.min.js
1 month ago
meta-boxes.js
6 months ago
meta-boxes.min.js
6 months ago
network-orders.js
8 years ago
network-orders.min.js
3 years ago
order-attribution-admin.js
2 years ago
order-attribution-admin.min.js
2 years ago
product-editor.js
1 year ago
product-editor.min.js
1 year ago
product-ordering.js
5 months ago
product-ordering.min.js
5 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 month ago
settings-views-html-settings-tax.min.js
1 month ago
settings.js
1 year ago
settings.min.js
1 year ago
system-status.js
1 month ago
system-status.min.js
1 month ago
term-ordering.js
5 months ago
term-ordering.min.js
5 months ago
users.js
5 years ago
users.min.js
3 years ago
variation-gallery.js
2 months ago
variation-gallery.min.js
2 months 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
1 year ago
wc-customer-stock-notifications.min.js
1 year ago
wc-enhanced-select.js
1 month ago
wc-enhanced-select.min.js
1 month ago
wc-orders.js
3 weeks ago
wc-orders.min.js
3 weeks 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
3 years ago
wc-recent-reviews-widget-async.js
6 months ago
wc-recent-reviews-widget-async.min.js
6 months ago
wc-setup.js
5 years ago
wc-setup.min.js
3 years ago
wc-shipping-classes.js
1 year ago
wc-shipping-classes.min.js
1 year ago
wc-shipping-providers.js
5 months ago
wc-shipping-providers.min.js
5 months ago
wc-shipping-zone-methods.js
7 months ago
wc-shipping-zone-methods.min.js
7 months ago
wc-shipping-zones.js
1 year ago
wc-shipping-zones.min.js
1 year ago
wc-status-widget-async.js
6 months ago
wc-status-widget-async.min.js
6 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
272 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 | toolsPollTimer: null, |
| 8 | toolsPollInProgress: false, |
| 9 | |
| 10 | init: function () { |
| 11 | $( document.body ) |
| 12 | .on( |
| 13 | 'click', |
| 14 | 'a.help_tip, a.woocommerce-help-tip, woocommerce-product-type-tip', |
| 15 | this.preventTipTipClick |
| 16 | ) |
| 17 | .on( 'click', 'a.debug-report', this.generateReport ) |
| 18 | .on( 'click', '#copy-for-support', this.copyReport ) |
| 19 | .on( 'click', '#copy-for-github', this.copyGithubReport ) |
| 20 | .on( 'aftercopy', '#copy-for-support, #copy-for-github', this.copySuccess ) |
| 21 | .on( 'aftercopyfailure', '#copy-for-support, #copy-for-github', this.copyFail ) |
| 22 | .on( 'click', '#download-for-support', this.downloadReport ); |
| 23 | |
| 24 | this.maybePollTools(); |
| 25 | }, |
| 26 | |
| 27 | /** |
| 28 | * Start polling the tools page if a background tool is running. |
| 29 | */ |
| 30 | maybePollTools: function() { |
| 31 | if ( |
| 32 | this.toolsPollTimer || |
| 33 | ! woocommerce_admin_system_status.tools_url || |
| 34 | ! this.shouldPollTools() |
| 35 | ) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | this.toolsPollTimer = window.setInterval( |
| 40 | $.proxy( this.pollTools, this ), |
| 41 | parseInt( woocommerce_admin_system_status.tools_poll_interval, 10 ) || 10000 |
| 42 | ); |
| 43 | }, |
| 44 | |
| 45 | /** |
| 46 | * Check whether any tool rows still need polling. |
| 47 | * |
| 48 | * @return {Bool} |
| 49 | */ |
| 50 | shouldPollTools: function() { |
| 51 | return $( '.wc_status_table--tools tr.requires-refresh' ).is( function() { |
| 52 | var $row = $( this ); |
| 53 | return $row.find( '.run-tool-status' ).length > 0 || $row.find( '.run-tool .button:disabled' ).length > 0; |
| 54 | }); |
| 55 | }, |
| 56 | |
| 57 | /** |
| 58 | * Refresh background tool rows from the tools page. |
| 59 | */ |
| 60 | pollTools: function() { |
| 61 | if ( this.toolsPollInProgress ) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | this.toolsPollInProgress = true; |
| 66 | |
| 67 | var self = this; |
| 68 | var toolsUrl = woocommerce_admin_system_status.tools_url; |
| 69 | var pollUrl = toolsUrl + ( toolsUrl.indexOf( '?' ) === -1 ? '?' : '&' ) + 'wc_status_tools_poll=' + Date.now(); |
| 70 | |
| 71 | $.get( pollUrl ) |
| 72 | .done( function( response ) { |
| 73 | var $response = $( '<div>' ).append( $.parseHTML( response ) ); |
| 74 | |
| 75 | $( '.wc_status_table--tools tr.requires-refresh' ).each( function() { |
| 76 | var $currentRow = $( this ); |
| 77 | var action = $currentRow.data( 'tool-action' ); |
| 78 | |
| 79 | if ( ! action ) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | var $updatedRow = $response.find( '.wc_status_table--tools tr[data-tool-action="' + action + '"]' ); |
| 84 | |
| 85 | if ( $updatedRow.length ) { |
| 86 | $currentRow.replaceWith( $updatedRow ); |
| 87 | } |
| 88 | }); |
| 89 | |
| 90 | if ( ! self.shouldPollTools() ) { |
| 91 | window.clearInterval( self.toolsPollTimer ); |
| 92 | self.toolsPollTimer = null; |
| 93 | } |
| 94 | }) |
| 95 | .fail( function() { |
| 96 | window.clearInterval( self.toolsPollTimer ); |
| 97 | self.toolsPollTimer = null; |
| 98 | }) |
| 99 | .always( function() { |
| 100 | self.toolsPollInProgress = false; |
| 101 | }); |
| 102 | }, |
| 103 | |
| 104 | /** |
| 105 | * Prevent anchor behavior when click on TipTip. |
| 106 | * |
| 107 | * @return {Bool} |
| 108 | */ |
| 109 | preventTipTipClick: function() { |
| 110 | return false; |
| 111 | }, |
| 112 | |
| 113 | /** |
| 114 | * Generate system status report. |
| 115 | * |
| 116 | * @return {Bool} |
| 117 | */ |
| 118 | generateReport: function() { |
| 119 | var report = ''; |
| 120 | |
| 121 | $( '.wc_status_table thead, .wc_status_table tbody' ).each( function() { |
| 122 | if ( $( this ).is( 'thead' ) ) { |
| 123 | var label = $( this ).find( 'th:eq(0)' ).data( 'exportLabel' ) || $( this ).text(); |
| 124 | report = report + '\n### ' + label.trim() + ' ###\n\n'; |
| 125 | } else { |
| 126 | $( 'tr', $( this ) ).each( function() { |
| 127 | var label = $( this ).find( 'td:eq(0)' ).data( 'exportLabel' ) || $( this ).find( 'td:eq(0)' ).text(); |
| 128 | var the_name = label.trim().replace( /(<([^>]+)>)/ig, '' ); // Remove HTML. |
| 129 | |
| 130 | // Find value |
| 131 | var $value_html = $( this ).find( 'td:eq(2)' ).clone(); |
| 132 | $value_html.find( '.private' ).remove(); |
| 133 | $value_html.find( '.dashicons-yes' ).replaceWith( '✔' ); |
| 134 | $value_html.find( '.dashicons-no-alt, .dashicons-warning' ).replaceWith( '❌' ); |
| 135 | |
| 136 | // Format value |
| 137 | var the_value = $value_html.text().trim(); |
| 138 | var value_array = the_value.split( ', ' ); |
| 139 | |
| 140 | if ( value_array.length > 1 ) { |
| 141 | // If value have a list of plugins ','. |
| 142 | // Split to add new line. |
| 143 | var temp_line =''; |
| 144 | $.each( value_array, function( key, line ) { |
| 145 | temp_line = temp_line + line + '\n'; |
| 146 | }); |
| 147 | |
| 148 | the_value = temp_line; |
| 149 | } |
| 150 | |
| 151 | if ( the_name || the_value ) { |
| 152 | report = report + '' + the_name + ': ' + the_value + '\n'; |
| 153 | } else { |
| 154 | report = report + '\n'; |
| 155 | } |
| 156 | }); |
| 157 | } |
| 158 | }); |
| 159 | |
| 160 | try { |
| 161 | $( '#debug-report' ).slideDown(); |
| 162 | $( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).trigger( 'focus' ).trigger( 'select' ); |
| 163 | $( this ).fadeOut(); |
| 164 | return false; |
| 165 | } catch ( e ) { |
| 166 | /* jshint devel: true */ |
| 167 | window.console.log( e ); |
| 168 | } |
| 169 | |
| 170 | return false; |
| 171 | }, |
| 172 | |
| 173 | /** |
| 174 | * Copy for report. |
| 175 | * |
| 176 | * @param {Object} evt Copy event. |
| 177 | */ |
| 178 | copyReport: function( evt ) { |
| 179 | wcClearClipboard(); |
| 180 | wcSetClipboard( $( '#debug-report' ).find( 'textarea' ).val(), $( this ) ); |
| 181 | evt.preventDefault(); |
| 182 | }, |
| 183 | /** |
| 184 | * Apply redactions |
| 185 | */ |
| 186 | applyRedactions( report ) { |
| 187 | var redactions = [ |
| 188 | { |
| 189 | regex: /(WordPress address \(URL\):)[^\n]*/, |
| 190 | replacement: "$1 [Redacted]" |
| 191 | }, |
| 192 | { |
| 193 | regex: /(Site address \(URL\):)[^\n]*/, |
| 194 | replacement: "$1 [Redacted]" |
| 195 | }, |
| 196 | { |
| 197 | regex: /(### Database ###\n)([\s\S]*?)(\n### Post Type Counts ###)/, |
| 198 | replacement: "$1\n[REDACTED]\n$3" |
| 199 | } |
| 200 | ]; |
| 201 | |
| 202 | redactions.forEach( function( redaction ) { |
| 203 | report = report.replace( redaction.regex, redaction.replacement ); |
| 204 | }); |
| 205 | return report; |
| 206 | }, |
| 207 | /** |
| 208 | * Copy for GitHub report. |
| 209 | * |
| 210 | * @param {Object} event Copy event. |
| 211 | */ |
| 212 | copyGithubReport: function( event ) { |
| 213 | wcClearClipboard(); |
| 214 | var reportValue = $( '#debug-report' ).find( 'textarea' ).val(); |
| 215 | var redactedReport = wcSystemStatus.applyRedactions( reportValue ); |
| 216 | |
| 217 | var reportForGithub = '<details><summary>System Status Report</summary>\n\n``' + redactedReport + '``\n</details>'; |
| 218 | |
| 219 | wcSetClipboard( reportForGithub, $( this ) ); |
| 220 | event.preventDefault(); |
| 221 | }, |
| 222 | |
| 223 | /** |
| 224 | * Display a "Copied!" tip when success copying |
| 225 | */ |
| 226 | copySuccess: function( event ) { |
| 227 | $( event.target ).tipTip({ |
| 228 | 'attribute': 'data-tip', |
| 229 | 'activation': 'focus', |
| 230 | 'fadeIn': 50, |
| 231 | 'fadeOut': 50, |
| 232 | 'delay': 0 |
| 233 | }).trigger( 'focus' ); |
| 234 | }, |
| 235 | |
| 236 | /** |
| 237 | * Displays the copy error message when failure copying. |
| 238 | */ |
| 239 | copyFail: function() { |
| 240 | $( '.copy-error' ).removeClass( 'hidden' ); |
| 241 | $( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).trigger( 'select' ); |
| 242 | }, |
| 243 | |
| 244 | downloadReport: function() { |
| 245 | var ssr_text = new Blob( [ $( '#debug-report' ).find( 'textarea' ).val() ], { type: 'text/plain' } ); |
| 246 | |
| 247 | var domain = window.location.hostname; |
| 248 | var datetime = new Date().toISOString().slice( 0, 19 ).replace( /:/g, '-' ); |
| 249 | |
| 250 | var a = document.createElement( 'a' ); |
| 251 | a.download = 'SystemStatusReport_' + domain + '_' + datetime + '.txt'; |
| 252 | a.href = window.URL.createObjectURL( ssr_text ); |
| 253 | a.textContent = 'Download ready'; |
| 254 | a.style='display:none'; |
| 255 | a.click(); |
| 256 | a.remove(); |
| 257 | } |
| 258 | }; |
| 259 | |
| 260 | wcSystemStatus.init(); |
| 261 | |
| 262 | $( '.wc_status_table' ).on( 'click', '.run-tool input.button', function( evt ) { |
| 263 | evt.stopImmediatePropagation(); |
| 264 | return window.confirm( woocommerce_admin_system_status.run_tool_confirmation ); |
| 265 | }); |
| 266 | |
| 267 | $( '#log-viewer-select' ).on( 'click', 'h2 a.page-title-action', function( evt ) { |
| 268 | evt.stopImmediatePropagation(); |
| 269 | return window.confirm( woocommerce_admin_system_status.delete_log_confirmation ); |
| 270 | }); |
| 271 | }); |
| 272 |