Created
April 27, 2018 10:42
-
-
Save MudassarAli/88323d1b9a53552dc771fc8558efa774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
< script type = "text/javascript" src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" > < /script> < script type = "text/javascript" language = "javascript" > | |
$(document).ready(function() | |
{ | |
$(document.getElementById('Ribbon.ListItem.Manage-LargeMedium-1-2')).addClass('ms-cui-row ms-cui-disabled'); | |
ExecuteOrDelayUntilScriptLoaded(init_disableRibbomButton, "sp.ribbon.js"); | |
}); | |
function init_disableRibbomButton() | |
{ | |
setInterval(function() | |
{ | |
disableRibbomButton(); | |
}, 10); | |
} | |
//Using CSOM GetSelectedItems | |
function disableRibbomButton() | |
{ | |
var cc = new SP.ClientContext.get_current(); | |
var web = cc.get_web(); | |
var listId = SP.ListOperation.Selection.getSelectedList(); | |
var selectedItems = SP.ListOperation.Selection.getSelectedItems(); | |
if (selectedItems.length == 1) | |
{ | |
var flag = CheckCreatedBy(listId, selectedItems[0].id, _spPageContextInfo.userId); | |
if (flag) | |
$(document.getElementById('Ribbon.ListItem.Manage-LargeMedium-1-2')).removeClass('ms-cui-row ms-cui-disabled'); | |
} else | |
{ | |
$(document.getElementById('Ribbon.ListItem.Manage-LargeMedium-1-2')).addClass('ms-cui-row ms-cui-disabled'); | |
} | |
} | |
//Using REST API Apply Filter Created Item by logged in user | |
function CheckCreatedBy(ListId, ItemID, AuthorID) | |
{ | |
var result = false; | |
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyid('" + ListId + "')/items?$filter=((ID eq '" + ItemID + "') and (Author/ID eq '" + AuthorID + "'))"; | |
getListItems(url, function(data) | |
{ | |
var items = data.d.results; | |
if (items.length > 0) | |
{ | |
result = true | |
} else | |
{ | |
result = false; | |
} | |
}, function(data) | |
{ | |
result = false; | |
}); | |
return result; | |
} | |
function getListItems(siteurl, success, failure) | |
{ | |
$.ajax | |
({ | |
async: false, | |
url: siteurl, | |
method: "GET", | |
headers: | |
{ | |
"Accept": "application/json; odata=verbose" | |
}, | |
success: function(data) | |
{ | |
success(data); | |
}, | |
error: function(data) | |
{ | |
failure(data); | |
} | |
}); | |
} < /script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment