diff options
author | Marc Alexander <admin@m-a-styles.de> | 2016-11-26 09:58:47 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2016-11-26 09:58:47 +0100 |
commit | 6c98e3b12f8b41a471e37a44eb413ce6489a70be (patch) | |
tree | 81b0b1de28db45f4f4cd0ec7796c5556508863f7 /phpBB | |
parent | 16620ea3d2c51f59bbc08f0d004f48fe675ff239 (diff) | |
download | forums-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')
-rw-r--r-- | phpBB/adm/style/ajax.js | 78 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_permissions.php | 5 |
2 files changed, 83 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(); + }); + } }); diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php index 660afb4e93..62e75a2db7 100644 --- a/phpBB/includes/acp/acp_permissions.php +++ b/phpBB/includes/acp/acp_permissions.php @@ -755,6 +755,7 @@ class acp_permissions $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_id, $forum_id); + meta_refresh(5, $this->u_action); trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action)); } @@ -825,10 +826,12 @@ class acp_permissions if ($mode == 'setting_forum_local' || $mode == 'setting_mod_local') { + meta_refresh(5, $this->u_action . '&forum_id[]=' . implode('&forum_id[]=', $forum_ids)); trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&forum_id[]=' . implode('&forum_id[]=', $forum_ids))); } else { + meta_refresh(5, $this->u_action); trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action)); } } @@ -899,10 +902,12 @@ class acp_permissions if ($mode == 'setting_forum_local' || $mode == 'setting_mod_local') { + meta_refresh(5, $this->u_action . '&forum_id[]=' . implode('&forum_id[]=', $forum_id)); trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&forum_id[]=' . implode('&forum_id[]=', $forum_id))); } else { + meta_refresh(5, $this->u_action); trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action)); } } |