Exemplo n.º 1
0
        /// <summary>
        /// 渲染 HTML 之前调用(页面第一次加载或者普通回发)
        /// </summary>
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();

            if (EnableFrame)
            {
                OB.AddProperty("frame", true);
            }


            #region Items

            // 如果是 ContentPanel, 启用 IFrame 或者包含 Content, 则不生成 items
            if (RenderChildrenAsContent || EnableIFrame || (Content != null))
            {
                if (RenderChildrenAsContent || (Content != null))
                {
                    OB.AddProperty("contentEl", String.Format("{0}", ContentID));
                }
            }
            else
            {
                if (Items.Count > 0)
                {
                    JsArrayBuilder ab = new JsArrayBuilder();
                    foreach (ControlBase item in Items)
                    {
                        if (item.Visible)
                        {
                            ab.AddProperty(String.Format("{0}", item.XID), true);
                        }
                    }

                    OB.AddProperty("items", ab.ToString(), true);
                }
            }

            #endregion

            #region Toolbars

            //JsArrayBuilder dockItems = new JsArrayBuilder();
            //foreach (Toolbar bar in Toolbars)
            //{
            //    dockItems.AddProperty(bar.XID, true);
            //}

            //if (this is Grid)
            //{
            //    Grid grid = this as Grid;
            //    if (grid.AllowPaging)
            //    {
            //        dockItems.AddProperty(grid.Render_PagingID, true);
            //    }
            //}

            Dictionary <string, JsArrayBuilder> bars = new Dictionary <string, JsArrayBuilder>();
            foreach (Toolbar bar in Toolbars)
            {
                string barPosition = ToolbarPositionHelper.GetExtName(bar.Position);

                if (!bars.ContainsKey(barPosition))
                {
                    bars[barPosition] = new JsArrayBuilder();
                }
                bars[barPosition].AddProperty(bar.XID, true);
            }

            // 将底部工具栏的顺序反转
            if (bars.ContainsKey("bottom"))
            {
                bars["bottom"].Reverse();
            }
            // 表格的分页工具栏
            if (this is Grid)
            {
                Grid grid = this as Grid;
                if (grid.AllowPaging)
                {
                    if (!bars.ContainsKey("bottom"))
                    {
                        bars["bottom"] = new JsArrayBuilder();
                    }

                    bars["bottom"].AddProperty(grid.Render_PagingID, true);
                }
            }


            JsArrayBuilder dockItems = new JsArrayBuilder();
            foreach (string barPosition in bars.Keys)
            {
                foreach (string barItem in bars[barPosition].Properties)
                {
                    dockItems.AddProperty(barItem, true);
                }
            }
            OB.AddProperty("dockedItems", dockItems);


            #endregion

            #region BodyStyle/ShowBorder

            string bodyStyleStr = BodyStyle;
            if (!bodyStyleStr.Contains("padding"))
            {
                if (!String.IsNullOrEmpty(BodyPadding))
                {
                    bodyStyleStr += String.Format("padding:{0};", StyleUtil.GetMarginPaddingStyle(BodyPadding));
                }
            }

            //if (EnableBackgroundColor)
            //{
            //    if (!bodyStyleStr.Contains("background-color"))
            //    {
            //        string backgroundColorStyleStr = GlobalConfig.GetDefaultBackgroundColor();
            //        if (!String.IsNullOrEmpty(backgroundColorStyleStr))
            //        {
            //            bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr);
            //        }
            //    }
            //}

            OB.AddProperty("bodyStyle", bodyStyleStr);

            OB.AddProperty("border", ShowBorder);


            #endregion

            #region MinHeight/MinHeight

            if (MinHeight != Unit.Empty)
            {
                OB.AddProperty("minHeight", MinHeight.Value);
            }
            if (MinWidth != Unit.Empty)
            {
                OB.AddProperty("minWidth", MinWidth.Value);
            }
            if (MaxHeight != Unit.Empty)
            {
                OB.AddProperty("maxHeight", MaxHeight.Value);
            }
            if (MaxWidth != Unit.Empty)
            {
                OB.AddProperty("maxWidth", MaxWidth.Value);
            }


            //// 对于Panel,如果宽度/高度没有定义
            //if (Width == Unit.Empty && AutoWidth)
            //{
            //    OB.AddProperty("autoWidth", true);
            //}

            //if (Height == Unit.Empty && AutoHeight)
            //{
            //    OB.AddProperty("autoHeight", true);
            //}


            //// 如果父控件是容器控件(不是ContentPanel),并且Layout != LayoutType.Container,
            //// 则设置AutoWidth/AutoHeight都为false
            //if (Parent is PanelBase)
            //{
            //    PanelBase parent = Parent as PanelBase;
            //    if (!(parent is ContentPanel) && parent.Layout != Layout.Container)
            //    {
            //        OB.RemoveProperty("autoHeight");
            //        OB.RemoveProperty("autoWidth");
            //    }
            //}



            if (AutoScroll)
            {
                OB.AddProperty("autoScroll", true);
            }


            #region old code
            //// 如果是 PageLayout 中的Panel,不能设置AutoWidth
            //if (Parent is PageLayout)
            //{
            //    // region
            //    if (Region != Region_Default) OB.AddProperty(OptionName.Region, RegionTypeName.GetName(Region.Value));
            //}
            //else
            //{
            //    // 对于Panel,如果宽度/高度没有定义,则使用自动宽度和高度
            //    if (Width == Unit.Empty)
            //    {
            //        OB.AddProperty(OptionName.AutoWidth, true);
            //    }

            //    if (Height == Unit.Empty)
            //    {
            //        OB.AddProperty(OptionName.AutoHeight, true);
            //    }

            //}

            //// 如果父控件是容器控件,并且Layout=Fit,则设置AutoWidth/AutoHeight都为false
            //if (Parent is PanelBase)
            //{
            //    PanelBase parentPanel = Parent as PanelBase;
            //    if (parentPanel.Layout == LayoutType.Fit
            //        || parentPanel.Layout == LayoutType.Anchor
            //        || parentPanel.Layout == LayoutType.Border)
            //    {
            //        OB.RemoveProperty(OptionName.AutoHeight);
            //        OB.RemoveProperty(OptionName.AutoWidth);
            //    }

            //}

            #endregion

            #endregion

            #region EnableIFrame

            if (EnableIFrame)
            {
                #region old code

                //string iframeJsContent = String.Empty;

                //string frameUrl = ResolveUrl(IFrameUrl);
                //JsObjectBuilder iframeBuilder = new JsObjectBuilder();
                //if (IFrameDelayLoad)
                //{
                //    iframeBuilder.AddProperty(OptionName.Src, "#");
                //}
                //else
                //{
                //    iframeBuilder.AddProperty(OptionName.Src, frameUrl);
                //}
                //iframeBuilder.AddProperty(OptionName.LoadMask, false);
                //iframeJsContent += String.Format("var {0}=new Ext.ux.ManagedIFrame('{0}',{1});", IFrameID, iframeBuilder.ToString());

                //if (IFrameDelayLoad)
                //{
                //    iframeJsContent += String.Format("{0}_url='{1}';", IFrameID, frameUrl);
                //}

                //iframeJsContent += "\r\n";

                //AddStartupScript(this, iframeJsContent);

                #endregion

                // 注意:
                // 如下依附于现有对象的属性名称的定义规则:x_property1
                // 存储于当前对象实例中
                OB.AddProperty("f_iframe", true);
                OB.AddProperty("f_iframe_url", IFrameUrl);
                OB.AddProperty("f_iframe_name", IFrameName);

                // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中
                if (!String.IsNullOrEmpty(IFrameUrl))
                {
                    //_writeIframeToHtmlDocument = true;
                    OB.AddProperty("f_iframe_loaded", true);
                    // 直接添加iframe属性
                    OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName));
                }
                else
                {
                    //_writeIframeToHtmlDocument = false;
                    OB.AddProperty("f_iframe_loaded", false);
                }

                #region old code

                //// If current panel is Tab, then process the IFrameDelayLoad property.
                //Tab tab = this as Tab;
                //if (tab != null && tab.IFrameDelayLoad)
                //{
                //    // 如果是Tab,并且此Tab不是激活的,则不添加iframe
                //    //_writeIframeToHtmlDocument = false;
                //    OB.AddProperty("box_property_iframe_loaded", false);
                //}
                //else
                //{
                //    // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中
                //    if (!String.IsNullOrEmpty(IFrameUrl))
                //    {
                //        //_writeIframeToHtmlDocument = true;
                //        OB.AddProperty("box_property_iframe_loaded", true);
                //        // 直接添加iframe属性
                //        OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName));
                //    }
                //    else
                //    {
                //        //_writeIframeToHtmlDocument = false;
                //        OB.AddProperty("box_property_iframe_loaded", false);
                //    }
                //}

                #endregion
            }

            #endregion

            #region RoundBorder

            //if (RoundBorder) OB.AddProperty(OptionName.Frame, true);

            #endregion

            #region oldcode

            //if (EnableLargeHeader)
            //{
            //    OB.AddProperty("cls", "f-panel-big-header");
            //}


            //OB.AddProperty("animCollapse", false);

            #endregion

            #region ContentEl

            //string finallyScript = String.Empty;

            if (RenderChildrenAsContent)
            {
                OB.AddProperty("contentEl", ContentID);

                // 在页面元素渲染完成后,才显示容器控件的内容
                //string renderScript = String.Format("Ext.get('{0}').show();", ContentID);
                //OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript), true);

                //string beforerenderScript = String.Format("Ext.get('{0}').setStyle('display','');", ChildrenContentID);
                //OB.Listeners.AddProperty("beforerender", "function(component){" + beforerenderScript + "}", true);


                // 这一段的逻辑(2008-9-1):
                // 如果是页面第一次加载 + 此Panel在Tab中 + 此Tab不是当前激活Tab + 此Tab的TabStrip启用了延迟加载
                // 那么在页面加载完毕后,把此Panel给隐藏掉,等此Panel渲染到页面中时再显示出来

                //Tab tab = ControlUtil.FindParentControl(this, typeof(Tab)) as Tab;
                //if (tab != null)
                //{
                //    TabStrip tabStrip = tab.Parent as TabStrip;
                //    if (tabStrip.EnableDeferredRender && tabStrip.Tabs[tabStrip.ActiveTabIndex] != tab)
                //    {
                //        // 页面第一次加载时,在显示(控件的render事件)之前要先隐藏
                //        AddStartupAbsoluteScript(String.Format("Ext.get('{0}').setStyle('display','none');", ContentID));
                //    }
                //}
            }

            #endregion
        }
Exemplo n.º 2
0
        /// <summary>
        /// 渲染 HTML 之前调用(页面第一次加载或者普通回发)
        /// </summary>
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();

            //ResourceManager.Instance.AddJavaScriptComponent("toolbar");

            #region Items

            // 重新设置Items
            if (Controls.Count > 0)
            {
                JsArrayBuilder ab = new JsArrayBuilder();
                foreach (Control item in Controls)
                {
                    if (item is ControlBase && item.Visible)
                    {
                        #region old code

                        //// 如果是分隔符
                        //if (item is ToolbarSeparator)
                        //{
                        //    ab.AddProperty("'-'", true);
                        //}
                        //else if (item is ToolbarText)
                        //{
                        //    ab.AddProperty(String.Format("'{0}'", (item as ToolbarText).Text), true);
                        //}
                        //if (item is ToolbarFill)
                        //{
                        //    ab.AddProperty("'->'", true);
                        //}
                        //else
                        //{
                        //ab.AddProperty(String.Format("{0}", (item as ControlBase).ClientJavascriptID), true);
                        //}

                        #endregion

                        ab.AddProperty(String.Format("{0}", (item as ControlBase).XID), true);
                    }
                }

                if (ab.Count > 0)
                {
                    OB.AddProperty("items", ab.ToString(), true);
                }
            }


            #endregion


            JsObjectBuilder layoutOB = new JsObjectBuilder();
            layoutOB.AddProperty("pack", ToolbarAlignHelper.GetName(ToolbarAlign));

            OB.AddProperty("layout", layoutOB, true);

            OB.AddProperty("xtype", "toolbar");

            OB.AddProperty("dock", ToolbarPositionHelper.GetExtName(Position));

            //string jsContent = String.Format("var {0}=Ext.create('Ext.toolbar.Toolbar',{1});", XID, OB.ToString());

            //string jsContent = String.Format("var {0}={1};", XID, OB.GetProperty("items"));
            string jsContent = String.Format("var {0}={1};", XID, OB.ToString());

            AddStartupScript(jsContent);
        }