遇到了很多次对网站功能区个性化定义的任务,包括标签按钮之类的修改,每次都要重新翻书,这次总结一下,留作备用。
添加内容
下面的XML我认为主要的内容是四部分,一个是CommandUIDefinition下的tab,一个是scaling,一个是button,一个是CommandUIHandler。
如果是完整的重新添加按钮,主要是分为以下几个主要内容:
- 定义location
- 添加tab
- 添加group,指定grouptemplate
- 添加button,指定commond
- 添加grouptemplate,id和在group中的引用保持一致
- 添加commond,和button中指定的保持一致。
注意在:
Section Alignment="Top" Type="OneRow"
Type="OneRow" 即一个按钮
Type="TwoRow" 即布局两个按钮
并且尽量使所有的id都不重复。
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="listApproval"
Location="CommandUI.Ribbon.DisplayForm"
RegistrationId="100"
RegistrationType="List"
Rights="EditListItems">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Tabs._children" >
<Tab
Id="Ribbon.ApprovalRibbon"
Title="审批流程"
Description="审批流程"
Sequence="1001">
<Scaling //缩放比例
Id="Ribbon.ApprovalRibbon.Scaling">
<MaxSize
Id="Ribbon.ApprovalRibbon.MaxSize"
GroupId="Ribbon.ApprovalRibbon.ApprovalGroup"
Size="OneLargeTwoMedium"/>
<Scale
Id="Ribbon.ApprovalRibbon.Scaling.CustomTabScaling"
GroupId="Ribbon.ApprovalRibbon.ApprovalGroup"
Size="OneLargeTwoMedium" />
</Scaling>
<Groups Id="Ribbon.ApprovalRibbon.Groups">
<Group
Id="Ribbon.ApprovalRibbon.ApprovalGroup"
Description="审批流程"
Title="审批流程"
Sequence="52"
Template="Ribbon.Templates.CustomTemplateExample">
<Controls Id="Ribbon.ApprovalRibbon.ApprovalGroup.Controls">
<Button
Id="Ribbon.ApprovalRibbon.ApprovalGroup.HelloWorld"
Command="ApprovalRibbon.SubmitCommand"
Sequence="15"
Description="提交"
LabelText="提交"
TemplateAlias="cust1"
Image32by32="/_layouts/images/ALLMTGS.gif"/>
<Button
Id="Ribbon.ApprovalRibbon.ApprovalGroup.Approval"
Command="ApprovalRibbon.ApprovalCommand"
Sequence="15"
Description="审批"
LabelText="审批"
TemplateAlias="cust2"
Image32by32="/_layouts/images/ALLMTGS.gif"/>
</Controls>
</Group>
</Groups>
</Tab>
</CommandUIDefinition>
<CommandUIDefinition Location="Ribbon.Templates._children">
<GroupTemplate Id="Ribbon.Templates.CustomTemplateExample">
<Layout
Title="OneLargeTwoMedium"
LayoutTitle="OneLargeTwoMedium">
<Section Alignment="Top" Type="OneRow">
<Row>
<ControlRef DisplayMode="Large" TemplateAlias="cust1" />
</Row>
</Section>
<Section Alignment="Top" Type="OneRow">
<Row>
<ControlRef DisplayMode="Large" TemplateAlias="cust2" />
</Row>
</Section>
</Layout>
</GroupTemplate>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="ApprovalRibbon.SubmitCommand"
CommandAction="javascript:MakeModelDialog('提交审批', 560, 200, '/_layouts/15/DVT.SharePoint.Portal.RLGS.Resources/ConfirmSubmitDetail.aspx?selectdata=' + GetDetailID());"/>
<CommandUIHandler
Command="ApprovalRibbon.ApprovalCommand"
CommandAction="javascript:approval();"/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
修改现有按钮
修改现有按钮,只需要重写Location的定义就可以了,下面的代码修改了列表的工作流按钮
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="ReplaceWorkFlow"
Location="CommandUI.Ribbon.ListView"
RegistrationId="100"
RegistrationType="List"
Rights="EditListItems">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.ListItem.Workflow.ViewWorkflows" >
<Button
Id="Ribbon.ListItem.Workflow.ViewWorkflows"
Sequence="10"
Command="ReplaceWorkFlowCommand"
Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-48" Image16by16Left="-208"
Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-192" Image32by32Left="-416"
LabelText="$Resources:core,cui_ButWorkflows;"
ToolTipTitle="$Resources:core,cui_ButWorkflows;"
ToolTipDescription="$Resources:core,cui_STT_ButItemManageWorkflow;"
TemplateAlias="o1"
/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="ReplaceWorkFlowCommand"
CommandAction="javascript:alert('请点击左上角的审批“流程-提交” 进行发布数据');"/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
修改现有按钮时比较重要的一点就是,找到location,以下是参考的内容:
- msdn 默认服务器功能区自定义位置,这些 ID 可在 CMDUI.xml 文件中找到,该文件存储在前端 Web 服务器上的 %ProgramFiles%Common FilesMicrosoft Sharedweb server extensions14TEMPLATEGLOBALXML 目录中。
- 找到正确的location定义