mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge branch '3.3.x'
This commit is contained in:
commit
6e42c34f79
2 changed files with 80 additions and 24 deletions
|
@ -269,8 +269,14 @@ function mark_one_option(id, field_name, s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset role dropdown field to Select role... if an option gets changed
|
* (Re)set the permission role dropdown.
|
||||||
*/
|
*
|
||||||
|
* Try and match the set permissions to an existing role.
|
||||||
|
* Otherwise reset the dropdown to "Select a role.."
|
||||||
|
*
|
||||||
|
* @param {string} id The fieldset identifier
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
function reset_role(id) {
|
function reset_role(id) {
|
||||||
var t = document.getElementById(id);
|
var t = document.getElementById(id);
|
||||||
|
|
||||||
|
@ -278,18 +284,37 @@ function reset_role(id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
t.options[0].selected = true;
|
// Before resetting the role dropdown, try and match any permission role
|
||||||
|
var parent = t.parentNode,
|
||||||
|
roleId = match_role_settings(id.replace('role', 'perm')),
|
||||||
|
text = no_role_assigned,
|
||||||
|
index = 0;
|
||||||
|
|
||||||
var parent = t.parentNode;
|
// If a role permissions was matched, grab that option's value and index
|
||||||
parent.querySelector('span.dropdown-trigger').innerText = no_role_assigned;
|
if (roleId) {
|
||||||
parent.querySelector('input[data-name^=role]').value = '0';
|
for (var i = 0; i < t.options.length; i++) {
|
||||||
|
if (parseInt(t.options[i].value, 10) === roleId) {
|
||||||
|
text = t.options[i].text;
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the select's value and selected index
|
||||||
|
t.value = roleId;
|
||||||
|
t.options[index].selected = true;
|
||||||
|
|
||||||
|
// Update the dropdown trigger to show the new value
|
||||||
|
parent.querySelector('span.dropdown-trigger').innerText = text;
|
||||||
|
parent.querySelector('input[data-name^=role]').value = roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load role and set options accordingly
|
* Load role and set options accordingly
|
||||||
*/
|
*/
|
||||||
function set_role_settings(role_id, target_id) {
|
function set_role_settings(role_id, target_id) {
|
||||||
settings = role_options[role_id];
|
var settings = role_options[role_id];
|
||||||
|
|
||||||
if (!settings) {
|
if (!settings) {
|
||||||
return;
|
return;
|
||||||
|
@ -302,3 +327,51 @@ function set_role_settings(role_id, target_id) {
|
||||||
mark_one_option(target_id, r, (settings[r] === 1) ? 'y' : 'n');
|
mark_one_option(target_id, r, (settings[r] === 1) ? 'y' : 'n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match the set permissions against the available roles.
|
||||||
|
*
|
||||||
|
* @param {string} id The parent fieldset identifier
|
||||||
|
* @return {number} The permission role identifier
|
||||||
|
*/
|
||||||
|
function match_role_settings(id) {
|
||||||
|
var fieldset = document.getElementById(id),
|
||||||
|
radios = fieldset.getElementsByTagName('input'),
|
||||||
|
set = {};
|
||||||
|
|
||||||
|
// Iterate over all the radio buttons
|
||||||
|
for (var i = 0; i < radios.length; i++) {
|
||||||
|
var matches = radios[i].id.match(/setting\[\d+]\[\d+]\[([a-z_]+)]/);
|
||||||
|
|
||||||
|
// Make sure the name attribute matches, the radio is checked and it is not the "No" (-1) value.
|
||||||
|
if (matches !== null && radios[i].checked && radios[i].value !== '-1') {
|
||||||
|
set[matches[1]] = parseInt(radios[i].value, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort and stringify the 'set permissions' object
|
||||||
|
set = sort_and_stringify(set);
|
||||||
|
|
||||||
|
// Iterate over the available role options and return the first match
|
||||||
|
for (var r in role_options)
|
||||||
|
{
|
||||||
|
if (sort_and_stringify(role_options[r]) === set) {
|
||||||
|
return parseInt(r, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort and stringify an Object so it can be easily compared against another object.
|
||||||
|
*
|
||||||
|
* @param {object} obj The object to sort (by key) and stringify
|
||||||
|
* @return {string} The sorted object as a string
|
||||||
|
*/
|
||||||
|
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
|
// Prepare dropdown
|
||||||
phpbb.prepareRolesDropdown();
|
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
|
})(jQuery); // Avoid conflicts with other libraries
|
||||||
|
|
Loading…
Add table
Reference in a new issue