diff options
author | Tristan Darricau <github@nicofuma.fr> | 2016-12-03 14:42:27 +0100 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2016-12-03 14:42:27 +0100 |
commit | 3acee9a3eea8e3fdcef59876da273358a46903e8 (patch) | |
tree | 3ed42316c51a61a1f40fb4a2c2f5952efc64c11d /phpBB/adm/style/ajax.js | |
parent | 487df8befc9477c742b2794593c2ddb290c1c678 (diff) | |
parent | 5895f56de05b637765a6583b8c51c1db3daabe91 (diff) | |
download | forums-3acee9a3eea8e3fdcef59876da273358a46903e8.tar forums-3acee9a3eea8e3fdcef59876da273358a46903e8.tar.gz forums-3acee9a3eea8e3fdcef59876da273358a46903e8.tar.bz2 forums-3acee9a3eea8e3fdcef59876da273358a46903e8.tar.xz forums-3acee9a3eea8e3fdcef59876da273358a46903e8.zip |
Merge pull request #4189 from marc1706/ticket/14492
[ticket/14492] Improve send stats page and include VigLink
* marc1706/ticket/14492: (47 commits)
[ticket/14492] Add user service to installer & only instantiate if needed
[ticket/14492] Fix redirection to help phpBB page
[ticket/14492] Encode URI components in systemdata for stats
[ticket/14492] Always update the time the stats were sent
[ticket/14492] Update versions in files
[ticket/14492] Add missing event variable
[ticket/14492] Don't explicitly pass data providers by refs
[ticket/14492] Update phpBB version and fix miscellaneous code issues
[ticket/14492] Install all extensions if 'all' is specified for extensions
[ticket/14492] Checkout master if viglink tag does not exist for latest version
[ticket/14492] Add language variables for updating extensions
[ticket/14492] Prevent timeouts in install & update extensions tasks
[ticket/14492] Use same list for checking if extension should be updated
[ticket/14492] Add missing config to schema_data.sql
[ticket/14492] Unify version check for installing default extensions
[ticket/14492] Use extension manager instead of finder and add try/catch
[ticket/14492] Checkout viglink for each version depending on tags
[ticket/14492] Remove unused use statement
[ticket/14492] Redirect to help phpBB page after installation
[ticket/14492] Properly retrieve version updating from
...
Diffstat (limited to 'phpBB/adm/style/ajax.js')
-rw-r--r-- | phpBB/adm/style/ajax.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 3c1c57505b..d5154b2a61 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -4,6 +4,101 @@ 'use strict'; + +phpbb.prepareSendStats = function () { + var $form = $('#acp_help_phpbb'); + var $dark = $('#darkenwrapper'); + var $loadingIndicator; + + $form.on('submit', function (event) { + var $this = $(this), + currentTime = Math.floor(new Date().getTime() / 1000), + statsTime = parseInt($this.find('input[name=help_send_statistics_time]').val(), 10); + + event.preventDefault(); + $this.unbind('submit'); + + // Skip ajax request if form is submitted too early or send stats + // checkbox is not checked + if (!$this.find('input[name=help_send_statistics]').is(':checked') || + statsTime > currentTime) { + $form.find('input[type=submit]').click(); + setTimeout(function () { + $form.find('input[type=submit]').click(); + }, 300); + return; + } + + /** + * Handler for AJAX errors + */ + function errorHandler(jqXHR, textStatus, errorThrown) { + if (typeof console !== 'undefined' && console.log) { + console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown); + } + phpbb.clearLoadingTimeout(); + var errorText = ''; + + if (typeof errorThrown === 'string' && errorThrown.length > 0) { + errorText = errorThrown; + } else { + errorText = $dark.attr('data-ajax-error-text-' + textStatus); + if (typeof errorText !== 'string' || !errorText.length) { + errorText = $dark.attr('data-ajax-error-text'); + } + } + phpbb.alert($dark.attr('data-ajax-error-title'), errorText); + } + + /** + * This is a private function used to handle the callbacks, refreshes + * and alert. It calls the callback, refreshes the page if necessary, and + * displays an alert to the user and removes it after an amount of time. + * + * It cannot be called from outside this function, and is purely here to + * avoid repetition of code. + * + * @param {object} res The object sent back by the server. + */ + function returnHandler(res) { + phpbb.clearLoadingTimeout(); + + // If a confirmation is not required, display an alert and call the + // callbacks. + $dark.fadeOut(phpbb.alertTime); + + if ($loadingIndicator) { + $loadingIndicator.fadeOut(phpbb.alertTime); + } + + var $sendStatisticsSuccess = $('<input />', { + type: 'hidden', + name: 'send_statistics_response', + value: res + }); + $sendStatisticsSuccess.appendTo('p.submit-buttons'); + + // Finish actual form submission + $form.find('input[type=submit]').click(); + } + + $loadingIndicator = phpbb.loadingIndicator(); + + $.ajax({ + url: $this.attr('data-ajax-action').replace('&', '&'), + type: 'POST', + data: 'systemdata=' + encodeURIComponent($this.find('input[name=systemdata]').val()), + success: returnHandler, + error: errorHandler, + cache: false + }).always(function() { + if ($loadingIndicator && $loadingIndicator.is(':visible')) { + $loadingIndicator.fadeOut(phpbb.alertTime); + } + }); + }); +}; + /** * The following callbacks are for reording items. row_down * is triggered when an item is moved down, and row_up is triggered when @@ -225,6 +320,10 @@ $(function() { $(this).attr('data-clicked', true); }); } + + if ($('#acp_help_phpbb')) { + phpbb.prepareSendStats(); + } }); |