Enable or disable ribbon custom action button in SharePoint 2010
http://msdn.microsoft.com/en-us//library/ff458385.aspx
http://msdn.microsoft.com/en-us/library/office/ee537017(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/office/ee537017(v=office.14).aspx
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="AlertRibbonButton"
RegistrationId="100"
RegistrationType="List"
Location="CommandUI.Ribbon"
Sequence="5"
Title="Alert
Ribbon Button">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.List.Settings.Controls._children">
<Button
Id="AlertRibbonButtonId"
Alt="Alert
Ribbon Button"
Sequence="5"
Command="AlertRibbonButton"
Image32by32="/_layouts/images/menulistsettings.gif"
Image16by16="/_layouts/images/itdcl.gif"
LabelText="Alert
Ribbon Button"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="AlertRibbonButton"
EnabledScript="javascript:
function getItemIds()
{
var itemIds = '';
var items =
SP.ListOperation.Selection.getSelectedItems();
var item;
for(var i in items)
{
item = items[i];
if(itemIds != '')
{
itemIds = itemIds + ',';
}
itemIds = itemIds + item.id;
}
alert(itemIds);
}
var EnableDisable = function() {
this.clientContext = SP.ClientContext.get_current();
this.selectedItems =
SP.ListOperation.Selection.getSelectedItems(this.clientContext);
var ci = CountDictionary(selectedItems);
return (ci > 0);
//return (ci == 1); //if we want enable for one item only
};
EnableDisable();"
CommandAction="javascript:
alert('Hi Alert!');" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>