mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[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
This commit is contained in:
parent
16620ea3d2
commit
6c98e3b12f
2 changed files with 83 additions and 0 deletions
|
@ -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() {
|
$('[data-ajax]').each(function() {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
|
@ -83,6 +153,14 @@ $('[data-ajax]').each(function() {
|
||||||
*/
|
*/
|
||||||
$(function() {
|
$(function() {
|
||||||
phpbb.resizeTextArea($('textarea:not(.no-auto-resize)'), {minHeight: 75});
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -755,6 +755,7 @@ class acp_permissions
|
||||||
|
|
||||||
$this->log_action($mode, 'add', $permission_type, $ug_type, $ug_id, $forum_id);
|
$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));
|
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')
|
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)));
|
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&forum_id[]=' . implode('&forum_id[]=', $forum_ids)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
meta_refresh(5, $this->u_action);
|
||||||
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($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')
|
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)));
|
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&forum_id[]=' . implode('&forum_id[]=', $forum_id)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
meta_refresh(5, $this->u_action);
|
||||||
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
|
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue