Blame Identity/Webenv/App/phpBB/3.0.4/adm/style/permissions.js

f2e824
/**
f2e824
* Hide and show all checkboxes
f2e824
* status = true (show boxes), false (hide boxes)
f2e824
*/
f2e824
function display_checkboxes(status) 
f2e824
{
f2e824
	var form = document.getElementById('set-permissions');
f2e824
	var cb = document.getElementsByTagName('input');
f2e824
	var display;
f2e824
f2e824
	//show
f2e824
	if (status)
f2e824
	{
f2e824
		display = 'inline';
f2e824
	}
f2e824
	//hide
f2e824
	else
f2e824
	{
f2e824
		display = 'none';
f2e824
	}
f2e824
	
f2e824
	for (var i = 0; i < cb.length; i++ )
f2e824
	{
f2e824
		if (cb[i].className == 'permissions-checkbox')
f2e824
		{
f2e824
			cb[i].style.display = display;
f2e824
		}
f2e824
		
f2e824
	}	
f2e824
	
f2e824
}
f2e824
f2e824
f2e824
/**
f2e824
* Change opacity of element
f2e824
* e = element
f2e824
* value = 0 (hidden) till 10 (fully visible)
f2e824
*/
f2e824
function set_opacity(e, value) {
f2e824
	e.style.opacity = value/10;
f2e824
	
f2e824
	//IE opacity currently turned off, because of its astronomical stupidity
f2e824
	//e.style.filter = 'alpha(opacity=' + value*10 + ')';
f2e824
}
f2e824
f2e824
/**
f2e824
* Reset the opacity and checkboxes
f2e824
* block_id = id of the element that needs to be toggled
f2e824
*/
f2e824
function toggle_opacity(block_id) {
f2e824
	var cb = document.getElementById('checkbox' + block_id);
f2e824
	var fs = document.getElementById('perm' + block_id);
f2e824
	
f2e824
	if (cb.checked) 
f2e824
	{
f2e824
		set_opacity(fs, 5);
f2e824
	} 
f2e824
	else 
f2e824
	{
f2e824
		set_opacity(fs, 10);
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Reset the opacity and checkboxes
f2e824
* value = 0 (checked) and 1 (unchecked)
f2e824
* except_id = id of the element not to hide
f2e824
*/
f2e824
function reset_opacity(status, except_id) {
f2e824
	var perm = document.getElementById('set-permissions');
f2e824
	var fs = perm.getElementsByTagName('fieldset');
f2e824
	var opacity = 5;
f2e824
f2e824
	if (status)
f2e824
	{
f2e824
		opacity = 10;	
f2e824
	}
f2e824
	
f2e824
	for (var i = 0; i < fs.length; i++ )
f2e824
	{
f2e824
		if (fs[i].className != 'quick')
f2e824
		{
f2e824
			set_opacity(fs[i], opacity);
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (typeof(except_id) != 'undefined')
f2e824
	{
f2e824
		set_opacity(document.getElementById('perm' + except_id), 10);
f2e824
	}
f2e824
f2e824
	//reset checkboxes too
f2e824
	marklist('set-permissions', 'inherit', !status);
f2e824
}
f2e824
f2e824
f2e824
/**
f2e824
* Check whether we have a full radiobutton row of true
f2e824
* index = offset for the row of inputs (0 == first row, 1 == second, 2 == third),
f2e824
* rb = array of radiobuttons
f2e824
*/
f2e824
function get_radio_status(index, rb) 
f2e824
{
f2e824
	for (var i = index; i < rb.length; i = i + 3 )
f2e824
	{
f2e824
		if (rb[i].checked != true)
f2e824
		{
f2e824
			if (i > index)
f2e824
			{
f2e824
				//at least one is true, but not all (custom)
f2e824
				return 2;
f2e824
			}
f2e824
			//first one is not true
f2e824
			return 0;
f2e824
		}
f2e824
	}
f2e824
f2e824
	// all radiobuttons true
f2e824
	return 1;
f2e824
}
f2e824
f2e824
/**
f2e824
* Set tab colours
f2e824
* id = panel the tab needs to be set for, 
f2e824
* init = initialising on open, 
f2e824
* quick = If no calculation needed, this contains the colour
f2e824
*/
f2e824
function set_colours(id, init, quick)
f2e824
{
f2e824
	var table = document.getElementById('table' + id);
f2e824
	var tab = document.getElementById('tab' + id);
f2e824
f2e824
	if (typeof(quick) != 'undefined') 
f2e824
	{
f2e824
		tab.className = 'permissions-preset-' + quick + ' activetab';
f2e824
		return;
f2e824
	}
f2e824
f2e824
	var rb = table.getElementsByTagName('input');
f2e824
	var colour = 'custom';
f2e824
f2e824
	var status = get_radio_status(0, rb);
f2e824
f2e824
	if (status == 1)
f2e824
	{
f2e824
		colour = 'yes';
f2e824
	}
f2e824
	else if (status == 0) 
f2e824
	{
f2e824
		// We move on to No
f2e824
		status = get_radio_status(1, rb);
f2e824
f2e824
		if (status == 1)
f2e824
		{
f2e824
			colour = 'no';
f2e824
		}
f2e824
		else if (status == 0) 
f2e824
		{
f2e824
			// We move on to Never
f2e824
			status = get_radio_status(2, rb);
f2e824
f2e824
			if (status == 1)
f2e824
			{
f2e824
				colour = 'never';
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (init)
f2e824
	{
f2e824
		tab.className = 'permissions-preset-' + colour;
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		tab.className = 'permissions-preset-' + colour + ' activetab';
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Initialise advanced tab colours on first load
f2e824
* block_id = block that is opened
f2e824
*/
f2e824
function init_colours(block_id)
f2e824
{	
f2e824
	var block = document.getElementById('advanced' + block_id);
f2e824
	var panels = block.getElementsByTagName('div');
f2e824
	var tab = document.getElementById('tab' + id);
f2e824
f2e824
	for (var i = 0; i < panels.length; i++)
f2e824
	{
f2e824
		if(panels[i].className == 'permissions-panel')
f2e824
		{
f2e824
			set_colours(panels[i].id.replace(/options/, ''), true);
f2e824
		}
f2e824
	}
f2e824
f2e824
	tab.className = tab.className + ' activetab';
f2e824
}
f2e824
f2e824
/**
f2e824
* Show/hide option panels
f2e824
* value = suffix for ID to show
f2e824
* adv = we are opening advanced permissions
f2e824
* view = called from view permissions
f2e824
*/
f2e824
function swap_options(pmask, fmask, cat, adv, view)
f2e824
{
f2e824
	id = pmask + fmask + cat;
f2e824
	active_option = active_pmask + active_fmask + active_cat;
f2e824
f2e824
	var	old_tab = document.getElementById('tab' + active_option);	
f2e824
	var new_tab = document.getElementById('tab' + id);
f2e824
	var adv_block = document.getElementById('advanced' + pmask + fmask);
f2e824
f2e824
	if (adv_block.style.display == 'block' && adv == true)
f2e824
	{
f2e824
		dE('advanced' + pmask + fmask, -1);
f2e824
		reset_opacity(1);
f2e824
		display_checkboxes(false);
f2e824
		return;
f2e824
	}
f2e824
f2e824
	// no need to set anything if we are clicking on the same tab again
f2e824
	if (new_tab == old_tab && !adv)
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	// init colours
f2e824
	if (adv && (pmask + fmask) != (active_pmask + active_fmask))
f2e824
	{
f2e824
		init_colours(pmask + fmask);
f2e824
		display_checkboxes(true);
f2e824
		reset_opacity(1);
f2e824
	} 
f2e824
	else if (adv) 
f2e824
	{
f2e824
		//Checkbox might have been clicked, but we need full visibility
f2e824
		display_checkboxes(true);
f2e824
		reset_opacity(1);
f2e824
	}
f2e824
f2e824
	// set active tab
f2e824
	old_tab.className = old_tab.className.replace(/\ activetab/g, '');
f2e824
	new_tab.className = new_tab.className + ' activetab';
f2e824
f2e824
	if (id == active_option && adv != true)
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	dE('options' + active_option, -1);
f2e824
	
f2e824
	//hiding and showing the checkbox
f2e824
	if (document.getElementById('checkbox' + active_pmask + active_fmask))
f2e824
	{
f2e824
		dE('checkbox' + pmask + fmask, -1);	
f2e824
		
f2e824
		if ((pmask + fmask) != (active_pmask + active_fmask))
f2e824
		{
f2e824
			document.getElementById('checkbox' + active_pmask + active_fmask).style.display = 'inline';
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (!view)
f2e824
	{
f2e824
		dE('advanced' + active_pmask + active_fmask, -1);
f2e824
	}
f2e824
f2e824
	if (!view)
f2e824
	{
f2e824
		dE('advanced' + pmask + fmask, 1);
f2e824
	}
f2e824
	dE('options' + id, 1);
f2e824
f2e824
	active_pmask = pmask;
f2e824
	active_fmask = fmask;
f2e824
	active_cat = cat;
f2e824
}
f2e824
f2e824
/**
f2e824
* Mark all radio buttons in one panel
f2e824
* id = table ID container, s = status ['y'/'u'/'n']
f2e824
*/
f2e824
function mark_options(id, s)
f2e824
{
f2e824
	var t = document.getElementById(id);
f2e824
f2e824
	if (!t)
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	var rb = t.getElementsByTagName('input');
f2e824
f2e824
	for (var r = 0; r < rb.length; r++)
f2e824
	{
f2e824
		if (rb[r].id.substr(rb[r].id.length-1) == s)
f2e824
		{
f2e824
			rb[r].checked = true;
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
function mark_one_option(id, field_name, s)
f2e824
{
f2e824
	var t = document.getElementById(id);
f2e824
f2e824
	if (!t)
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	var rb = t.getElementsByTagName('input');
f2e824
f2e824
	for (var r = 0; r < rb.length; r++)
f2e824
	{
f2e824
		if (rb[r].id.substr(rb[r].id.length-field_name.length-3, field_name.length) == field_name && rb[r].id.substr(rb[r].id.length-1) == s)
f2e824
		{
f2e824
			rb[r].checked = true;
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Reset role dropdown field to Select role... if an option gets changed
f2e824
*/
f2e824
function reset_role(id)
f2e824
{
f2e824
	var t = document.getElementById(id);
f2e824
f2e824
	if (!t)
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	t.options[0].selected = true;
f2e824
}
f2e824
f2e824
/**
f2e824
* Load role and set options accordingly
f2e824
*/
f2e824
function set_role_settings(role_id, target_id)
f2e824
{
f2e824
	settings = role_options[role_id];
f2e824
f2e824
	if (!settings)
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	// Mark all options to no (unset) first...
f2e824
	mark_options(target_id, 'u');
f2e824
f2e824
	for (var r in settings)
f2e824
	{
f2e824
		mark_one_option(target_id, r, (settings[r] == 1) ? 'y' : 'n');
f2e824
	}
f2e824
}