I'm not talking about the code itself but the ability to provide function level security which should include hiding/displaying toolbar buttons, left navigation items, menu items and crm fields (attributes).
The snippet handles both hiding and showing of buttons and spacers.
Paste the code inside the onload event and use the ShowHideToolbarButton with the relevant parameters.
In order to support a multilingual environment you need to separate the button title values with a pipe ("|"). See the first example (save button) bellow.
var Spacer = {
Right : 1, // hides a right spacer if it exists
Left : 2, // hides a left spacer if it exists
Both : 3, // and so on...
None : 4
}
var Display = {
Show : "inline",
Hide : "none"
}
function OnCrmPageLoad()
{
//Configure Display when the form loads.
ConfigreToolbarDisplay();
//Configure the display each time a user manually changes the window width size.
attachEvent("onresize",ConfigreToolbarDisplay);
}
function ConfigreToolbarDisplay()
{
// Opportunity toolbar buttons
// English | German | Spanish
ShowHideToolbarButton( "Save|Speichern|Guardar" , Spacer.None , Display.Hide );
ShowHideToolbarButton( "Follow Up" , Spacer.Right , Display.Hide );
ShowHideToolbarButton( "Recalculate" , Spacer.Left , Display.Hide );
ShowHideToolbarButton( "Attach a File" , Spacer.Both , Display.Hide );
ShowHideToolbarButton( "Follow Up" , Spacer.Right , Display.Show );
}
function ShowHideToolbarButton( btnTitle , spacer , state )
{
if( isNullOrEmpty( document.all.mnuBar1 ) )
return;
if( isNullOrEmpty( btnTitle ) )
return;
if( isNullOrEmpty( spacer ) )
spacer = ToolbarSpacer.None;
if( isNullOrEmpty( state ) )
state = ButtonDisplay.Hide;
//Get all toolbar buttons
var toolBarButtons = document.all.mnuBar1.rows[0].cells[0].childNodes[0].childNodes;
//Loop through each button
for (var i = 0 ; i < toolBarButtons.length ; i++)
{
var button = toolBarButtons[i];
if( button.title.match(btnTitle) != null ||
button.innerText.match(btnTitle) != null)
{
button.style.display = state;
switch(spacer)
{
case Spacer.Right:
ShowHideSpacer( button.nextSibling );
break;
case Spacer.Left:
ShowHideSpacer( button.previousSibling );
break;
case Spacer.Both:
ShowHideSpacer( button.nextSibling );
ShowHideSpacer( button.previousSibling );
break;
}
return;
}
}
function ShowHideSpacer( btnSpacer ){
if( !isNullOrEmpty( btnSpacer ) )
btnSpacer.style.display = state;
}
function isNullOrEmpty( obj ){
return obj == null || typeof(obj) == "undefined" || obj == "";
}
}
OnCrmPageLoad();