Hiding the ribbon except for one control (export to excel) for a specific group
-
mardi 15 mai 2012 18:54
My users have a single-use site for a short project. There is no serious security involved, they are just trying to make the appearance simple and clean - no functionality showing that the target user won't need. They wanted the ribbon hidden for everybody except site admins, for aesthetic purposes. BUT! can we let the Legal team have Export to Excel?
I have a rough solution here but I'm thinking there might be a way to use the SPSecurityTrimmedControl instead of the Javascript - but I'm not sure if it has any way to set it based on Group instead of Permissions. The target group has no special permission distinction from any other users - they receive the URL to "Legal View" in their email, and the other users get a "Manager View" URL.
First, I used the Sharepoint:SPSecurityTrimmedControl to hide the ribbon. (before s4-ribboncont)
<Sharepoint:SPSecurityTrimmedControl runat="server"
Permissions="AddAndCustomizePages">
<style type="text/css">
div#s4-ribbonrow {
display:block;
}
</style>
</Sharepoint:SPSecurityTrimmedControl>
Then I added the link for downloading Excel. You'll have to replace your own values for site, list, and view.<a href="/YOURSITE/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={YOURLIST}&View=YOURVIEW&CacheControl=1">Download to Excel<a>
To get the ribbon's Export-To-Excel icon, I put a transparent spacer in SiteAssets. The <img> tag relies on the existing CSS sprite icon set in Sharepoint.
<span lang="en-us" id="legalview" >
<a href="/YOURSITE/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={YOURLIST}&View=YOURVIEW&CacheControl=1">
<img border="0" src="/SiteAssets/spacer.gif"
style="vertical-align:middle; background-image: url('/_layouts/1033/images/formatmap32x32.png');
background-position:0px -352px; height=32px; width=32px;"/>
<sp n style="margin-left:10px;">Download to Excel</span>
</a>
</span>
Finally, a little quick Javascript and the link will only appear on the Legal View site page:
//if this is not the legal view, hide this span
var legalView = document.getElementById('legalview');
if(document.URL.indexOf("Legal%20View.aspx") >= 0)
{
legalview.style.display='inline';
}
else
{
legalview.style.display='none';
}Taking suggestions ... if I could use a Sharepoint tag instead of the Javascript, that would be cleaner.

