Ejemplo n.º 1
0
        private void OnReturnRibbonAndInitialTab(DataQueryResult res)
        {
            PMetrics.PerfMark(PMarker.perfCUIRibbonInitStart);

            RibbonBuildContext rbc = (RibbonBuildContext)res.ContextData;

            // Apply any extensions to the data.
            res.QueryData = ApplyDataExtensions(res.QueryData);
            Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            JSObject templates = DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData, DataNodeWrapper.TEMPLATES);
            if (!CUIUtility.IsNullOrUndefined(templates))
                TemplateManager.Instance.LoadTemplates(templates);

            Ribbon = BuildRibbon(res.QueryData, rbc);
            Ribbon.RibbonBuilder = this;
            BuildClient.OnComponentCreated(Ribbon, Ribbon.Id);
            if (RibbonBuildOptions.Minimized)
            {
                Ribbon.MinimizedInternal = true;
            }
            else
            {
                Ribbon.MinimizedInternal = false;
                Tab firstTab = (Tab)Ribbon.GetChild(rbc.InitialTabId);
                if (!CUIUtility.IsNullOrUndefined(firstTab))
                {
                    // We need this in order to set the "ChangedByUser" property of the first
                    // TabSwitch command that comes out of the ribbon correctly.
                    firstTab.SelectedByUser = RibbonBuildOptions.InitialTabSelectedByUser;
                    Ribbon.MakeTabSelectedInternal(firstTab);
                }
            }

            Ribbon.ClientID = RibbonBuildOptions.ClientID;

            bool shouldAttach = !RibbonBuildOptions.Minimized && RibbonBuildOptions.AttachToDOM;

            if (shouldAttach)
            {
                // Scale the ribbon to the scaling index that matches the ribbon that was
                // rendered by the server.  This sets the in memory Ribbon structure to match
                // what was rendered by the server.  This is needed so that Ribbon.AttachInternal()
                // will work properly.  
                if (!((RibbonBuildOptions)Options).Minimized)
                {
                    // We subtract one from this scaling index because internally
                    // this scaling index is an entry into an array of "<ScaleStep>" so
                    // the MaxSize for all the groups is actually index "-1" and the first 
                    // step is index 0.
                    Ribbon.ScaleIndex(rbc.InitialScalingIndex - 1);
                }

                Ribbon.AttachInternal(true);

                // Attach to the QAT and Jewel
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                    Ribbon.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, true, DataSource);
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                    Ribbon.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, true, DataSource);

#if DEBUG
                // Validate that the server rendered ribbon is identical to the client rendered one
                // for this tab.
                if (Options.ValidateServerRendering)
                {
                    RibbonBuilder rb2 = new RibbonBuilder(this.RibbonBuildOptions,
                                                          this.Placeholder,
                                                          null);

                    DataSource ds = new DataSource(this.DataSource.DataUrl,
                                                   this.DataSource.Version,
                                                   this.DataSource.Lcid);

                    rb2.DataSource = ds;
                    SPRibbon r2 = rb2.BuildRibbon(res.QueryData, rbc);
                    r2.Id += "-client";
                    r2.ClientID = RibbonBuildOptions.ClientID + "-client";
                    r2.RibbonBuilder = this;
                    if (!RibbonBuildOptions.Minimized)
                        r2.Minimized = false;

                    // Clone all the peripheral sections for the client-rendering version
                    Div p_qrc = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.QATRowCenter);
                    Div p_qrr = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.QATRowRight);
                    Div p_trl = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.TabRowLeft);
                    Div p_trr = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.TabRowRight);

                    Div hiddenClonedPeripherals = new Div();
                    hiddenClonedPeripherals.Style.Display = "none";
                    Browser.Document.Body.AppendChild(hiddenClonedPeripherals);

                    Div clone;
                    if (null != p_qrc)
                    {
                        clone = (Div)p_qrc.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_qrr)
                    {
                        clone = (Div)p_qrr.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_trl)
                    {
                        clone = (Div)p_trl.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_trr)
                    {
                        clone = (Div)p_trr.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }

                    r2.MakeTabSelectedInternal((Tab)r2.GetChild(rbc.InitialTabId));
                    r2.RefreshInternal();

                    if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                        r2.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, false, ds);
                    if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                        r2.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, false, ds);

                    r2.ScaleIndex(rbc.InitialScalingIndex - 1);
                    r2.CompleteConstruction();

                    // If this returns a message it means that it found some inconsistencies
                    // between the DOM Nodes
                    CompareNodes(Ribbon.ElementInternal, r2.ElementInternal);
                }
#endif
            }
            else
            {
                // Do the minimum amount of work necessary in order to be able to 
                // get the outer ribbon element and to be able to attach the Jewel and QAT.
                Ribbon.EnsureDOMElement();

                // Build the QAT and Jewel after the ribbon so that the placeholders
                // will have been created within the ribbon via Ribbon.RefreshInternal()
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                    Ribbon.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, false, DataSource);
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                    Ribbon.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, false, DataSource);

                // Remove anything else that is in the placeholder in case there is a temporary
                // animated gif or a static ribbon in there while the ribbon is loading.
                // We're doing this the slow way since partners might have a reference to this node
                Utility.RemoveChildNodesSlow(Placeholder);
                Placeholder.AppendChild(Ribbon.ElementInternal);
            }

            Ribbon.Scale();
            OnRootBuilt(Ribbon);
            BuildClient.OnComponentBuilt(Ribbon, Ribbon.Id);
            if (RibbonBuildOptions.LaunchedByKeyboard)
                Ribbon.SetFocusOnRibbon();

            PMetrics.PerfMark(PMarker.perfCUIRibbonInitPercvdEnd);
        }
Ejemplo n.º 2
0
        internal void BuildAndSetQAT(string qatId, bool attachToDOM, DataSource ds)
        {
            // Build QAT
            QATBuildOptions options = new QATBuildOptions();
            options.AttachToDOM = attachToDOM;
            options.TrimmedIds = RibbonBuilder.Options.TrimmedIds;
            QATBuilder builder = new QATBuilder(options,
                                                _elmQATPlaceholder,
                                                RibbonBuilder.BuildClient);
            builder.DataSource = ds;
            if (!builder.BuildQAT(qatId))
                throw new InvalidOperationException("QAT could not be built");

            QAT = builder.QAT;
            _elmTopBar1.Style.Display = "block";
        }
Ejemplo n.º 3
0
        internal void BuildAndSetJewel(string jewelId, bool attachToDOM, DataSource ds)
        {
            _elmJewelPlaceholder.Style.Display = "block";

            // Build Jewel
            JewelBuildOptions options = new JewelBuildOptions();
            options.AttachToDOM = attachToDOM;
            options.TrimmedIds = RibbonBuilder.Options.TrimmedIds;
            JewelBuilder builder = new JewelBuilder(options,
                                                    _elmJewelPlaceholder,
                                                    RibbonBuilder.BuildClient);
            builder.DataSource = ds;
            if (!builder.BuildJewel(jewelId))
                throw new InvalidOperationException("Jewel could not be built");

            Jewel = builder.Jewel;
        }
Ejemplo n.º 4
0
        private void RibbonInitFunc1()
        {
            RibbonBuildOptions rbOpts = new RibbonBuildOptions();
            rbOpts.LazyTabInit = true;
            rbOpts.ShallowTabs = true;
            rbOpts.LazyMenuInit = true;
            rbOpts.AttachToDOM = false;
            rbOpts.InitialScalingIndex = 0;
            rbOpts.ValidateServerRendering = false;

            rbOpts.ShowQATId = "";
            rbOpts.ShowJewelId = "";
            rbOpts.ShownContextualGroups = null;
            rbOpts.FixedPositioningEnabled = false;
            rbOpts.NormalizedContextualGroups = null;

            rbOpts.DataExtensions = null;
            rbOpts.TrimEmptyGroups = true;
            rbOpts.ScalingHint = "-1819788779";
            rbOpts.ClientID = "RibbonContainer";
            rbOpts.Minimized = _ribbon.GetField<bool>("buildMinimized");
            rbOpts.LaunchedByKeyboard = _ribbon.GetField<bool>("launchedByKeyboard");
            rbOpts.InitialTabSelectedByUser = _ribbon.GetField<bool>("initialTabSelectedByUser");

            rbOpts.ShownTabs = new Dictionary<string, bool>();
            rbOpts.ShownTabs.Add("Ribbon.Read", true);
            rbOpts.ShownTabs.Add("Ribbon.Library", true);
            rbOpts.ShownTabs.Add("Ribbon.Document", true);

            rbOpts.InitiallyVisibleContextualGroups = new Dictionary<string, bool>();
            rbOpts.InitiallyVisibleContextualGroups.Add("Ribbon.LibraryContextualGroup", true);

            rbOpts.TrimmedIds = new Dictionary<string, bool>();
            rbOpts.TrimmedIds.Add("Ribbon.List.GanttView", true);
            rbOpts.TrimmedIds.Add("Ribbon.List.Share.AlertMe", true);
            rbOpts.TrimmedIds.Add("Ribbon.Library.Share.AlertMe", true);
            rbOpts.TrimmedIds.Add("Ribbon.Documents.FormActions", true);
            rbOpts.TrimmedIds.Add("Ribbon.ListItem.Share.AlertMe", true);
            rbOpts.TrimmedIds.Add("Ribbon.Documents.Share.AlertMe", true);
            rbOpts.TrimmedIds.Add("Ribbon.List.Actions.AllMeetings", true);
            rbOpts.TrimmedIds.Add("Ribbon.WebPartPage.Share.AlertMe", true);
            rbOpts.TrimmedIds.Add("Ribbon.Library.Actions.AllMeetings", true);
            rbOpts.TrimmedIds.Add("Ribbon.Calendar.Events.Share.AlertMe", true);
            rbOpts.TrimmedIds.Add("Ribbon.Calendar.Calendar.Share.AlertMe", true);
            rbOpts.TrimmedIds.Add("Ribbon.ListItem.Actions.ChangeItemOrder", true);
            rbOpts.TrimmedIds.Add("Ribbon.WebPartInsert.InsertRelatedDataToListForm", true);

            // Get parent Ribbon Container and prepare to build
            HtmlElement ribbonCont = Browser.Document.GetById("RibbonContainer");
            RibbonBuilder builder = new RibbonBuilder(rbOpts, ribbonCont, PageManager.Instance);

            // Set the data source and build tab
            DataSource dataSource = new DataSource("\u002f_layouts\u002fcommandui.ashx", "-829476993", "1033");
            builder.DataSource = dataSource;
            builder.BuildRibbonAndInitialTab(_ribbon.GetField<string>("initialTabId"));

            PMetrics.PerfReport();
        }