| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| | |
| 6 | 6 | | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | | |
| 7 | 7 | | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| | |
| 8 | 8 | | | |
| 9 | - | (c) Jerome Bruandet ~ https://code-profiler.com/ | | |
| 9 | + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ | | |
| 10 | 10 | +=====================================================================+ |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // ===================================================================== |
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | |
| 16 | 16 | // TipTip tooltip |
| 17 | 17 | jQuery( document ).ready(function( $ ) { |
| 18 | 18 | 'use strict'; |
| 19 | - $( '.code-profiler-tip' ).tipTip( { | |
| 19 | + $('.code-profiler-tip').tipTip( { | |
| 20 | 20 | 'attribute': 'data-tip', |
| 21 | 21 | 'fadeIn': 50, |
| 22 | 22 | 'fadeOut': 50, |
| 23 | 23 | 'delay': 100, |
| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | // if the user reloaded the page that would throw an error: |
| 29 | 29 | var url = window.location.href; |
| 30 | 30 | window.history.replaceState({}, |
| 31 | 31 | document.title, |
| 32 | - url.replace( /&action=delete_profiles&.+/, '' ) | |
| 32 | + url.replace( /&action=delete_profiles&.+/, '') | |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | 35 | }); |
| 36 | 36 | |
| @@ -44,21 +44,21 @@ | ||
| 44 | 44 | // Case sensitivity |
| 45 | 45 | if ( jQuery('#case-search-input').is(':checked') === true ) { |
| 46 | 46 | query += '&c=1'; |
| 47 | 47 | } |
| 48 | - jQuery("#profile-form").attr('action', jQuery("#profile-form").attr('action')+ query ); | |
| 48 | + jQuery('#profile-form').attr('action', jQuery('#profile-form').attr('action')+ query ); | |
| 49 | 49 | |
| 50 | 50 | } else { |
| 51 | - jQuery("#profile-form").attr('action','' ); | |
| 51 | + jQuery('#profile-form').attr('action',''); | |
| 52 | 52 | var url = window.location.href; |
| 53 | 53 | window.history.replaceState({}, |
| 54 | 54 | document.title, |
| 55 | - url.replace( /&s=[^&$]+/, '' ) | |
| 55 | + url.replace( /&s=[^&$]+/, '') | |
| 56 | 56 | ); |
| 57 | 57 | var url = window.location.href; |
| 58 | 58 | window.history.replaceState({}, |
| 59 | 59 | document.title, |
| 60 | - url.replace( /&c=1/, '' ) | |
| 60 | + url.replace( /&c=1/, '') | |
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| @@ -81,9 +81,9 @@ | ||
| 81 | 81 | jQuery('#p-custom').hide(); |
| 82 | 82 | jQuery('#id-backend').focus(); |
| 83 | 83 | jQuery('#user-unauthenticated').prop('disabled', true); |
| 84 | 84 | jQuery('#user-authenticated').prop('checked', true); |
| 85 | - jQuery("#user-name").prop('disabled', false); | |
| 85 | + jQuery('#user-name').prop('disabled', false); | |
| 86 | 86 | } else { |
| 87 | 87 | jQuery('#p-custom').show(); |
| 88 | 88 | jQuery('#p-frontend').hide(); |
| 89 | 89 | jQuery('#p-backend').hide(); |
| @@ -93,29 +93,55 @@ | ||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | function cpjs_authenticated( id ) { |
| 96 | 96 | if ( id == 1 ) { |
| 97 | - jQuery("#user-name").prop('disabled', false); | |
| 98 | - jQuery("#user-name").focus(); | |
| 97 | + jQuery('#user-name').prop('disabled', false); | |
| 98 | + jQuery('#user-name').focus(); | |
| 99 | 99 | } else { |
| 100 | - jQuery("#user-name").prop('disabled', true); | |
| 100 | + jQuery('#user-name').prop('disabled', true); | |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | function cpjs_show_adv_settings() { |
| 105 | - jQuery("#cp-advanced-settings").slideDown(); | |
| 106 | - jQuery("#button-adv-settings").prop('disabled', true); | |
| 105 | + jQuery('#cp-advanced-settings').slideDown(); | |
| 106 | + jQuery('#button-adv-settings').prop('disabled', true); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | function cpjs_get_post( id ) { |
| 110 | 110 | if ( id == 1 ) { |
| 111 | - jQuery("#post-value").prop('disabled', false); | |
| 112 | - jQuery("#post-value").focus(); | |
| 111 | + jQuery('#post-value').prop('disabled', false); | |
| 112 | + jQuery('#id-content-type').prop('disabled', false); | |
| 113 | + jQuery('#post-value').focus(); | |
| 113 | 114 | } else { |
| 114 | - jQuery("#post-value").prop('disabled', true); | |
| 115 | + jQuery('#post-value').prop('disabled', true); | |
| 116 | + jQuery('#id-content-type').prop('disabled', true); | |
| 115 | 117 | } |
| 116 | 118 | } |
| 117 | 119 | |
| 120 | +function cpjs_content_type( value ) { | |
| 121 | + if ( value == 1 ) { | |
| 122 | + jQuery('#ct-1').slideDown(); | |
| 123 | + jQuery('#ct-2').slideUp(); | |
| 124 | + } else { | |
| 125 | + jQuery('#ct-2').slideDown(); | |
| 126 | + jQuery('#ct-1').slideUp(); | |
| 127 | + } | |
| 128 | +} | |
| 129 | + | |
| 130 | +function cpjs_isJSON( data ) { | |
| 131 | + | |
| 132 | + if ( jQuery('#id-content-type').val() == 1 || jQuery('#get-method').prop('checked') == true ) { | |
| 133 | + // Ignore | |
| 134 | + return 1; | |
| 135 | + } | |
| 136 | + try { | |
| 137 | + return JSON.parse( data ); | |
| 138 | + } catch (e) { | |
| 139 | + // Not a JSON-encoded string | |
| 140 | + return null; | |
| 141 | + } | |
| 142 | +} | |
| 143 | + | |
| 118 | 144 | // ===================================================================== |
| 119 | 145 | // Log page: filter and delete the log. |
| 120 | 146 | |
| 121 | 147 | function cpjs_filter_log() { |
| @@ -124,8 +150,9 @@ | ||
| 124 | 150 | var bitmask = 0; |
| 125 | 151 | if ( document.cplogform.info.checked == true ) { bitmask += 1; } |
| 126 | 152 | if ( document.cplogform.warn.checked == true ) { bitmask += 2; } |
| 127 | 153 | if ( document.cplogform.error.checked == true ) { bitmask += 4; } |
| 154 | + if ( document.cplogform.debug.checked == true ) { bitmask += 8; } | |
| 128 | 155 | |
| 129 | 156 | // Clear the textarea |
| 130 | 157 | document.cplogform.cptxtlog.value = ''; |
| 131 | 158 | |
| @@ -133,9 +160,9 @@ | ||
| 133 | 160 | var cp_count = 0; |
| 134 | 161 | var i = 0; |
| 135 | 162 | for ( i = 0; i < cplog_array.length; ++i ) { |
| 136 | 163 | var line = decodeURIComponent( cplog_array[i] ); |
| 137 | - var line_array = line.split( '~~', 2 ); | |
| 164 | + var line_array = line.split('~~', 2 ); | |
| 138 | 165 | if ( line_array[0] & bitmask ) { |
| 139 | 166 | document.cplogform.cptxtlog.value += line_array[1]; |
| 140 | 167 | ++cp_count; |
| 141 | 168 | } |
| @@ -158,9 +185,9 @@ | ||
| 158 | 185 | function cpjs_start_profiler() { |
| 159 | 186 | 'use strict'; |
| 160 | 187 | // Get the nonce |
| 161 | 188 | var cp_nonce = jQuery('#cp_nonce').val(); |
| 162 | - if ( cp_nonce == '' ) { | |
| 189 | + if ( cp_nonce == '') { | |
| 163 | 190 | alert( cpi18n.missing_nonce ); |
| 164 | 191 | return; |
| 165 | 192 | } |
| 166 | 193 | |
| @@ -166,15 +193,15 @@ | ||
| 166 | 193 | |
| 167 | 194 | // Get the scan type (frontend/backend) |
| 168 | 195 | var post; |
| 169 | 196 | var where = jQuery('input[name="where"]:checked').val(); |
| 170 | - if ( where == 'frontend' ) { | |
| 197 | + if ( where == 'frontend') { | |
| 171 | 198 | post = jQuery('#id-frontend').val(); |
| 172 | 199 | |
| 173 | - } else if ( where == 'backend' ) { | |
| 200 | + } else if ( where == 'backend') { | |
| 174 | 201 | post = jQuery('#id-backend').val(); |
| 175 | 202 | |
| 176 | - } else if ( where == 'custom' ) { | |
| 203 | + } else if ( where == 'custom') { | |
| 177 | 204 | post = jQuery('#id-custom').val().trim(); // Trim user input |
| 178 | 205 | |
| 179 | 206 | } else { |
| 180 | 207 | alert( cpi18n.missing_frontbackend ); |
| @@ -179,9 +206,9 @@ | ||
| 179 | 206 | } else { |
| 180 | 207 | alert( cpi18n.missing_frontbackend ); |
| 181 | 208 | return; |
| 182 | 209 | } |
| 183 | - if ( post == '' ) { | |
| 210 | + if ( post == '') { | |
| 184 | 211 | alert( cpi18n.missing_post ); |
| 185 | 212 | return; |
| 186 | 213 | } |
| 187 | 214 | |
| @@ -186,9 +213,9 @@ | ||
| 186 | 213 | } |
| 187 | 214 | |
| 188 | 215 | // Get the profile's name |
| 189 | 216 | var profile = jQuery('input[name="profile"]').val(); |
| 190 | - if ( profile == '' ) { | |
| 217 | + if ( profile == '') { | |
| 191 | 218 | alert( cpi18n.missing_profilename ); |
| 192 | 219 | jQuery('input[name="profile"]').focus(); |
| 193 | 220 | return; |
| 194 | 221 | } |
| @@ -193,16 +220,16 @@ | ||
| 193 | 220 | return; |
| 194 | 221 | } |
| 195 | 222 | |
| 196 | 223 | var user = jQuery('input[name="user"]:checked').val(); |
| 197 | - if ( user == '' ) { | |
| 224 | + if ( user == '') { | |
| 198 | 225 | alert( cpi18n.missing_userauth ); |
| 199 | 226 | return; |
| 200 | 227 | } |
| 201 | 228 | |
| 202 | 229 | var username = jQuery('#user-name').val().trim(); // Trim user input |
| 203 | - if ( user == 'authenticated' ) { | |
| 204 | - if ( username == '' ) { | |
| 230 | + if ( user == 'authenticated') { | |
| 231 | + if ( username == '') { | |
| 205 | 232 | alert( cpi18n.missing_username ); |
| 206 | 233 | jQuery('#user-name').focus(); |
| 207 | 234 | return; |
| 208 | 235 | } |
| @@ -208,16 +235,18 @@ | ||
| 208 | 235 | } |
| 209 | 236 | } |
| 210 | 237 | |
| 211 | 238 | var ua = jQuery('#ua-id').val(); |
| 212 | - if ( ua == 'undefined' ) { | |
| 239 | + if ( ua == 'undefined') { | |
| 213 | 240 | ua = 'FireFox'; |
| 214 | 241 | } |
| 215 | 242 | |
| 243 | + var theme = jQuery('#id-theme').val(); | |
| 244 | + | |
| 216 | 245 | // GET or POST |
| 217 | 246 | var method = jQuery('input[name="method"]:checked').val(); |
| 218 | 247 | var payload = ''; |
| 219 | - if ( method == 'post' ) { | |
| 248 | + if ( method == 'post') { | |
| 220 | 249 | // Payload |
| 221 | 250 | payload = jQuery('#post-value').val(); |
| 222 | 251 | } else { |
| 223 | 252 | method = 'get'; |
| @@ -222,10 +251,23 @@ | ||
| 222 | 251 | } else { |
| 223 | 252 | method = 'get'; |
| 224 | 253 | } |
| 225 | 254 | |
| 226 | - var cookies = jQuery('#cp-cookies').val(); | |
| 255 | + //Content type | |
| 256 | + var ct = jQuery('#id-content-type').val(); | |
| 257 | + // application/json | |
| 258 | + if ( ct == 2 ) { | |
| 259 | + if ( cpjs_isJSON( payload ) == null ) { | |
| 260 | + alert( cpi18n.missing_ajax ); | |
| 261 | + jQuery('#user-name').focus(); | |
| 262 | + return; | |
| 263 | + } | |
| 264 | + } | |
| 227 | 265 | |
| 266 | + var cookies = jQuery('#cp-cookies').val(); | |
| 267 | + var headers = jQuery('#custom-headers').val(); | |
| 268 | + var exclusions = jQuery('#exclusions').val(); | |
| 269 | + | |
| 228 | 270 | // Change buttons status and add animated image with status message |
| 229 | 271 | jQuery('#start-profile').prop('disabled', true); |
| 230 | 272 | jQuery('#cp-progress-div').slideDown(); |
| 231 | 273 | jQuery('#progress-gif').slideDown(); |
| @@ -237,19 +279,23 @@ | ||
| 237 | 279 | 'action': 'codeprofiler_start_profiler', |
| 238 | 280 | 'cp_nonce': cp_nonce, |
| 239 | 281 | 'where': where, |
| 240 | 282 | 'post': post, |
| 283 | + 'content_type': ct, | |
| 241 | 284 | 'profile': profile, |
| 242 | 285 | 'user': user, |
| 243 | 286 | 'username': username, |
| 244 | 287 | 'cookies': cookies, |
| 288 | + 'custom_headers': headers, | |
| 289 | + 'exclusions': exclusions, | |
| 245 | 290 | 'method': method, |
| 246 | 291 | 'payload': payload, |
| 247 | - 'ua': ua | |
| 292 | + 'ua': ua, | |
| 293 | + 'theme': theme | |
| 248 | 294 | }; |
| 249 | 295 | // Send the request via AJAX |
| 250 | 296 | jQuery.ajax( { |
| 251 | - type: "POST", | |
| 297 | + type: 'POST', | |
| 252 | 298 | url: ajaxurl, |
| 253 | 299 | data: data, |
| 254 | 300 | dataType: 'json', |
| 255 | 301 | success: function( response ) { |
| @@ -254,14 +300,14 @@ | ||
| 254 | 300 | dataType: 'json', |
| 255 | 301 | success: function( response ) { |
| 256 | 302 | |
| 257 | 303 | if (typeof response === 'undefined') { |
| 258 | - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' ); | |
| 304 | + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>'); | |
| 259 | 305 | return; |
| 260 | 306 | } |
| 261 | 307 | |
| 262 | - if ( response.status != 'success' ) { | |
| 263 | - cpjs_start_error( '<p>'+ response.message +'</p>' ); | |
| 308 | + if ( response.status != 'success') { | |
| 309 | + cpjs_start_error('<p>'+ response.message +'</p>'); | |
| 264 | 310 | return; |
| 265 | 311 | } |
| 266 | 312 | |
| 267 | 313 | // ------------------------------------------------------------ |
| @@ -271,9 +317,9 @@ | ||
| 271 | 317 | |
| 272 | 318 | data['action'] = 'codeprofiler_prepare_report'; |
| 273 | 319 | data['microtime'] = response.microtime; |
| 274 | 320 | jQuery.ajax( { |
| 275 | - type: "POST", | |
| 321 | + type: 'POST', | |
| 276 | 322 | url: ajaxurl, |
| 277 | 323 | data: data, |
| 278 | 324 | dataType: 'json', |
| 279 | 325 | success: function( response ) { |
| @@ -278,18 +324,18 @@ | ||
| 278 | 324 | dataType: 'json', |
| 279 | 325 | success: function( response ) { |
| 280 | 326 | |
| 281 | 327 | if (typeof response === 'undefined') { |
| 282 | - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' ); | |
| 328 | + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>'); | |
| 283 | 329 | return; |
| 284 | 330 | } |
| 285 | 331 | |
| 286 | - if ( response.status != 'success' ) { | |
| 287 | - cpjs_start_error( '<p>'+ response.message +'</p>' ); | |
| 332 | + if ( response.status != 'success') { | |
| 333 | + cpjs_start_error('<p>'+ response.message +'</p>'); | |
| 288 | 334 | return; |
| 289 | 335 | } |
| 290 | 336 | var cp_uri; |
| 291 | - if (response.cp_profile !== 'undefined' && response.cp_profile != '' ) { | |
| 337 | + if (response.cp_profile !== 'undefined' && response.cp_profile != '') { | |
| 292 | 338 | cp_uri = '&cptab=profiles_list&action=view_profile&id=' + response.cp_profile + '§ion=1'; |
| 293 | 339 | } else { |
| 294 | 340 | cp_uri = '&cptab=profiles_list'; |
| 295 | 341 | } |
| @@ -302,9 +348,9 @@ | ||
| 302 | 348 | }, |
| 303 | 349 | |
| 304 | 350 | // Display non-200 HTTP response |
| 305 | 351 | error: function( xhr, status, err ) { |
| 306 | - if ( err != '' ) { | |
| 352 | + if ( err != '') { | |
| 307 | 353 | if ( xhr.status != 0 ) { |
| 308 | 354 | var message = cpi18n.http_error +' '+ xhr.status +' '+ err; |
| 309 | 355 | // Timeout |
| 310 | 356 | if ( xhr.status == 503 || xhr.status == 504 ) { |
| @@ -316,16 +362,16 @@ | ||
| 316 | 362 | } else if ( xhr.status == 403 ) { |
| 317 | 363 | cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>'); |
| 318 | 364 | // Internal error |
| 319 | 365 | } else if ( xhr.status == 500 ) { |
| 320 | - cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.</p>'); | |
| 366 | + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>'); | |
| 321 | 367 | } else { |
| 322 | - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' ); | |
| 368 | + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>'); | |
| 323 | 369 | } |
| 324 | 370 | return; |
| 325 | 371 | |
| 326 | 372 | } else { |
| 327 | - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' ); | |
| 373 | + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>'); | |
| 328 | 374 | return; |
| 329 | 375 | } |
| 330 | 376 | } |
| 331 | 377 | return; |
| @@ -335,9 +381,9 @@ | ||
| 335 | 381 | }, |
| 336 | 382 | |
| 337 | 383 | // Display non-200 HTTP response |
| 338 | 384 | error: function( xhr, status, err ) { |
| 339 | - if ( err != '' ) { | |
| 385 | + if ( err != '') { | |
| 340 | 386 | if ( xhr.status != 0 ) { |
| 341 | 387 | var message = cpi18n.http_error +' '+ xhr.status +' '+ err; |
| 342 | 388 | // Timeout |
| 343 | 389 | if ( xhr.status == 503 || xhr.status == 504 ) { |
| @@ -349,16 +395,16 @@ | ||
| 349 | 395 | } else if ( xhr.status == 403 ) { |
| 350 | 396 | cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>'); |
| 351 | 397 | // Internal error |
| 352 | 398 | } else if ( xhr.status == 500 ) { |
| 353 | - cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.</p>'); | |
| 399 | + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>'); | |
| 354 | 400 | } else { |
| 355 | - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' ); | |
| 401 | + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>'); | |
| 356 | 402 | } |
| 357 | 403 | return; |
| 358 | 404 | |
| 359 | 405 | } else { |
| 360 | - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' ); | |
| 406 | + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>'); | |
| 361 | 407 | return; |
| 362 | 408 | } |
| 363 | 409 | } |
| 364 | 410 | return; |
| @@ -389,8 +435,106 @@ | ||
| 389 | 435 | } |
| 390 | 436 | return false; |
| 391 | 437 | } |
| 392 | 438 | |
| 439 | +// Hide/show the edit box and buttons when renaming a profile. | |
| 440 | +function cpjs_toggle_name( row ) { | |
| 441 | + if ( jQuery('#profile_div_'+ row).css('display') == 'none') { | |
| 442 | + jQuery('#profile_name_'+ row).hide(); | |
| 443 | + jQuery('#profile_div_'+ row).show(); | |
| 444 | + jQuery('#edit-'+ row).val( jQuery('#profile_name_'+ row).html() ); | |
| 445 | + jQuery('#edit-'+ row).focus(); | |
| 446 | + } else { | |
| 447 | + jQuery('#profile_div_'+ row).hide(); | |
| 448 | + jQuery('#profile_name_'+ row).show(); | |
| 449 | + } | |
| 450 | +} | |
| 451 | + | |
| 452 | +// Edit the profile name via AJAX endpoint. | |
| 453 | +function cpjs_edit_name( profile, id, cp_nonce, row ) { | |
| 454 | + | |
| 455 | + 'use strict'; | |
| 456 | + | |
| 457 | + if ( cp_nonce == '') { | |
| 458 | + alert( cpi18n.missing_nonce ); | |
| 459 | + return; | |
| 460 | + } | |
| 461 | + if ( profile == '') { | |
| 462 | + alert( cpi18n.missing_profileid ); | |
| 463 | + return; | |
| 464 | + } | |
| 465 | + | |
| 466 | + var new_name = jQuery('#edit-'+ id).val().trim(); | |
| 467 | + if ( new_name == '') { | |
| 468 | + alert( cpi18n.missing_profilename ); | |
| 469 | + return; | |
| 470 | + } | |
| 471 | + | |
| 472 | + jQuery('#profile_spinner_'+ row).addClass('is-active'); | |
| 473 | + | |
| 474 | + var data = { | |
| 475 | + 'action': 'codeprofiler_rename', | |
| 476 | + 'cp_nonce': cp_nonce, | |
| 477 | + 'new_name': new_name, | |
| 478 | + 'profile': profile, | |
| 479 | + }; | |
| 480 | + | |
| 481 | + // Send the request via AJAX | |
| 482 | + jQuery.ajax( { | |
| 483 | + type: 'POST', | |
| 484 | + url: ajaxurl, | |
| 485 | + data: data, | |
| 486 | + dataType: 'json', | |
| 487 | + success: function( response ) { | |
| 488 | + jQuery('#profile_spinner_'+ row ).removeClass('is-active'); | |
| 489 | + | |
| 490 | + if (typeof response === 'undefined') { | |
| 491 | + alert( cpi18n.unknown_error ); | |
| 492 | + return; | |
| 493 | + } | |
| 494 | + | |
| 495 | + if ( response.status != 'success') { | |
| 496 | + alert( response.message ); | |
| 497 | + return; | |
| 498 | + } | |
| 499 | + | |
| 500 | + // Success: update the name in the table | |
| 501 | + jQuery('#profile_name_'+ id).html( response.newname ); | |
| 502 | + cpjs_toggle_name(row); | |
| 503 | + }, | |
| 504 | + // Display non-200 HTTP response | |
| 505 | + error: function( xhr, status, err ) { | |
| 506 | + jQuery('#profile_spinner_'+ row ).removeClass('is-active'); | |
| 507 | + if ( err != '') { | |
| 508 | + if ( xhr.status != 0 ) { | |
| 509 | + var message = cpi18n.http_error +' '+ xhr.status +' '+ err; | |
| 510 | + // Timeout | |
| 511 | + if ( xhr.status == 503 || xhr.status == 504 ) { | |
| 512 | + alert( message +'<br />'+ cpi18n.timeout_error ); | |
| 513 | + // Redirections, not found | |
| 514 | + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) { | |
| 515 | + alert( message +'<br />'+ cpi18n.notfound_error ); | |
| 516 | + // Forbidden | |
| 517 | + } else if ( xhr.status == 403 ) { | |
| 518 | + alert( message +'<br />'+ cpi18n.forbidden_error ); | |
| 519 | + // Internal error | |
| 520 | + } else if ( xhr.status == 500 ) { | |
| 521 | + alert( message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error ); | |
| 522 | + } else { | |
| 523 | + alert( cpi18n.http_error +' '+ xhr.status +' '+ err ); | |
| 524 | + } | |
| 525 | + return; | |
| 526 | + | |
| 527 | + } else { | |
| 528 | + alert( cpi18n.unknown_error +' '+ err ); | |
| 529 | + return; | |
| 530 | + } | |
| 531 | + } | |
| 532 | + return; | |
| 533 | + } | |
| 534 | + }); | |
| 535 | +} | |
| 536 | + | |
| 393 | 537 | // ===================================================================== |
| 394 | 538 | // Plugins/Theme chart. |
| 395 | 539 | |
| 396 | 540 | function cpjs_plugins_chart( caxis, clabel, cdata, ctotal_time ) { |
| @@ -397,9 +541,9 @@ | ||
| 397 | 541 | 'use strict'; |
| 398 | 542 | // Switch between vertical and horizontal bars |
| 399 | 543 | var _indexAxis = caxis; |
| 400 | 544 | document.getElementById('htov').onclick = function() { |
| 401 | - if ( _indexAxis == 'x' ) { | |
| 545 | + if ( _indexAxis == 'x') { | |
| 402 | 546 | _indexAxis = 'y'; |
| 403 | 547 | } else { |
| 404 | 548 | _indexAxis = 'x'; |
| 405 | 549 | } |
| @@ -438,9 +582,9 @@ | ||
| 438 | 582 | const total_time = ctotal_time; |
| 439 | 583 | const footer = (tooltipItems) => { |
| 440 | 584 | var sum; |
| 441 | 585 | tooltipItems.forEach(function(tooltipItem) { |
| 442 | - if ( _indexAxis == 'x' ) { | |
| 586 | + if ( _indexAxis == 'x') { | |
| 443 | 587 | sum = Math.round( ( tooltipItem.parsed.y / total_time ) * 100 ); |
| 444 | 588 | } else { |
| 445 | 589 | sum = Math.round( ( tooltipItem.parsed.x / total_time ) * 100 ); |
| 446 | 590 | } |
| @@ -511,9 +655,9 @@ | ||
| 511 | 655 | 'use strict'; |
| 512 | 656 | // Switch between vertical and horizontal bars |
| 513 | 657 | var _indexAxis = caxis; |
| 514 | 658 | document.getElementById('htov').onclick = function() { |
| 515 | - if ( _indexAxis == 'x' ) { | |
| 659 | + if ( _indexAxis == 'x') { | |
| 516 | 660 | _indexAxis = 'y'; |
| 517 | 661 | } else { |
| 518 | 662 | _indexAxis = 'x'; |
| 519 | 663 | } |
| @@ -612,9 +756,9 @@ | ||
| 612 | 756 | 'use strict'; |
| 613 | 757 | // Switch between vertical and horizontal bars |
| 614 | 758 | var _indexAxis = caxis; |
| 615 | 759 | document.getElementById('htov').onclick = function() { |
| 616 | - if ( _indexAxis == 'x' ) { | |
| 760 | + if ( _indexAxis == 'x') { | |
| 617 | 761 | _indexAxis = 'y'; |
| 618 | 762 | } else { |
| 619 | 763 | _indexAxis = 'x'; |
| 620 | 764 | } |