aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/adm
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2016-11-26 09:58:47 +0100
committerMarc Alexander <admin@m-a-styles.de>2016-11-26 09:58:47 +0100
commit6c98e3b12f8b41a471e37a44eb413ce6489a70be (patch)
tree81b0b1de28db45f4f4cd0ec7796c5556508863f7 /phpBB/adm
parent16620ea3d2c51f59bbc08f0d004f48fe675ff239 (diff)
downloadforums-6c98e3b12f8b41a471e37a44eb413ce6489a70be.tar
forums-6c98e3b12f8b41a471e37a44eb413ce6489a70be.tar.gz
forums-6c98e3b12f8b41a471e37a44eb413ce6489a70be.tar.bz2
forums-6c98e3b12f8b41a471e37a44eb413ce6489a70be.tar.xz
forums-6c98e3b12f8b41a471e37a44eb413ce6489a70be.zip
[ticket/9590] Submit permissions form in chunks when using "Apply all"
This will add an AJAX call that will submit the permissions form in chunks of 5 fieldsets when clicking on "Apply all permissions". PHPBB3-9590
Diffstat (limited to 'phpBB/adm')
-rw-r--r--phpBB/adm/style/ajax.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js
index 4ad6b6afa5..42dcbe6de8 100644
--- a/phpBB/adm/style/ajax.js
+++ b/phpBB/adm/style/ajax.js
@@ -62,7 +62,77 @@ phpbb.addAjaxCallback('row_delete', function(res) {
}
});
+/**
+ * Handler for submitting permissions form in chunks
+ * This call will submit permissions forms in chunks of 5 fieldsets.
+ */
+function submitPermissions() {
+ var $form = $('form#set-permissions'),
+ fieldsetList = $form.find('fieldset[id^=perm]'),
+ formDataSets = [],
+ $submitAllButton = $form.find('input[type=submit][name^=action]')[0];
+
+ $.each(fieldsetList, function (key, value) {
+ if (key % 5 === 0) {
+ formDataSets[Math.floor(key / 5)] = $form.find('fieldset#' + value.id + ' input').serialize();
+ } else {
+ formDataSets[Math.floor(key / 5)] += '&' + $form.find('fieldset#' + value.id + ' input').serialize();
+ }
+ });
+
+ // Set proper start values for handling refresh of page
+ var permissionSubmitSize = formDataSets.length,
+ permissionRequestCount = 0,
+ permissionSubmitFailed = false;
+
+ /**
+ * Handler for submitted permissions form chunk
+ *
+ * @param {object} res Object returned by AJAX call
+ */
+ function handlePermissionReturn(res) {
+ permissionRequestCount++;
+ var $dark = $('#darkenwrapper');
+
+ if (res.S_USER_WARNING) {
+ phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
+ permissionSubmitFailed = true;
+ } else if (!permissionSubmitFailed && res.S_USER_NOTICE) {
+ if (permissionRequestCount >= permissionSubmitSize) {
+ var $alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
+ // Do not allow closing alert
+ $dark.off('click');
+ $alert.find('.alert_close').hide();
+
+ if (typeof res.REFRESH_DATA !== 'undefined') {
+ setTimeout(function () {
+ window.location = res.REFRESH_DATA.url;
+
+ // Hide the alert even if we refresh the page, in case the user
+ // presses the back button.
+ $dark.fadeOut(phpbb.alertTime, function () {
+ if (typeof $alert !== 'undefined') {
+ $alert.hide();
+ }
+ });
+ }, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds
+ }
+ }
+ }
+ }
+ $.each(formDataSets, function (key, formData) {
+ $.ajax({
+ url: $form.action,
+ type: 'POST',
+ data: formData + '&' + $submitAllButton.name + '=' + encodeURIComponent($submitAllButton.value) +
+ '&creation_time=' + $form.find('input[type=hidden][name=creation_time]')[0].value +
+ '&form_token=' + $form.find('input[type=hidden][name=form_token]')[0].value,
+ success: handlePermissionReturn,
+ error: handlePermissionReturn
+ });
+ });
+}
$('[data-ajax]').each(function() {
var $this = $(this),
@@ -83,6 +153,14 @@ $('[data-ajax]').each(function() {
*/
$(function() {
phpbb.resizeTextArea($('textarea:not(.no-auto-resize)'), {minHeight: 75});
+
+ var $setPermissionsForm = $('form#set-permissions');
+ if ($setPermissionsForm.length) {
+ $setPermissionsForm.on('submit', function (e) {
+ submitPermissions();
+ e.preventDefault();
+ });
+ }
});