From 48d6abcf0a28d33363c8da596570bfe8637d246c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 26 Nov 2016 23:10:47 +0100 Subject: [ticket/9590] Update permissions with correct permission role PHPBB3-9590 --- phpBB/adm/style/ajax.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'phpBB/adm/style/ajax.js') diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 7ddd2d3742..3c1c57505b 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -70,6 +70,7 @@ function submitPermissions() { var $form = $('form#set-permissions'), fieldsetList = $form.find('fieldset[id^=perm]'), formDataSets = [], + dataSetIndex = 0, $submitAllButton = $form.find('input[type=submit][name^=action]')[0], $submitButton = $form.find('input[type=submit][data-clicked=true]')[0]; @@ -84,10 +85,21 @@ function submitPermissions() { } $.each(fieldsetList, function (key, value) { + dataSetIndex = Math.floor(key / 5); + var $fieldset = $('fieldset#' + value.id); if (key % 5 === 0) { - formDataSets[Math.floor(key / 5)] = $form.find('fieldset#' + value.id).serialize(); + formDataSets[dataSetIndex] = $fieldset.find('select:visible, input:not([data-name])').serialize(); } else { - formDataSets[Math.floor(key / 5)] += '&' + $form.find('fieldset#' + value.id).serialize(); + formDataSets[dataSetIndex] += '&' + $fieldset.find('select:visible, input:not([data-name])').serialize(); + } + + // Find proper role value + var roleInput = $fieldset.find('input[name^=role][data-name]'); + if (roleInput.val()) { + formDataSets[dataSetIndex] += '&' + roleInput.attr('name') + '=' + roleInput.val(); + } else { + formDataSets[dataSetIndex] += '&' + roleInput.attr('name') + '=' + + $fieldset.find('select[name="' + roleInput.attr('name') + '"]').val(); } }); -- cgit v1.2.1 From 89fef2ce13a183c7b963032274f455a09a05f325 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 21 Feb 2016 22:14:58 +0100 Subject: [ticket/14492] Send statistics via ajax request Flooding ajax requests will try to be prevented and sending stats without JS will also properly work. PHPBB3-14492 --- phpBB/adm/style/ajax.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'phpBB/adm/style/ajax.js') diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 3c1c57505b..1d4e00dfa4 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 () { + 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 = $('', { + 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=' + $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(); + } }); -- cgit v1.2.1 From afe16a62724451cb5c7eca7864a3c110404f4e2a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 3 Sep 2016 10:47:20 +0200 Subject: [ticket/14492] Add missing event variable PHPBB3-14492 --- phpBB/adm/style/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/adm/style/ajax.js') diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 1d4e00dfa4..28f761bc0b 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -10,7 +10,7 @@ phpbb.prepareSendStats = function () { var $dark = $('#darkenwrapper'); var $loadingIndicator; - $form.on('submit', function () { + $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); -- cgit v1.2.1 From 9b4190e1365aed639068d341cb4296e895ad4ba1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 9 Nov 2016 22:02:46 +0100 Subject: [ticket/14492] Encode URI components in systemdata for stats The stats data needs to be URI encoded to prevent issues when submitting the data to the receive_stats script on www.phpbb.com. PHPBB3-14492 --- phpBB/adm/style/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/adm/style/ajax.js') diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 28f761bc0b..d5154b2a61 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -87,7 +87,7 @@ phpbb.prepareSendStats = function () { $.ajax({ url: $this.attr('data-ajax-action').replace('&', '&'), type: 'POST', - data: 'systemdata=' + $this.find('input[name=systemdata]').val(), + data: 'systemdata=' + encodeURIComponent($this.find('input[name=systemdata]').val()), success: returnHandler, error: errorHandler, cache: false -- cgit v1.2.1