1. How to hide div based on user groups (nested logic)
2. JavaScript Client Code to get current user's groups for SharePoint Server 2013
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', IsCurrentUserWithContributePerms);
function IsCurrentUserWithContributePerms() {
IsCurrentUserMemberOfGroup("Group1", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none'; //
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
IsCurrentUserMemberOfGroup("Group2", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none';
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
IsCurrentUserMemberOfGroup("Group3", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none';
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
IsCurrentUserMemberOfGroup("Group4", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none';
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
}
});
}
});
}
});
}
});
}
2. JavaScript Client Code to get current user's groups for SharePoint Server 2013
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', IsCurrentUserWithContributePerms);
function IsCurrentUserWithContributePerms() {
IsCurrentUserMemberOfGroup("Group1", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none'; //
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
IsCurrentUserMemberOfGroup("Group2", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none';
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
IsCurrentUserMemberOfGroup("Group3", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none';
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
IsCurrentUserMemberOfGroup("Group4", function (isCurrentUserInGroup) {
if (isCurrentUserInGroup) {
document.getElementById("Ribbon1").style.display = 'none';
document.getElementById("Ribbon2").style.display = 'none';
}
else {
document.getElementById("Ribbon1").style.display = 'block';
document.getElementById("Ribbon2").style.display = 'block';
}
});
}
});
}
});
}
});
}
No comments:
Post a Comment