Example #1
0
        /// <summary>
        /// 获取添加选项卡的脚本
        /// </summary>
        /// <param name="tabID">选项卡ID</param>
        /// <param name="iframeUrl">IFrame地址</param>
        /// <param name="tabTitle">选项卡标题</param>
        /// <param name="iconUrl">选项卡图标</param>
        /// <param name="enableClose">是否可以关闭</param>
        /// <returns>客户端脚本</returns>
        public string GetAddTabReference(string tabID, string iframeUrl, string tabTitle, string iconUrl, bool enableClose)
        {
            if (!String.IsNullOrEmpty(iframeUrl))
            {
                iframeUrl = ResolveIFrameUrl(iframeUrl);
            }

            JsObjectBuilder options = new JsObjectBuilder();

            options.AddProperty("id", tabID);
            options.AddProperty("url", iframeUrl);
            options.AddProperty("title", tabTitle);
            options.AddProperty("closable", enableClose);

            string iconScript = String.Empty;

            if (!String.IsNullOrEmpty(iconUrl))
            {
                string className = String.Format("icon_{0}", System.Guid.NewGuid().ToString("N"));
                iconScript = String.Format("X.util.addCSS('{0}','{1}');", className, StyleUtil.GetNoRepeatBackgroundStyle("." + className, ResolveUrl(iconUrl)));

                options.AddProperty("iconCls", className);
            }

            return(iconScript + String.Format("{0}.addTab({1});", ScriptID, options));
        }
Example #2
0
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();

            #region options

            if (!ShowTrigger)
            {
                OB.AddProperty("hideTrigger", true);
            }


            if (!ShowTrigger1)
            {
                OB.AddProperty("hideTrigger1", true);
            }
            if (!ShowTrigger2)
            {
                OB.AddProperty("hideTrigger2", true);
            }

            if (!EnableEdit)
            {
                OB.AddProperty("editable", false);
            }

            #endregion

            #region Trigger1Icon/Trigger2Icon

            if (Trigger1Icon != TriggerIcon.None)
            {
                OB.AddProperty("trigger1Class", TriggerIconHelper.GetName(Trigger1Icon));
            }
            else if (!String.IsNullOrEmpty(Trigger1IconUrl))
            {
                string className = String.Format("extaspnet_{0}_twintriggerbox_icon1", XID);
                string selector  = String.Format(".x-form-field-wrap .x-form-twin-triggers .{0}", className);
                AddStartupCSS(className, StyleUtil.GetBackgroundStyle(selector, ResolveUrl(Trigger1IconUrl)));

                OB.AddProperty("trigger1Class", className);
            }


            if (Trigger2Icon != TriggerIcon.None)
            {
                OB.AddProperty("trigger2Class", TriggerIconHelper.GetName(Trigger2Icon));
            }
            else if (!String.IsNullOrEmpty(Trigger2IconUrl))
            {
                string className = String.Format("extaspnet_{0}_twintriggerbox_icon2", XID);
                string selector  = String.Format(".x-form-field-wrap .x-form-twin-triggers .{0}", className);
                AddStartupCSS(className, StyleUtil.GetBackgroundStyle(selector, ResolveUrl(Trigger2IconUrl)));

                OB.AddProperty("trigger2Class", className);
            }


            #endregion

            #region Trigger1Click/Trigger1Click

            if (Enabled)
            {
                string clientTrigger1ClickScript = OnClientTrigger1Click;
                if (!String.IsNullOrEmpty(clientTrigger1ClickScript) && !clientTrigger1ClickScript.EndsWith(";"))
                {
                    clientTrigger1ClickScript += ";";
                }
                string trigger1PostbackScript = String.Empty;
                if (EnableTrigger1PostBack)
                {
                    trigger1PostbackScript = GetPostBackEventReference("Trigger$1");
                }
                //string trigger1ClickScript = String.Format("function(){{{0}}}", clientTrigger1ClickScript + trigger1PostbackScript);
                //// createDelegate 用来为一个Function创建一个Scope
                //OB.AddProperty(OptionName.OnTrigger1Click, String.Format("({0}).createDelegate(box)", trigger1ClickScript), true);
                OB.AddProperty("onTrigger1Click", JsHelper.GetFunction(clientTrigger1ClickScript + trigger1PostbackScript), true);


                string clientTrigger2ClickScript = OnClientTrigger2Click;
                if (!String.IsNullOrEmpty(clientTrigger2ClickScript) && !clientTrigger2ClickScript.EndsWith(";"))
                {
                    clientTrigger2ClickScript += ";";
                }
                string trigger2PostbackScript = String.Empty;
                if (EnableTrigger2PostBack)
                {
                    trigger2PostbackScript = GetPostBackEventReference("Trigger$2");
                }
                //string trigger2ClickScript = String.Format("function(){{{0}}}", clientTrigger2ClickScript + Trigger2PostbackScript);
                //// createDelegate 用来为一个Function创建一个Scope
                //OB.AddProperty(OptionName.OnTrigger2Click, String.Format("({0}).createDelegate(box)", trigger2ClickScript), true);
                OB.AddProperty("onTrigger2Click", JsHelper.GetFunction(clientTrigger2ClickScript + trigger2PostbackScript), true);
            }

            #endregion

            #region Specialkey

            if (Enabled)
            {
                // 首先启用enableKeyEvents
                //OB.AddProperty("enableKeyEvents", true);
                OB.Listeners.AddProperty("specialkey", String.Format("function(field,e){{if(e.getKey()==e.ENTER){{{0}.onTrigger2Click();e.stopEvent();}}}}", XID), true);
            }

            #endregion

            #region old code

            //string renderScript = String.Empty;


            ////// 只禁用文本框,不禁用Trigger
            ////if (!EnableTextBox)
            ////{
            ////    //AddAbsoluteStartupScript(String.Format("{0}.el.dom.disabled=true;", ClientJavascriptID));
            ////    renderScript += String.Format("{0}.el.dom.disabled=true;", ClientJavascriptID);
            ////}


            //if (AjaxPropertyChanged("ShowTrigger1", ShowTrigger1))
            //{
            //    AddAjaxPropertyChangedScript(String.Format("{0}.getTrigger(0).{1}();", XID, ShowTrigger1 ? "show" : "hide"));
            //}

            //if (AjaxPropertyChanged("ShowTrigger2", ShowTrigger2))
            //{
            //    AddAjaxPropertyChangedScript(String.Format("{0}.getTrigger(1).{1}();", XID, ShowTrigger2 ? "show" : "hide"));
            //}


            //renderScript = "(function(){" + renderScript + "}).defer(20);";
            //OB.Listeners.AddProperty("render", "function(component){" + renderScript + "}", true);

            #endregion

            string jsContent = String.Format("var {0}=new Ext.form.TwinTriggerField({1});", XID, OB.ToString());
            AddStartupScript(jsContent);
        }
Example #3
0
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();



            #region options
            if (!ShowTrigger)
            {
                OB.AddProperty("hideTrigger", true);
            }

            if (!EnableEdit)
            {
                OB.AddProperty("editable", false);
            }



            #endregion

            #region TriggerIcon

            if (TriggerIcon != TriggerIcon.None)
            {
                OB.AddProperty("triggerClass", TriggerIconHelper.GetName(TriggerIcon));
            }
            else if (!String.IsNullOrEmpty(TriggerIconUrl))
            {
                string className = String.Format("extaspnet_{0}_triggerbox_icon", XID);
                string selector  = String.Format(".x-form-field-wrap .{0}", className);
                AddStartupCSS(className, StyleUtil.GetBackgroundStyle(selector, ResolveUrl(TriggerIconUrl)));

                OB.AddProperty("triggerClass", className);
            }


            #endregion

            #region TriggerClick

            if (Enabled)
            {
                string clientClickScript = OnClientTriggerClick;
                if (!String.IsNullOrEmpty(clientClickScript) && !clientClickScript.EndsWith(";"))
                {
                    clientClickScript += ";";
                }

                string postbackScript = String.Empty;
                if (EnablePostBack)
                {
                    postbackScript = GetPostBackEventReference();
                }

                OB.AddProperty("onTriggerClick", JsHelper.GetFunction(clientClickScript + postbackScript), true);
            }

            #endregion

            #region Specialkey

            if (Enabled)
            {
                // 首先启用enableKeyEvents
                //OB.AddProperty("enableKeyEvents", true);
                OB.Listeners.AddProperty("specialkey", String.Format("function(field,e){{if(e.getKey()==e.ENTER){{{0}.onTriggerClick();e.stopEvent();}}}}", XID), true);

                //OB.Listeners.AddProperty("keydown", JsHelper.GetFunction("var i=0;"), true);
            }

            #endregion

            #region old code

            //// 只禁用文本框,不禁用Trigger
            //if (Readonly)
            //{
            //    //OB.AddProperty(OptionName.Disabled, true);
            //    //AddAbsoluteStartupScript( String.Format("{0}.el.dom.disabled=true;", ClientID));



            //    //OB.Listeners.AddProperty(OptionName.Focus, String.Format("function(field){{field.blur.defer(10,field);\r\n}}"), true);
            //    //OB.Listeners.AddProperty(OptionName.Keydown, String.Format("function(){{return false;}}"), true);


            //    // 晕,最后的解决方案居然是设置 readonly=true
            //    OB.AddProperty(OptionName.ReadOnly, true);

            //    //string cssClassName = CssClass;
            //    //cssClassName += "x-item-disabled";

            //    //OB.RemoveProperty(OptionName.Cls);
            //    //OB.AddProperty(OptionName.Cls, cssClassName);
            //    //OB.AddProperty(OptionName.FocusClass, "");
            //}

            #endregion

            string jsContent = String.Format("var {0}=new Ext.form.TriggerField({1});", XID, OB.ToString());
            AddStartupScript(jsContent);
        }
Example #4
0
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();

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

            #region Items

            if (!RenderChildrenAsContent)
            {
                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

            foreach (Toolbar bar in Toolbars)
            {
                string toolbarID = String.Format("{0}", bar.XID);

                if (bar.Position == ToolbarPosition.Top)
                {
                    OB.AddProperty("tbar", toolbarID, true);
                }
                else if (bar.Position == ToolbarPosition.Bottom)
                {
                    OB.AddProperty("bbar", toolbarID, true);
                }
            }

            #endregion

            #region BodyStyle/ShowBorder

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

            if (EnableBackgroundColor)
            {
                if (!bodyStyleStr.Contains("background-color"))
                {
                    string backgroundColorStyleStr = GlobalConfig.GetDefaultBackgroundColor();
                    if (!String.IsNullOrEmpty(backgroundColorStyleStr))
                    {
                        bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr);
                    }
                }
            }
            //else if (EnableLightBackgroundColor)
            //{
            //    if (!bodyStyleStr.Contains("background-color"))
            //    {
            //        string backgroundColorStyleStr = GlobalConfig.GetLightBackgroundColor(PageManager.Instance.Theme.ToString());
            //        bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr);
            //    }
            //}
            OB.AddProperty("bodyStyle", bodyStyleStr);

            OB.AddProperty("border", ShowBorder);


            #endregion

            #region IconUrl

            if (!String.IsNullOrEmpty(IconUrl))
            {
                // Window控件的特殊处理在Window控件中
                // 添加CSS样式
                string className = String.Format("extaspnet_{0}_panelbase_icon", XID);
                AddStartupCSS(className, StyleUtil.GetNoRepeatBackgroundStyle("." + className, ResolveUrl(IconUrl)));

                OB.AddProperty("iconCls", className);

                //// 下面这种方式不行,这个样式是要添加到Head中的,而不是最外层的DIV
                //AddExtraStyle("background", StyleUtil.GetNoRepeatBackgroundStyleValue(ResolveUrl(IconUrl)));
            }

            #endregion

            #region Width/Height

            // 对于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("x_iframe", true);
                OB.AddProperty("x_iframe_url", IFrameUrl);
                OB.AddProperty("x_iframe_name", IFrameName);

                // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中
                if (!String.IsNullOrEmpty(IFrameUrl))
                {
                    //_writeIframeToHtmlDocument = true;
                    OB.AddProperty("x_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("x_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 EnableLargeHeader

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

            #endregion

            #region remove fx

            // 关闭折叠时特效
            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", "function(component){" + 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
        }