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

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