mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-14 12:52:08 +02:00
[ticket/15766] Check for role on changing permission settings
PHPBB3-15766
This commit is contained in:
parent
880deabac1
commit
11cf09b41a
@ -278,11 +278,26 @@ function reset_role(id) {
|
||||
return;
|
||||
}
|
||||
|
||||
t.options[0].selected = true;
|
||||
var parent = t.parentNode,
|
||||
roleId = match_role_settings(id.replace('role', 'perm')),
|
||||
text = no_role_assigned,
|
||||
index = 0;
|
||||
|
||||
var parent = t.parentNode;
|
||||
parent.querySelector('span.dropdown-trigger').innerText = no_role_assigned;
|
||||
parent.querySelector('input[data-name^=role]').value = '0';
|
||||
if (roleId) {
|
||||
for (var i = 0; i < t.options.length; i++) {
|
||||
if (t.options[i].value == roleId) {
|
||||
text = t.options[i].text;
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.value = roleId;
|
||||
t.options[index].selected = true;
|
||||
|
||||
parent.querySelector('span.dropdown-trigger').innerText = text;
|
||||
parent.querySelector('input[data-name^=role]').value = roleId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,3 +317,36 @@ function set_role_settings(role_id, target_id) {
|
||||
mark_one_option(target_id, r, (settings[r] === 1) ? 'y' : 'n');
|
||||
}
|
||||
}
|
||||
|
||||
function match_role_settings(id)
|
||||
{
|
||||
var fs = document.getElementById(id),
|
||||
cbs = fs.getElementsByTagName('input'),
|
||||
xyz = {};
|
||||
|
||||
for (var i = 0; i < cbs.length; i++) {
|
||||
var matches = cbs[i].id.match(/setting\[\d+]\[\d+]\[([a-z_]+)]/);
|
||||
|
||||
if (matches !== null && cbs[i].checked && cbs[i].value !== '-1') {
|
||||
xyz[matches[1]] = parseInt(cbs[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
xyz = sort_and_stringify(xyz);
|
||||
|
||||
for (var r in role_options)
|
||||
{
|
||||
if (sort_and_stringify(role_options[r]) === xyz) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function sort_and_stringify(obj) {
|
||||
return JSON.stringify(Object.keys(obj).sort().reduce(function (result, key) {
|
||||
result[key] = obj[key];
|
||||
return result;
|
||||
}, {}));
|
||||
}
|
||||
|
@ -218,23 +218,6 @@ $(function() {
|
||||
|
||||
// Prepare dropdown
|
||||
phpbb.prepareRolesDropdown();
|
||||
|
||||
// Reset role drop-down on modifying permissions in advanced tab
|
||||
$('div.permissions-switch > a').on('click', function () {
|
||||
$.each($('input[type=radio][name^="setting["]'), function () {
|
||||
var $this = $(this);
|
||||
$this.on('click', function () {
|
||||
var $rolesOptions = $this.closest('fieldset.permissions').find('.roles-options'),
|
||||
rolesSelect = $rolesOptions.find('select > option')[0];
|
||||
|
||||
// Set selected setting
|
||||
$rolesOptions.children('span')
|
||||
.text(rolesSelect.text);
|
||||
$rolesOptions.children('input[type=hidden]')
|
||||
.val(rolesSelect.value);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery); // Avoid conflicts with other libraries
|
||||
|
Loading…
x
Reference in New Issue
Block a user