/// <summary> /// Adding ribbon tab to control's page here /// </summary> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!DisplayTab) { return; } var tabDefinition = GetTabDefinition(); try { if (SPRibbon.GetCurrent(this.Page) == null) { return; } if (tabDefinition != null && !this.DesignMode) { RibbonController.Current.AddRibbonTabToPage(tabDefinition, this.Page, false); } } catch (Exception ex) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Fluent Ribbon", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "Error occured: " + ex.Message + "\nStackTrace: " + ex.StackTrace); } }
protected static void AddContextualTab(Page page, string initialTabId, string approvalsTab) { var ribbon = SPRibbon.GetCurrent(page); if (ribbon != null) { ribbon.Minimized = false; ribbon.CommandUIVisible = true; if (!ribbon.IsTabAvailable(initialTabId)) { ribbon.MakeTabAvailable(initialTabId); } } var language = SPContext.Current.Web.Language.ToString(); Microsoft.Web.CommandUI.Ribbon ribbon1 = SPRibbon.GetCurrent(page); var ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(approvalsTab.Replace(LanguageId, language)); ribbon1.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ListContextualGroup._children"); ribbonExtensions.LoadXml(Properties.Resources.flexible2); ribbon1.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml("<Button Id=\"Ribbon.List.Datasheet.Print\" Sequence=\"10\" Command=\"PrintGrid\" Image16by16=\"/_layouts/epmlive/images/print.gif\" Image32by32=\"/_layouts/epmlive/images/printmenu.gif\" LabelText=\"Print\" ToolTipTitle=\"Print\" ToolTipDescription=\"\" TemplateAlias=\"o1\"/>"); ribbon1.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.List.Share.Controls._children"); ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(Properties.Resources.txtTimesheetTemplate.Replace(LanguageId, language)); ribbon1.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); }
private void AddContextualTab() { var currentWeb = SPContext.Current.Web; var ribbon = SPRibbon.GetCurrent(Page); if (ribbon != null) { ribbon.Minimized = false; ribbon.CommandUIVisible = true; const string InitialTabId = "Ribbon.ListItem"; if (!ribbon.IsTabAvailable(InitialTabId)) { ribbon.MakeTabAvailable(InitialTabId); } } var language = currentWeb.Language.ToString(); Ribbon ribbon1 = SPRibbon.GetCurrent(Page); var ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(Resources.txtResourcePlannerTab.Replace("#language#", language)); ribbon1.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ListContextualGroup._children"); ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(Resources.gridribbontemplate.Replace("#language#", language)); ribbon1.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); }
// Private Methods (1) /// <summary> /// Adds the contextual tab. /// </summary> private void AddContextualTab() { SPRibbon spRibbon = SPRibbon.GetCurrent(Page); if (spRibbon == null) { return; } var ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(_contextualTab.Replace("{title}", DisplayTitle)); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ContextualTabs._children"); ribbonExtensions.LoadXml(_contextualTabTemplate); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); spRibbon.Minimized = false; spRibbon.CommandUIVisible = true; if (!spRibbon.IsTabAvailable(MANAGE_TAB)) { spRibbon.MakeTabAvailable(MANAGE_TAB); } }
/// <summary> /// Add ribbon tab to the specified page /// </summary> /// <param name="definition">Definition of the ribbon tab</param> /// <param name="page">Page, to which the definition will be added</param> /// <param name="makeInitial">if true, the ribbon tab will be active when page is loaded, otherwise the default tab (Browse) will be active</param> /// <remarks> /// <para> /// This method is intended to provide ability to add local ribbon customizations. The customizations have to be specified each time /// when the page gets loaded. To add permanent customizations, use <see cref="RibbonCustomAction"/>. /// </para> /// <para> /// This method cannot create contextual tabs, only static. /// </para> /// </remarks> /// <example> /// <para> /// Example of usage: /// </para> /// <code lang="csharp"> /// public class MyPage : LayoutsPageBase /// { /// public void Page_Load(object sender, EventArgs e) /// { /// RibbonController.Current.AddRibbonTabToPage(MyRibbonManager.MyTabDefinition, this, true); /// } /// } /// </code> /// <para> /// This will add initially active ribbon tab to the application page MyPage. /// Tab definition is supposed to be stored in some custom user class MyRibbonManager. /// </para> /// <para> /// Also its possible to use this method for adding tabs to ribbon from webparts. But you must provide different ribbon ids /// for different webparts and even for different instances of the same webpart. /// </para> /// </example> public void AddRibbonTabToPage(TabDefinition definition, Page page, bool makeInitial) { if (SPRibbon.GetCurrent(page) == null) { throw new Exception("SPRibbon.GetCurrent returned null for the specified page!"); } AddRibbonExtension(XmlGenerator.Current.GetTabXML(definition), page, "Ribbon.Tabs", makeInitial); AddGroupTemplatesRibbonExtensions(definition.GroupTemplates, page); var commands = new RibbonCommandRepository(); commands.AddCommands(definition); page.Items[CommandsKey] = commands; page.PreRenderComplete -= new EventHandler(page_PreRenderComplete); page.PreRenderComplete += new EventHandler(page_PreRenderComplete); Ribbon ribbon = SPRibbon.GetCurrent(page); ribbon.MakeTabAvailable("Ribbon." + definition.Id); if (makeInitial) { ribbon.InitialTabId = "Ribbon." + definition.Id; } }
private void CheckRibbonBehavior() { SPRibbon spRibbon = SPRibbon.GetCurrent(Page); if (spRibbon == null) { return; } //Ribbon Behaviour: SPList list = SPContext.Current.Web.Lists.TryGetList("Resources"); EPMLiveCore.GridGanttSettings gSettings = new EPMLiveCore.GridGanttSettings(list); string resourceRibbonBehavior = gSettings.RibbonBehavior; switch (resourceRibbonBehavior) { case "2": //Hidden { spRibbon.TrimById(HIDE_TAB); spRibbon.TrimById(PAGE_TAB); spRibbon.TrimById(MANAGE_TAB); spRibbon.TrimById(VIEWS_TAB); } break; } }
protected override void CreateChildControls() { //SPSecurity.RunWithElevatedPrivileges(delegate() //{ SPRibbon current = SPRibbon.GetCurrent(this.Page); if (current != null) { current.MakeTabAvailable("Ribbon.Read"); current.InitialTabId = "Ribbon.Read"; current.Minimized = true; } //}); //current.TrimById("Ribbon.ListForm.Display"); //SPRibbonScriptManager manager = new SPRibbonScriptManager(); //List<IRibbonCommand> commands = new List<IRibbonCommand>(); //bool admin = base.GlobalAdmin.IsCurrentUserMachineAdmin(); //commands.Add(new SPRibbonCommand("WebAppTab")); // <script type='txt/javascript'> //_spBodyOnLoadFunctionNames.push("InitTab"); //function InitTab() //{ //InitializeTab("Ribbon.Document"); //} //</script> }
/// <summary> /// Builds and adds the custom ribbon tab /// </summary> protected virtual void AddRibbonTab() { try { // Gets the current instance of the ribbon on the page and replaces it with the custom ribbon. Ribbon = SPRibbon.GetCurrent(this.Page); XmlDocument ribbonExtensions = new XmlDocument(); Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("{0}.{1}.xml", RIBBON_XML_FILE_LOCATION, "SPAtab")); XmlTextReader mainTab = new XmlTextReader(stream); ribbonExtensions.Load(mainTab); Ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Tabs._children"); // Adds the custom tab stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("{0}.{1}.xml", RIBBON_XML_FILE_LOCATION, "SPAcontextualtab")); XmlTextReader contextualTab = new XmlTextReader(stream); ribbonExtensions.Load(contextualTab); Ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); Ribbon.CommandUIVisible = true; if (!Ribbon.IsTabAvailable(RIBBON_INITIAL_TAB_ID)) { Ribbon.MakeTabAvailable(RIBBON_INITIAL_TAB_ID); } } catch (Exception ex) { SPA.Error.WriteError(ex); } }
public string GetCallbackResult() { try { if (result != null) { throw (result); } } catch (SPException exception) { base.SetGenericErrorMessage(exception); } base.RefreshPageState(); base.parentStateControl.OnPageStateChanged(); SPRibbon ribbon = SPRibbon.GetCurrent(this.Page); if (ribbon != null) { string currentTab = ribbon.ActiveTabId; ribbon.SetInitialTabId(currentTab, "WSSPageStateVisibilityContext"); } //UriBuilder builder = new UriBuilder(HttpContext.Current.Request.Url.OriginalString); //SPUtility.Redirect(builder.Uri.PathAndQuery, SPRedirectFlags.Trusted, HttpContext.Current); return(base.BuildReturnValue(string.Format("{0} has been changed.Refresh your page.", action))); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (SPContext.Current != null) { GetSources(); } var tabDefinition = GetTabDefinition(); try { if (SPRibbon.GetCurrent(this.Page) == null) { return; } if (tabDefinition != null && !this.DesignMode) { RibbonController.Current.AddRibbonTabToPage(tabDefinition, this.Page, false); } } catch (Exception ex) { ex.ToString(); } }
private void HideRibbon() { SPRibbon ribbon = SPRibbon.GetCurrent(this.Page); if (ribbon != null) { ribbon.Minimized = true; } }
/// <summary> /// Register the XML extension for the ribbon /// </summary> /// <param name = "xmlExtension">Ribbon XML extension string</param> /// <param name = "location">Location of the ribbon definition to register</param> public void RegisterRibbonExtension(string xmlExtension, string location) { var ribbonExtension = new XmlDocument(); ribbonExtension.LoadXml(xmlExtension); // Register the ribbon extension SPRibbon.GetCurrent(Page).RegisterDataExtension(ribbonExtension.FirstChild, location); }
private void AddContextualTab() { Ribbon ribbon = SPRibbon.GetCurrent(Page); var ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(_contextualTab); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ContextualTabs._children"); ribbonExtensions.LoadXml(_contextualTabTemplate); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); }
private void AddRibbonExtension(string xml, Page page, string parentId, bool makeInitial) { Ribbon ribbon = SPRibbon.GetCurrent(page); ribbon.CommandUIVisible = true; ribbon.Minimized = makeInitial ? false : ribbon.Minimized; XmlDocument ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(xml); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, parentId + "._children"); }
private void AddGroupTemplatesRibbonExtensions(IEnumerable <GroupTemplateDefinition> templates, Page page) { Ribbon ribbon = SPRibbon.GetCurrent(page); XmlDocument ribbonExtensions = new XmlDocument(); foreach (GroupTemplateDefinition template in templates) { ribbonExtensions.LoadXml(template.XML); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); } }
private void HideRibbonElements() { var rm = SPRibbon.GetCurrent(Page); if (rm != null && RibbonHiddenElements != null) { foreach (var element in RibbonHiddenElements) { rm.TrimById(element); } } }
// Private Methods (1) private void RegisterRibbon() { var xmlDocument = new XmlDocument(); SPRibbon spRibbon = SPRibbon.GetCurrent(Page); xmlDocument.LoadXml(Resources.MyWorkWebPart_ContextualTab.Replace("{title}", "My Work")); spRibbon.RegisterDataExtension(xmlDocument.FirstChild, "Ribbon.Tabs._children"); xmlDocument.LoadXml(Resources.MyWorkWebPart_ContextualTabTemplate); spRibbon.RegisterDataExtension(xmlDocument.FirstChild, "Ribbon.Templates._children"); spRibbon.Minimized = false; spRibbon.CommandUIVisible = true; }
protected override void CreateChildControls() { //SPSecurity.RunWithElevatedPrivileges(delegate() //{ SPRibbon current = SPRibbon.GetCurrent(this.Page); if (current != null) { current.MakeTabAvailable("Ribbon.Read"); current.InitialTabId = "Ribbon.Read"; current.Minimized = true; } //}); }
public bool CreateNew = false; // Create or Edit mode protected override void OnInit(EventArgs e) { InitHtmlEditors(); SPRibbon ribbon = SPRibbon.GetCurrent(this.Page); if (ribbon != null) { ribbon.CommandUIVisible = true; ribbon.TrimById("Ribbon.EditingTools.CPEditTab.Layout"); ribbon.TrimById("Ribbon.EditingTools.CPEditTab.Styles"); ribbon.TrimById("Ribbon.EditingTools.CPEditTab.EditAndCheckout"); } base.OnInit(e); }
protected override void OnPreRender(EventArgs e) { var list = SPContext.Current.List; var listName = list != null ? list.Title : string.Empty; string viewName; var viewContext = SPContext.Current.ViewContext; if (viewContext != null && viewContext.View != null) { viewName = viewContext.View.Title; } else { viewName = string.Empty; } ribbon = SPRibbon.GetCurrent(Page); ribbonCommands = new List <IRibbonCommand>(); RegisterRibbonExtension(SPContext.Current.Web, listName, viewName); if (isRegistedRibbons) { // Register required scripts ScriptLink.RegisterScriptAfterUI(Page, "CUI.js", false, true); ScriptLink.RegisterScriptAfterUI(Page, "SP.js", false, true); ScriptLink.RegisterScriptAfterUI(Page, "SP.Runtime.js", false, true); ScriptLink.RegisterScriptAfterUI(Page, "SP.Ribbon.js", false, true); // Register custom page component to handle custom ribbon commands if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "Register Ribbon Customization")) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Register Ribbon Customization", RibbonCustomizationScript, true); } // Register custom ribbon commands var ribbonScriptManager = new SPRibbonScriptManager(); ribbonScriptManager.RegisterGetCommandsFunction(Page, "getGlobalCommands", ribbonCommands); ribbonScriptManager.RegisterCommandEnabledFunction(Page, "commandEnabled", ribbonCommands); ribbonScriptManager.RegisterHandleCommandFunction(Page, "handleCommand", ribbonCommands); } base.OnPreRender(e); }
private void AddRibbonTab() { // Gets the current instance of the ribbon on the page. SPRibbon ribbon = SPRibbon.GetCurrent(this.Page); //Prepares an XmlDocument object used to load the ribbon XmlDocument ribbonExtensions = new XmlDocument(); //WorkPlanner Tab ribbonExtensions.LoadXml(Properties.Resources.txtBuildTeamTab); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Tabs._children"); //Load the custom templates and register the ribbon. ribbonExtensions.LoadXml(Properties.Resources.txtBuildTeamRibbonTemplate); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); ribbon.Minimized = false; ribbon.CommandUIVisible = true; const string initialTabId = "Ribbon.BuildTeam"; if (!ribbon.IsTabAvailable(initialTabId)) { ribbon.MakeTabAvailable(initialTabId); } ribbon.InitialTabId = initialTabId; if (bCanEditTeam != "true") { if (sDisable != "") { ribbon.TrimById("Ribbon.BuildTeam.ResourceGroup"); } ribbon.TrimById("Ribbon.BuildTeam.StandardGroup.SaveCloseButton"); } else if (sDisable != "") { ribbon.TrimById("Ribbon.BuildTeam.ResourceGroup"); ribbon.TrimById("Ribbon.BuildTeam.TeamGroup.AddToTeam"); ribbon.TrimById("Ribbon.BuildTeam.TeamGroup.RemoveFromTeam"); } }
public static void AddRibbonButtonsToPage(List <ListMetadataAction> ribbonBtns, Page page) { // Gets the current instance of the ribbon on the page. SPRibbon ribbon = SPRibbon.GetCurrent(page); XmlDocument ribbonExtensions = new XmlDocument(); //Load the contextual tab XML and register the ribbon. ribbonExtensions.LoadXml(string.Format(Constants.Ribbon.VIEW_TAB_TEMPLATE, string.Join("", ribbonBtns.Select(b => b.GetButtonAsXml())))); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Tabs._children"); //Load the custom templates and register the ribbon. ribbonExtensions.LoadXml(Constants.Ribbon.CONTEXTUAL_TAB_TEMPLATE); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); ribbon.Minimized = false; ribbon.CommandUIVisible = true; const string initialTabId = "Ribbon.RosterTab"; if (!ribbon.IsTabAvailable(initialTabId)) { ribbon.MakeTabAvailable(initialTabId); } ribbon.InitialTabId = initialTabId; // REGISTER COMMANDS var commands = new List <IRibbonCommand>(); // register the command at the ribbon. Include the callback to the server to generate the xml ribbonBtns.ToList().ForEach(b => { commands.Add(new SPRibbonCommand(b.GetCommandName(), b.Command, "true")); }); //Register initialize function var manager = new SPRibbonScriptManager(); var methodInfo = typeof(SPRibbonScriptManager).GetMethod("RegisterInitializeFunction", BindingFlags.Instance | BindingFlags.NonPublic); methodInfo.Invoke(manager, new object[] { page, "InitPageComponent", "/_layouts/15/Roster.Presentation/js/PageComponent.js", false, "Roster.PageComponent.initialize()" }); // Register ribbon scripts manager.RegisterGetCommandsFunction(page, "getGlobalCommands", commands); manager.RegisterCommandEnabledFunction(page, "commandEnabled", commands); manager.RegisterHandleCommandFunction(page, "handleCommand", commands); }
// Private Methods (1) /// <summary> /// Adds the contextual tab. /// </summary> private void AddContextualTab() { SPRibbon spRibbon = SPRibbon.GetCurrent(Page); if (spRibbon == null) { return; } var ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(_contextualTab.Replace("{title}", DisplayTitle)); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ContextualTabs._children"); ribbonExtensions.LoadXml(_contextualTabTemplate); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); spRibbon.MakeTabAvailable(MANAGE_TAB_ID); spRibbon.MakeTabAvailable(VIEWS_TAB_ID); }
/// <summary> /// Registers the ribbon. /// </summary> private void RegisterRibbon() { var xmlDocument = new XmlDocument(); SPRibbon spRibbon = SPRibbon.GetCurrent(Page); xmlDocument.LoadXml(Resources.AssignmentPlanner_ContextualTab); spRibbon.RegisterDataExtension(xmlDocument.FirstChild, "Ribbon.Tabs._children"); xmlDocument.LoadXml(Resources.AssignmentPlanner_ContextualTabTemplate); spRibbon.RegisterDataExtension(xmlDocument.FirstChild, "Ribbon.Templates._children"); spRibbon.Minimized = false; spRibbon.CommandUIVisible = true; if (!spRibbon.IsTabAvailable(INITIAL_TAB_ID)) { spRibbon.MakeTabAvailable(INITIAL_TAB_ID); } spRibbon.InitialTabId = INITIAL_TAB_ID; }
protected override void OnPreRender(EventArgs e) { try { if (this.Page == null) { return; } if (SPContext.Current == null) { return; } SPRibbon currentRibbon = SPRibbon.GetCurrent(this.Page); WorkBox workBox = null; // If we're looking at a modal dialog box then we want to // leave workBox == null so that no further action is taken: if (Request.QueryString["IsDlg"] == null || Request.QueryString["IsDlg"] != "1") { workBox = WorkBox.GetIfWorkBox(SPContext.Current); } if (workBox != null) { //OK so we are looking at a work box. isWorkBox = true; SPWeb workBoxWeb = workBox.Web; if (!currentRibbon.IsTabAvailable("WorkBoxFramework.Ribbon.WorkBox")) { currentRibbon.MakeTabAvailable("WorkBoxFramework.Ribbon.WorkBox"); } // Now let's register the commands for the tasks flyout button: // Inspired by blogs: // http://www.sharepointnutsandbolts.com/2010/02/ribbon-customizations-dropdown-controls.html // http://patrickboom.wordpress.com/2010/05/25/adding-a-custom-company-menu-tab-with-dynamic-menu-on-the-ribbon/ // http://www.wictorwilen.se/Post/Creating-a-SharePoint-2010-Ribbon-extension-part-2.aspx WBLogging.DEBUG.Monitorable("About to do various for Tasks flyout menu:"); ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Core.js", false, false); ScriptLink.RegisterScriptAfterUI(this.Page, "CUI.js", false, false); ScriptLink.RegisterScriptAfterUI(this.Page, "core.js", true, false); ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Ribbon.js", false, false); ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Runtime.js", false, false); ScriptLink.RegisterScriptAfterUI(this.Page, "SP.js", false, false); //ScriptLink.RegisterScriptAfterUI(this.Page, "WorkBoxFramework/PageComponent.js", false, true); var commands = new List <IRibbonCommand>(); // register the command at the ribbon. Include the callback to the server to generate the xml commands.Add(new SPRibbonCommand("WorkBoxFramework.Command.PopulateDynamicTasks", "if (wbf_callCount==0) WorkBoxFramework_getDynamicTasksMenu('',''); wbf_callCount++; if (wbf_callCount > 1000) wbf_menuXml = WorkBoxFramework_errorMenuXml('Timeout'); if (wbf_menuXml != '') properties.PopulationXML = wbf_menuXml;")); commands.Add(new SPRibbonCommand("WorkBoxFramework.Command.PopulateDynamicTemplates", "if (wbf_callCount==0) WorkBoxFramework_getDynamicTasksMenu('',''); wbf_callCount++; if (wbf_callCount > 1000) wbf_menu2Xml = WorkBoxFramework_errorMenuXml('Timeout'); if (wbf_menu2Xml != '') properties.PopulationXML = wbf_menu2Xml;")); // commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "properties.PopulationXML = errorMenuXml();")); //commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "alert('Callaa to Popdyn'); if (menuXml == '') { CreateServerMenu('',''); } else { properties.PopulationXML = menuXml; }")); // commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "alert('Call to Popdyn: ' + menuXml); properties.PopulationXML = menuXml;")); //Register various: var manager = new SPRibbonScriptManager(); // Register ribbon scripts manager.RegisterGetCommandsFunction(Page, "getGlobalCommands", commands); manager.RegisterCommandEnabledFunction(Page, "commandEnabled", commands); manager.RegisterHandleCommandFunction(Page, "handleCommand", commands); WBLogging.DEBUG.Monitorable("Registered ribbon scripts"); //Register initialize function var methodInfo = typeof(SPRibbonScriptManager).GetMethod("RegisterInitializeFunction", BindingFlags.Instance | BindingFlags.NonPublic); methodInfo.Invoke(manager, new object[] { Page, "InitPageComponent", "/_layouts/WorkBoxFramework/PageComponent.js", false, "WorkBoxFramework.PageComponent.initialize()" }); // register the client callbacks so that the JavaScript can call the server. ClientScriptManager cm = this.Page.ClientScript; String cbReference = cm.GetCallbackEventReference(this, "arg", "WorkBoxFramework_receiveTasksMenu", "", "WorkBoxFramework_processCallBackError", false); String callbackScript = "function WorkBoxFramework_getDynamicTasksMenu(arg, context) {" + cbReference + "; }"; WBLogging.DEBUG.Monitorable("Creating the call back function WorkBoxFramework_getDynamicTasksMenu to call: \n" + callbackScript); cm.RegisterClientScriptBlock(this.GetType(), "WorkBoxFramework_getDynamicTasksMenu", callbackScript, true); // Now let's check or set the last visited Guid: WBUser user = new WBUser(workBox); UserProfile profile = user.Profile; // SPSite _site = SPContext.Current.Site; // SPServiceContext _serviceContext = SPServiceContext.GetContext(_site); // UserProfileManager _profileManager = new UserProfileManager(_serviceContext); // UserProfile profile = _profileManager.GetUserProfile(true); scriptForSettingGlobalVariables = makeScriptForSettingWorkBoxVariables(workBox, user, profile); UserProfileValueCollection lastVisitedGuidUserProfileValueCollection = profile[WorkBox.USER_PROFILE_PROPERTY__WORK_BOX_LAST_VISITED_GUID]; bool needsUpdating = false; if (lastVisitedGuidUserProfileValueCollection == null || lastVisitedGuidUserProfileValueCollection.Count == 0) { needsUpdating = true; } else { Guid lastGuid = new Guid(lastVisitedGuidUserProfileValueCollection.Value.ToString()); if (!lastGuid.Equals(workBoxWeb.ID)) { needsUpdating = true; } } if (needsUpdating) { workBoxWeb.AllowUnsafeUpdates = true; string currentGuidString = workBoxWeb.ID.ToString(); lastVisitedGuidUserProfileValueCollection.Clear(); lastVisitedGuidUserProfileValueCollection.Add(currentGuidString); // OK now we're going to make sure that this work box is the latest on the list of recently visited work boxes: WBLogging.WorkBoxes.Verbose("Updating the list of recently visited work boxes - as we've just come to this work box"); UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES]; //string mostRecentWorkBoxDetails = workBoxWeb.Title + "|" + workBoxWeb.Url + "|" + workBox.UniqueID + "|" + workBoxWeb.ID.ToString() + "|" + DateTime.Now.Ticks; WBLink mostRecentWorkBoxDetails = new WBLink(workBox, true); WBLogging.WorkBoxes.Verbose("The most recent work box details are: " + mostRecentWorkBoxDetails); List <String> newList = new List <String>(); newList.Add(mostRecentWorkBoxDetails.ToString()); if (workBoxesRecentlyVisited.Value != null) { string[] recentWorkBoxes = workBoxesRecentlyVisited.Value.ToString().Split(';'); int totalLength = 0; foreach (string recentWorkBox in recentWorkBoxes) { if (totalLength >= 3000) { break; } if (!recentWorkBox.Contains(currentGuidString)) { newList.Add(recentWorkBox); totalLength += recentWorkBox.Length + 1; } } } profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES].Value = WBUtils.JoinUpToLimit(";", newList, 3100); profile.Commit(); workBoxWeb.AllowUnsafeUpdates = false; } } else { scriptForSettingGlobalVariables = makeScriptForSettingNonWorkBoxVariables(SPContext.Current.Web); if (currentRibbon.IsTabAvailable("WorkBoxFramework.Ribbon.WorkBox")) { currentRibbon.TrimById("WorkBoxFramework.Ribbon.WorkBox"); } } // currentRibbon.MakeContextualGroupInitiallyVisible("WorkBoxFramework.Ribbon.ContextualGroup", string.Empty); } catch (Exception exception) { // If this isn't working - let's just do nothing so that at least the SharePoint site is visible. scriptForSettingGlobalVariables = "<!-- Exception thrown in MaybeShowWorkBoxRibbonTools \n\n" + exception.Message + "\n\n" + exception.StackTrace + "\n\n-->"; } }
// Protected Methods (2) protected override void OnPreLoad(EventArgs e) { SPRibbon spRibbon = SPRibbon.GetCurrent(Page); /*if (spRibbon == null) return; * * var ribbonExtensions = new XmlDocument(); * * ribbonExtensions.LoadXml(Properties.Resources.txtMyTimesheet_Ribbon.Replace("{title}", "My Timesheet").Replace("#language#", SPContext.Current.Web.Language.ToString())); * spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ContextualTabs._children"); * * ribbonExtensions.LoadXml(Properties.Resources.txtMyTimesheet_Template); * spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); * * * // ribbonExtensions = new XmlDocument(); * // ribbonExtensions.LoadXml(@"<Label * // Id=""Ribbon.Timesheet.ActionsGroup.StatusLabel2"" * // Sequence=""11"" * // Command=""Ribbon.MyTimesheet.StatusLabel1"" * // LabelText=""" + sStatus + @""" * // Image16by16=""/_layouts/epmlive/images/tss_" + sStatus + @".png"" * // TemplateAlias=""oM"" * // /> "); * // spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.MyTimesheet.ActionsGroup.Controls._children"); * string sUserId = ""; * * if (!string.IsNullOrEmpty(Page.Request["Delegate"])) * { * SPUser user = TimesheetAPI.GetUser(SPContext.Current.Web, Page.Request["Delegate"]); * sUserId = user.ID.ToString(); * } * * * DataTable dtTsDelegates = EPMLiveCore.API.APITeam.GetResourcePool("<Resources FilterField=\"TimesheetDelegates\" FilterFieldValue=\"" + SPContext.Current.Web.CurrentUser.Name + "\" Columns=\"\"/>", SPContext.Current.Web); * string sCurrentDelegate = ""; * string sDelegates = ""; * * foreach (DataRow dr in dtTsDelegates.Rows) * { * if (sUserId == dr["SPID"].ToString()) * sCurrentDelegate = dr["Title"].ToString(); * * sDelegates += dr["SPID"].ToString() + "|" + dr["Title"].ToString() + "^"; * } * * sDelegates = sDelegates.Trim('^'); * * if (sDelegates == "") * { * spRibbon.TrimById("Ribbon.MyTimesheet.DelegateGroup"); * } * * * if (sCurrentDelegate != "") * { * ribbonExtensions = new XmlDocument(); * ribbonExtensions.LoadXml(@"<Label * Id=""Ribbon.Timesheet.DelegateGroup.CurrentDelegateLabel1"" * Sequence=""20"" * Command=""Ribbon.MyTimesheet.CurrentDelegate"" * LabelText=""Current Delegate:"" * TemplateAlias=""oM"" * /> "); * spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.MyTimesheet.DelegateGroup.Controls._children"); * * * ribbonExtensions = new XmlDocument(); * ribbonExtensions.LoadXml(@"<Label * Id=""Ribbon.Timesheet.DelegateGroup.CurrentDelegateLabel2"" * Sequence=""20"" * Command=""Ribbon.MyTimesheet.CurrentDelegate"" * LabelText=""" + sCurrentDelegate + @""" * TemplateAlias=""oM"" * /> "); * spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.MyTimesheet.DelegateGroup.Controls._children"); * }*/ spRibbon.MakeTabAvailable("Ribbon.MyTimesheetTab"); spRibbon.MakeTabAvailable("Ribbon.MyTimesheetViewsTab"); //spRibbon.InitialTabId = "Ribbon.MyTimesheetTab"; spRibbon.Minimized = false; spRibbon.CommandUIVisible = true; base.OnPreRender(e); }
private void AddContextualTab() { SPRibbon spRibbon = SPRibbon.GetCurrent(Page); if (spRibbon == null) { return; } var ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(Properties.Resources.txtMyTimesheet_Ribbon.Replace("{title}", DisplayTitle).Replace("#language#", SPContext.Current.Web.Language.ToString())); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ContextualTabs._children"); ribbonExtensions.LoadXml(Properties.Resources.txtMyTimesheet_Template); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); // ribbonExtensions = new XmlDocument(); // ribbonExtensions.LoadXml(@"<Label // Id=""Ribbon.Timesheet.ActionsGroup.StatusLabel2"" // Sequence=""11"" // Command=""Ribbon.MyTimesheet.StatusLabel1"" // LabelText=""" + sStatus + @""" // Image16by16=""/_layouts/epmlive/images/tss_" + sStatus + @".png"" // TemplateAlias=""oM"" // /> "); // spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.MyTimesheet.ActionsGroup.Controls._children"); if (sDelegates == "") { spRibbon.TrimById("Ribbon.MyTimesheet.DelegateGroup"); } if (sCurrentDelegate != "") { ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(@"<Label Id=""Ribbon.Timesheet.DelegateGroup.CurrentDelegateLabel1"" Sequence=""20"" Command=""Ribbon.MyTimesheet.CurrentDelegate"" LabelText=""Current Delegate:"" TemplateAlias=""oM"" /> " ); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.MyTimesheet.DelegateGroup.Controls._children"); ribbonExtensions = new XmlDocument(); ribbonExtensions.LoadXml(@"<Label Id=""Ribbon.Timesheet.DelegateGroup.CurrentDelegateLabel2"" Sequence=""20"" Command=""Ribbon.MyTimesheet.CurrentDelegate"" LabelText=""" + sCurrentDelegate + @""" TemplateAlias=""oM"" /> " ); spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.MyTimesheet.DelegateGroup.Controls._children"); } bool bDisable = BApprovalDisabled(); if (bDisable) { spRibbon.TrimById("Ribbon.MyTimesheet.Approvals.TM"); } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); SPRibbon ribbon = SPRibbon.GetCurrent(this.Page); //Prepares an XmlDocument object used to load the ribbon XmlDocument ribbonExtensions = new XmlDocument(); //WorkPlanner Tab ribbonExtensions.LoadXml(Properties.Resources.txtMyTimesheetWork_Ribbon); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Tabs._children"); ribbonExtensions.LoadXml(Properties.Resources.txtMyTimesheetWork_ViewRibbon); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Tabs._children"); ribbonExtensions.LoadXml(Properties.Resources.txtMyTimesheet_Template); ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children"); ribbon.Minimized = false; ribbon.CommandUIVisible = true; const string initialTabId = "Ribbon.MyTimesheetWorkTab"; if (!ribbon.IsTabAvailable(initialTabId)) { ribbon.MakeTabAvailable(initialTabId); } if (!ribbon.IsTabAvailable("Ribbon.MyTimesheetWorkViewsTab")) { ribbon.MakeTabAvailable("Ribbon.MyTimesheetWorkViewsTab"); } ribbon.InitialTabId = initialTabId; var manager = new SPRibbonScriptManager(); var methodInfo = typeof(SPRibbonScriptManager).GetMethod("RegisterInitializeFunction", BindingFlags.Instance | BindingFlags.NonPublic); methodInfo.Invoke(manager, new object[] { Page, "InitPageComponent", "/_layouts/epmlive/MyTimesheetWorkContextualTabPageComponent.js", false, "MyTimesheetWorkPageComponent.PageComponent.initialize()" }); var commands = new List <IRibbonCommand>(); //commands.Add(new SPRibbonCommand("Ribbon.MyTimesheetWork.AddWork", "alert('d');", "true")); manager.RegisterGetCommandsFunction(Page, "getGlobalCommands", commands); manager.RegisterCommandEnabledFunction(Page, "commandEnabled", commands); manager.RegisterHandleCommandFunction(Page, "handleCommand", commands); //if(!ribbon.IsTabAvailable("Ribbon.Project")) // ribbon.MakeTabAvailable("Ribbon.Project"); //if(!ribbon.IsTabAvailable("Ribbon.WorkViews")) // ribbon.MakeTabAvailable("Ribbon.WorkViews"); if (Request["nonwork"] == "true") { ribbon.TrimById("Ribbon.MyTimesheetWorkViews.AllWork"); ribbon.TrimById("Ribbon.MyTimesheetWork.ActionsGroup.Search"); } else { bool bDisable = BShowAllWork(); if (!bDisable) { ribbon.TrimById("Ribbon.MyTimesheetWorkViews.AllWork"); } } }
protected override void OnPreRender(EventArgs e) { var list = SPContext.Current.List; var listName = list != null ? list.Title : string.Empty; string viewName; var viewContext = SPContext.Current.ViewContext; if (viewContext != null && viewContext.View != null) { viewName = viewContext.View.Title; } else { viewName = string.Empty; } ribbon = SPRibbon.GetCurrent(Page); //ribbonCommands = new List<IRibbonCommand>(); RegisterRibbonExtension(SPContext.Current.Web, listName, viewName); //if (isRegistedRibbons) //{ ////Fix error Ribbon is disabled // Register required scripts //Microsoft.SharePoint.WebControls.ScriptLink.RegisterScriptAfterUI(Page, "CUI.js", false, true); //Microsoft.SharePoint.WebControls.ScriptLink.RegisterScriptAfterUI(Page, "SP.js", false, true); //Microsoft.SharePoint.WebControls.ScriptLink.RegisterScriptAfterUI(Page, "SP.Runtime.js", false, true); //Microsoft.SharePoint.WebControls.ScriptLink.RegisterScriptAfterUI(Page, "SP.Ribbon.js", false, true); string commandString = ""; foreach (var ribbonCommand in RibbonCommands) { if (commandString != "") { commandString += ","; } commandString += "'" + ribbonCommand.Id + "'"; } string temp = string.Format("return [{0}]", commandString); // Register custom page component to handle custom ribbon commands if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "Register Ribbon Customization")) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Register Ribbon Customization", RibbonCustomizationScript.Replace("getGlobalCommandsTemplate", temp), true); } // Register custom ribbon commands var ribbonScriptManager = new SPRibbonScriptManager(); ribbonScriptManager.RegisterGetCommandsFunction(Page, "getGlobalCommands", RibbonCommands); ribbonScriptManager.RegisterCommandEnabledFunction(Page, "commandEnabled", RibbonCommands); ribbonScriptManager.RegisterHandleCommandFunction(Page, "handleCommand", RibbonCommands); //} base.OnPreRender(e); }
/* * protected void Page_Load(object sender, EventArgs e) * { * try * { * HtmlGenericControl body = this.Master.FindControl("body") as HtmlGenericControl; * if (body != null) * { * body.Attributes.Add("onload", "if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();"); * } * } * catch { }; * } */ protected override void OnLoad(EventArgs e) { base.OnLoad(e); //EnsureChildControls(); SPRibbon current = SPRibbon.GetCurrent(this.Page); if ((current != null) && HttpContext.Current.User.Identity.IsAuthenticated) { if (wpsc == null) { wpsc = new WebPageStateControl(); this.Page.Controls.Add(wpsc); } WebPageSetHomePageHandler homepage = new WebPageSetHomePageHandler(wpsc); this.Controls.Add(homepage); ContentRibbon content = new ContentRibbon(wpsc); this.Controls.Add(content); DesignRibbon design = new DesignRibbon(wpsc); this.Controls.Add(design); CssRegistration.Register("/_layouts/Hemrika/WebSitePage/Hemrika.SharePresence.WebSite.css"); TransformDialog(); var manager = new SPRibbonScriptManager(); var methodInfo = typeof(SPRibbonScriptManager).GetMethod("RegisterInitializeFunction", BindingFlags.Instance | BindingFlags.NonPublic); methodInfo.Invoke(manager, new object[] { Page, "InitPageComponent", "/_layouts/Hemrika/WebSitePage/Hemrika.SharePresence.WebSite.Page.js", false, "Hemrika.SharePresence.WebSite.Page.PageComponent.initialize()" }); current.CommandUIVisible = true; current.CheckForInitializationReadiness = true; current.MakeTabAvailable("Ribbon.Read", "WSSPageStateVisibilityContext"); current.MakeTabAvailable("Ribbon.EditingTools", "WSSPageStateVisibilityContext"); current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Page", "WSSPageStateVisibilityContext"); current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Content", "WSSPageStateVisibilityContext"); current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Design", "WSSPageStateVisibilityContext"); current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.SEO", "WSSPageStateVisibilityContext"); current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Analytics", "WSSPageStateVisibilityContext"); current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Settings", "WSSPageStateVisibilityContext"); current.EnableVisibilityContext("WSSPageStateVisibilityContext"); //current.DisableVisibilityContext("WSSWebPartPage"); //Allow Browse button for visibility //current.TrimById(SPRibbon.ReadTabId); current.TrimById("Ribbon.WebPartPage", "WSSWebPartPage"); current.TrimById("Ribbon.WikiPageTab", "WSSPageStateVisibilityContext"); current.TrimById("Ribbon.EditingTools.CPEditTab.Layout.PageLayout", "WSSPageStateVisibilityContext"); current.TrimById("Ribbon.WebPartInsert", "WSSPageStateVisibilityContext"); current.TrimById("Ribbon.WebPartInsert.Tab", "WSSPageStateVisibilityContext"); current.CommandUIVisible = true; //RegisterWebSitePage(this); //AlohaEditor(this); } else { EnsureChildControls(); ScriptManager manager = ScriptManager.GetCurrent(Page); manager.LoadScriptsBeforeUI = false; manager.AllowCustomErrorsRedirect = true; manager.ScriptMode = ScriptMode.Release; //Remove WPSC script block this.Page.ClientScript.RegisterStartupScript(typeof(SPWebPartManager), "WPSCScriptBlock", string.Empty); } //BlogConnector(); }