Пример #1
0
        /// <summary>
        /// Builds the toolbar and attaches it to the page.
        /// Called once the DataQuery completes and the toolbar data is available.
        /// </summary>
        private void OnReturnToolbarData(DataQueryResult res)
        {
            ToolbarBuildContext context = (ToolbarBuildContext)res.ContextData;

            // Apply any extensions to the data.
            res.QueryData = ApplyDataExtensions(res.QueryData);

            Toolbar = BuildToolbarFromData(res.QueryData, context);
            Toolbar.ToolbarBuilder = this;
            BuildClient.OnComponentCreated(Toolbar, Toolbar.Id);
            Toolbar.RefreshInternal();

            Placeholder.AppendChild(Toolbar.ElementInternal);

            // If there's a jewel on the toolbar, position the left buttondock adjacent to it
            foreach (ButtonDock dock in Toolbar.Children)
            {
                if (dock.Alignment == DataNodeWrapper.LEFTALIGN)
                {
                    Div jewelContainer = (Div)Browser.Document.GetById("jewelcontainer");
                    if (!CUIUtility.IsNullOrUndefined(jewelContainer))
                    {
                        if (Toolbar.TextDirection == Direction.LTR)
                        {
                            dock.ElementInternal.Style.Left = jewelContainer.OffsetWidth + "px";
                        }
                        else
                        {
                            dock.ElementInternal.Style.Right = jewelContainer.OffsetWidth + "px";
                        }
                    }
                    break;
                }
            }

            Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            BuildClient.OnComponentBuilt(Toolbar, Toolbar.Id);
        }
Пример #2
0
        /// <summary>
        /// Constructs a toolbar from its JSON data.
        /// </summary>
        private Toolbar BuildToolbarFromData(object data, ToolbarBuildContext context)
        {
            JSObject toolbarElement = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.TOOLBAR);

            if (CUIUtility.IsNullOrUndefined(toolbarElement))
                throw new ArgumentNullException("No toolbar element was present in the data");

            bool hasJewel = !CUIUtility.IsNullOrUndefined(DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.JEWEL));

            Toolbar = new Toolbar(
                DataNodeWrapper.GetAttribute(toolbarElement, DataNodeWrapper.ID),
                DataNodeWrapper.GetNodeAttributes(toolbarElement).To<ToolbarProperties>(),
                this,
                hasJewel);

            Toolbar.ClientID = Options.ClientID;
            Toolbar.UseDataCookie = true;

            Toolbar.RefreshInternal(); // We need to refresh before we can attach the jewel.

            if (hasJewel)
            {
                Toolbar.AttachAndBuildJewelFromData(data);
            }

            // Build the ButtonDocks (the Docks will build their subcontrols).
            JSObject docks = DataNodeWrapper.GetFirstChildNodeWithName(toolbarElement, DataNodeWrapper.BUTTONDOCKS);
            JSObject[] dockChildren = DataNodeWrapper.GetNodeChildren(docks);

            for (int i = 0; i < dockChildren.Length; i++)
            {
                ButtonDock dock = BuildButtonDock(dockChildren[i], context);
                Toolbar.AddChild(dock);
            }

            return Toolbar;
        }