diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 6290666..f568767 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -41,14 +41,14 @@ define('ERROR_REPORTING_DISPLAY_SOME', 1); define('ERROR_REPORTING_DISPLAY_ALL', 2); /** - * Ajax error reporting level: display errors is alert window. + * JS error reporting level: display errors in console. */ -define('AJAX_ERROR_REPORTING_ALERT', 0); +define('JS_ERROR_REPORTING_CONSOLE', 0); /** - * Ajax error reporting level: display errors in console. + * JS error reporting level: display errors in an alert window. */ -define('AJAX_ERROR_REPORTING_CONSOLE', 1); +define('JS_ERROR_REPORTING_ALERT', 1); /** * Indicates that the item should never be removed unless explicitly selected. diff --git a/misc/ajax.js b/misc/ajax.js index fbe3383..c7b3dc6 100644 --- a/misc/ajax.js +++ b/misc/ajax.js @@ -476,14 +476,7 @@ Drupal.ajax.prototype.getEffect = function (response) { * Handler for the form redirection error. */ Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) { - if (Drupal.settings.ajaxErrorDisplay === '1') { - if (typeof(window.console) !== 'undefined') { - window.console.log(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); - } - } - else { - alert(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); - } + Drupal.alert(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); // Remove the progress element. if (this.progress.element) { diff --git a/misc/autocomplete.js b/misc/autocomplete.js index eb27df3..2b68cb6 100644 --- a/misc/autocomplete.js +++ b/misc/autocomplete.js @@ -310,14 +310,7 @@ Drupal.ACDB.prototype.search = function (searchString) { } }, error: function (xmlhttp) { - if (Drupal.settings.ajaxErrorDisplay === '1') { - if (typeof(window.console) !== 'undefined') { - window.console.log(Drupal.ajaxError(xmlhttp, db.uri)); - } - } - else { - alert(Drupal.ajaxError(xmlhttp, db.uri)); - } + Drupal.alert(Drupal.ajaxError(xmlhttp, db.uri)); } }); }, this.delay); diff --git a/misc/drupal.js b/misc/drupal.js index 427c4a1..8f667f7 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -414,6 +414,20 @@ Drupal.getSelection = function (element) { }; /** + * Shows an error on an alert window or the console + */ + Drupal.alert = function (message) { + if (Drupal.settings.errorDisplay) { + alert(message); + } + else { + if (typeof(window.console) !== 'undefined') { + window.console.log(message); + } + } + } + +/** * Build an error message from an Ajax response. */ Drupal.ajaxError = function (xmlhttp, uri, customMessage) { diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index cfd87c7..e90b9f0 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1676,14 +1676,15 @@ function system_logging_settings() { '#description' => t('It is recommended that sites running on production environments do not display any errors.'), ); - $form['ajax_error_level'] = array( + $form['js_error_level'] = array( '#type' => 'radios', - '#title' => t('Ajax errors to display'), - '#default_value' => variable_get('ajax_error_level', AJAX_ERROR_REPORTING_ALERT), + '#title' => t('Javascript alert behaviour'), + '#default_value' => variable_get('js_error_level', JS_ERROR_REPORTING_ALERT), '#options' => array( - AJAX_ERROR_REPORTING_ALERT => t('Show in alert window'), - AJAX_ERROR_REPORTING_CONSOLE => t('Show in console'), + JS_ERROR_REPORTING_ALERT => t('Show in alert window'), + JS_ERROR_REPORTING_CONSOLE => t('Show in console'), ), + '#description' => t('This applies to certain javascript errors (i.e. AJAX), allowing you to disable the alert and have them being logged to the browser console when available.'), ); return system_settings_form($form); diff --git a/modules/system/system.module b/modules/system/system.module index 744253d..343a0cf 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1101,7 +1101,7 @@ function system_library() { 'misc/ajax.js' => array('group' => JS_LIBRARY, 'weight' => 2), array( 'type' => 'setting', - 'data' => array('ajaxErrorDisplay' => variable_get('ajax_error_level', AJAX_ERROR_REPORTING_ALERT)), + 'data' => array('errorDisplay' => (int) variable_get('js_error_level', JS_ERROR_REPORTING_ALERT)), ), ), 'dependencies' => array( @@ -1178,7 +1178,7 @@ function system_library() { 'misc/autocomplete.js' => array('group' => JS_DEFAULT), array( 'type' => 'setting', - 'data' => array('ajaxErrorDisplay' => variable_get('ajax_error_level', AJAX_ERROR_REPORTING_ALERT)), + 'data' => array('errorDisplay' => (int) variable_get('js_error_level', JS_ERROR_REPORTING_ALERT)), ), ), );