Type.registerNamespace('COB.SharePoint.Ribbon.PageComponent');
COB.SharePoint.Ribbon.PageComponent = function () {
COB.SharePoint.Ribbon.PageComponent.initializeBase(this);
}
// the initialize function needs to be called by some script added to the page elsewhere - in the end, it does the important work
// of calling PageManager.addPageComponent()..
COB.SharePoint.Ribbon.PageComponent.initialize = function () {
ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, COB.SharePoint.Ribbon.PageComponent.initializePageComponent), 'SP.Ribbon.js');
}
COB.SharePoint.Ribbon.PageComponent.initializePageComponent = function() {
var ribbonPageManager = SP.Ribbon.PageManager.get_instance();
if (null !== ribbonPageManager) {
ribbonPageManager.addPageComponent(COB.SharePoint.Ribbon.PageComponent.instance);
}
}
COB.SharePoint.Ribbon.PageComponent.prototype = {
init: function () { },
getFocusedCommands: function () {
return ['COB.PageComponent.Command.FieldControl.GroupCommand', 'COB.PageComponent.Command.FieldControl.TabCommand', 'COB.PageComponent.Command.FieldControl.ContextualGroupCommand', 'COB.PageComponent.Command.FieldControl.RibbonCommand'];
},
getGlobalCommands: function () {
return ['COB.PageComponent.Command.DoAction', 'COB.PageComponent.Command.PopulateDropDown', 'COB.PageComponent.Command.QueryDoAction'];
},
canHandleCommand: function (commandId) {
if ((commandId === 'COB.PageComponent.Command.DoAction') ||
(commandId === 'COB.PageComponent.Command.PopulateDropDown') || (commandId === 'COB.PageComponent.Command.QueryDoAction')) {
return true;
}
else {
return false;
}
},
handleCommand: function (commandId, properties, sequence) {
if (commandId === 'COB.PageComponent.Command.FieldControl.GroupCommand') {
alert("COB.PageComponent.Command.FieldControl.GroupCommand fired");
}
if (commandId === 'COB.PageComponent.Command.FieldControl.TabCommand') {
alert("COB.PageComponent.Command.FieldControl.TabCommand fired");
}
if (commandId === 'COB.PageComponent.Command.FieldControl.ContextualGroupCommand') {
alert("COB.PageComponent.Command.FieldControl.ContextualGroupCommand fired");
}
if (commandId === 'COB.PageComponent.Command.FieldControl.RibbonCommand') {
alert("COB.PageComponent.Command.FieldControl.RibbonCommand fired");
}
if (commandId === 'COB.PageComponent.Command.QueryDoAction') {
// this command executes as soon as tab is requested, so do initialization here ready for if our dropdown gets requested..
loadCurrentWebLists();
}
if (commandId === 'COB.PageComponent.Command.PopulateDropDown') {
// actually build the dropdown contents by setting the PopulationXML property to a value with the expected format. We have to deal with possible
// timing issues/dependency on core SharePoint JS code with an ExecuteOrDelay..
ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, getDropdownItemsXml), 'SP.js');
properties.PopulationXML = getDropdownItemsXml();
}
if (commandId === 'COB.PageComponent.Command.DoAction') {
// here we're using the SourceControlId to detect the selected item, but more normally each item would have a unique commandId (rather than 'DoAction').
// However this isn't possible in this case since each item is a list in the current web, and this can change..
var selectedItem = properties.SourceControlId.toString();
var listName = selectedItem.substring(selectedItem.lastIndexOf('.') + 1);
alert("You selected the list: " + listName);
}
},
isFocusable: function () {
return true;
},
receiveFocus: function () {
return true;
},
yieldFocus: function () {
return true;
}
}
// **** BEGIN: helper code specific to this sample ****
// some global variables which we'll use with the async processing..
var lists = null;
var querySucceeded = false;
// use the Client Object Model to fetch the lists in the current site..
function loadCurrentWebLists() {
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
this.lists = web.get_lists();
clientContext.load(lists);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
querySucceeded = true;
}
function onQueryFailed(sender, args) {
querySucceeded = false;
}
function getDropdownItemsXml() {
var sb = new Sys.StringBuilder();
sb.append('<Menu Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu\'>');
sb.append('<MenuSection DisplayMode=\'Menu\' Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu.Manage\'>');
sb.append('<Controls Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu.Manage.Controls\'>');
if (querySucceeded)
{
var listEnumerator = lists.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
sb.append('<Button');
sb.append(' Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu.Manage.');
sb.append(oList.get_title());
sb.append('\'');
sb.append(' Command=\'');
sb.append('COB.PageComponent.Command.DoAction');
sb.append('\'');
sb.append(' LabelText=\'');
sb.append(SP.Utilities.HttpUtility.htmlEncode(oList.get_title()));
sb.append('\'');
sb.append('/>');
}
}
sb.append('</Controls>');
sb.append('</MenuSection>');
sb.append('</Menu>');
return sb.toString();
}
// **** END: helper code specific to this sample ****
COB.SharePoint.Ribbon.PageComponent.registerClass('COB.SharePoint.Ribbon.PageComponent', CUI.Page.PageComponent);
COB.SharePoint.Ribbon.PageComponent.instance = new COB.SharePoint.Ribbon.PageComponent();
NotifyScriptLoadedAndExecuteWaitingJobs("COB.SharePoint.Ribbon.PageComponent.js");