<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="/_layouts/15/init.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript">//<![CDATA[
var g_pageLoadAnimationParams = { elementSlideIn : "sideNavBox", elementSlideInPhase2 : "contentBox" };
$(document).ready(function(){
//disableControls();
checkUser();
});
var adminUsers;
var vCurrUserName;
var groupCollection;
var _group;
function checkUser() {
alert('username');
var currentContext = new SP.ClientContext.get_current();
//get current user
vCurrUserName = currentContext.get_web().get_currentUser();
alert(vCurrUserName);
currentContext.load(vCurrUserName);
// get Admin group
groupCollection = currentContext.get_web().get_siteGroups();
currentContext.load(groupCollection);
//var _group = groupCollection.getById(10); // ID of the Group
currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess),
Function.createDelegate(this, this.checkUserFailure));
}
var vIsAdmin = false;
function checkUserSuccess() {
var currentContext = new SP.ClientContext.get_current();
var grpEnum = groupCollection.getEnumerator();
while(grpEnum.moveNext()){
var grpItem = grpEnum.get_current();
currentContext.load(grpItem);
alert('Mohan');
// here you can add one more if condition to check for "Approvers" group.
alert(grpItem.get_title());
if(grpItem.get_title() == "Member"){
_group = grpItem;
break;
}
}
adminUsers = _group.get_users();
currentContext.load(adminUsers);
currentContext.executeQueryAsync(Function.createDelegate(this, this.findUserInGroup),
Function.createDelegate(this, this.checkUserFailure));
}
function findUserInGroup(){
var listEnumerator = adminUsers.getEnumerator();
while (listEnumerator.moveNext()) {
var item = listEnumerator.get_current();
//check current user login name and user login name from admin group
if (vCurrUserName.get_loginName() == item.get_loginName()) {
vIsAdmin = true;
break;
}
}
if (vIsAdmin) {
alert('Admin');
// do something here
}
else
{
alert('not Admin')
// do something here
}
}
//]]>
</script>
<script type="text/javascript" src="/_layouts/15/init.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript">//<![CDATA[
var g_pageLoadAnimationParams = { elementSlideIn : "sideNavBox", elementSlideInPhase2 : "contentBox" };
$(document).ready(function(){
//disableControls();
checkUser();
});
var adminUsers;
var vCurrUserName;
var groupCollection;
var _group;
function checkUser() {
alert('username');
var currentContext = new SP.ClientContext.get_current();
//get current user
vCurrUserName = currentContext.get_web().get_currentUser();
alert(vCurrUserName);
currentContext.load(vCurrUserName);
// get Admin group
groupCollection = currentContext.get_web().get_siteGroups();
currentContext.load(groupCollection);
//var _group = groupCollection.getById(10); // ID of the Group
currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess),
Function.createDelegate(this, this.checkUserFailure));
}
var vIsAdmin = false;
function checkUserSuccess() {
var currentContext = new SP.ClientContext.get_current();
var grpEnum = groupCollection.getEnumerator();
while(grpEnum.moveNext()){
var grpItem = grpEnum.get_current();
currentContext.load(grpItem);
alert('Mohan');
// here you can add one more if condition to check for "Approvers" group.
alert(grpItem.get_title());
if(grpItem.get_title() == "Member"){
_group = grpItem;
break;
}
}
adminUsers = _group.get_users();
currentContext.load(adminUsers);
currentContext.executeQueryAsync(Function.createDelegate(this, this.findUserInGroup),
Function.createDelegate(this, this.checkUserFailure));
}
function findUserInGroup(){
var listEnumerator = adminUsers.getEnumerator();
while (listEnumerator.moveNext()) {
var item = listEnumerator.get_current();
//check current user login name and user login name from admin group
if (vCurrUserName.get_loginName() == item.get_loginName()) {
vIsAdmin = true;
break;
}
}
if (vIsAdmin) {
alert('Admin');
// do something here
}
else
{
alert('not Admin')
// do something here
}
}
//]]>
</script>
No comments:
Post a Comment