5/09/2011

Writing a Page Component : SharePoint 2010

Code :
<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction

Id="SharedDocAction"

RegistrationType="List"

RegistrationId="101"

Location="CommandUI.Ribbon.ListView">

<CommandUIExtension>

<CommandUIDefinitions>

<CommandUIDefinition

Location="Ribbon.Documents.New.Controls._children">

<Button

Id="CustomContextualButton"

Alt="MyDocumentsNew Alt"

Command="MyDocumentsNewButton"

LabelText="ScriptBlock Button"

ToolTipTitle="Tooltip Title"

Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png?vk=4536" Image16by16Top="-80" Image16by16Left="0"

Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png?vk=4536" Image32by32Top="-96" Image32by32Left="-64"

ToolTipDescription="Tooltip Description"

TemplateAlias="o1"/>

</CommandUIDefinition>

</CommandUIDefinitions>

<CommandUIHandlers>

<CommandUIHandler

Command="MyDocumentsNewButton"

CommandAction="javascript:

ExecuteOrDelayUntilScriptLoaded(_registerMyScriptBlockPageComponent, 'sp.ribbon.js');

function _registerMyScriptBlockPageComponent()

{

Type.registerNamespace('MyScriptBlock');

MyScriptBlock.MyScriptBlockPageComponent = function MyScriptBlockPageComponent_Ctr() {

MyScriptBlock.MyScriptBlockPageComponent.initializeBase(this);

};

MyScriptBlock.MyScriptBlockPageComponent.prototype = {

init: function MyScriptBlockPageComponent_init() {

},

_globalCommands: null,

buildGlobalCommands: function MyScriptBlockPageComponent_buildGlobalCommands() {

if (SP.ScriptUtility.isNullOrUndefined(this._globalCommands)) {

this._globalCommands = [];

this._globalCommands[this._globalCommands.length] = 'DocumentTab';

this._globalCommands[this._globalCommands.length] = 'DocumentNewGroup';

this._globalCommands[this._globalCommands.length] = 'MyDocumentsNewButton';

}

return this._globalCommands;

},

getGlobalCommands: function MyScriptBlockPageComponent_getGlobalCommands() {

return this.buildGlobalCommands();

},

canHandleCommand: function MyScriptBlockPageComponent_canHandleCommand(commandId) {

var items = SP.ListOperation.Selection.getSelectedItems();

if (SP.ScriptUtility.isNullOrUndefined(items))

return false;

if (0 == items.length)

return false;

if (commandId === 'DocumentNewTab'){

return true;

}

if (commandId === 'DocumentNewGroup'){

return true;

}

if (commandId === 'MyDocumentsNewButton'){

return true;

}

return false;

},

handleCommand: function MyScriptBlockPageComponent_handleCommand(commandId, properties, sequence) {

alert('You hit my button!');

return true;

}

}

MyScriptBlock.MyScriptBlockPageComponent.get_instance = function MyScriptBlockPageComponent_get_instance() {

if (SP.ScriptUtility.isNullOrUndefined(MyScriptBlock.MyScriptBlockPageComponent._singletonPageComponent)) {

MyScriptBlock.MyScriptBlockPageComponent._singletonPageComponent = new MyScriptBlock.MyScriptBlockPageComponent();

}

return MyScriptBlock.MyScriptBlockPageComponent._singletonPageComponent;

}

MyScriptBlock.MyScriptBlockPageComponent.registerWithPageManager = function MyScriptBlockPageComponent_registerWithPageManager() {

SP.Ribbon.PageManager.get_instance().addPageComponent(MyScriptBlock.MyScriptBlockPageComponent.get_instance());

}

MyScriptBlock.MyScriptBlockPageComponent.unregisterWithPageManager = function MyScriptBlockPageComponent_unregisterWithPageManager() {

if (false == SP.ScriptUtility.isNullOrUndefined(MyScriptBlock.MyScriptBlockPageComponent._singletonPageComponent)) {

SP.Ribbon.PageManager.get_instance().removePageComponent(MyScriptBlock.MyScriptBlockPageComponent.get_instance());

}

}

MyScriptBlock.MyScriptBlockPageComponent.registerClass('MyScriptBlock.MyScriptBlockPageComponent', CUI.Page.PageComponent);

MyScriptBlock.MyScriptBlockPageComponent.registerWithPageManager();

}

" />

</CommandUIHandlers>

</CommandUIExtension>

</CustomAction>

</Elements>

0 comments: