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

            //ResourceManager.Instance.AddJavaScriptComponent("button");
            //if (Menu.Items.Count > 0)
            //{
            //    ResourceManager.Instance.AddJavaScriptComponent("menu");
            //}

            #region Properties
            if (TabIndex != null)
            {
                OB.AddProperty("tabIndex", TabIndex);
            }

            if (!String.IsNullOrEmpty(ToolTip))
            {
                OB.AddProperty("tooltip", ToolTip);
                OB.AddProperty("tooltipType", ToolTipTypeName.GetName(ToolTipType));
            }

            OB.AddProperty("text", Text);

            if (EnablePress)
            {
                OB.AddProperty("enableToggle", EnablePress);
                OB.AddProperty("pressed", Pressed);

                //hiddenFieldsScript += GetSetHiddenFieldValueScript(PressedHiddenFieldID, Pressed.ToString().ToLower());
                //string toggleScript = String.Format("function(btn,pressed){{F.util.setHiddenFieldValue('{0}',pressed);}}", PressedHiddenFieldID);
                //OB.Listeners.AddProperty(OptionName.Toggle, toggleScript, true);
            }

            //if (Type != ButtonType.Button)
            //{
            //    OB.AddProperty("type", ButtonTypeName.GetName(Type));
            //}



            if (Size != ButtonSize.Small)
            {
                OB.AddProperty("scale", ButtonSizeName.GetName(Size));
            }

            #endregion

            #region Icon IconUrl

            string resolvedIconUrl = IconHelper.GetResolvedIconUrl(Icon, IconUrl);
            if (!String.IsNullOrEmpty(resolvedIconUrl))
            {
                // 不需要先删除原来的属性,因为在AddProperty内部已经有这个逻辑了
                OB.AddProperty("cls", CssClass + " x-btn-text-icon");
                OB.AddProperty("icon", resolvedIconUrl);

                if (IconAlign != IconAlign.Left)
                {
                    OB.AddProperty("iconAlign", IconAlignHelper.GetName(IconAlign));
                }
            }

            #endregion

            #region Click

            string clickScript = GetClickScript();
            if (!String.IsNullOrEmpty(clickScript))
            {
                OB.AddProperty("handler", JsHelper.GetFunction(clickScript), true);
            }

            #endregion

            #region oldcode

            //string clickScriptFunction = GetClickScriptFunction();
            //if (AjaxPropertyChanged("ClickScriptFunction", clickScriptFunction))
            //{
            //    string ajaxClickFunction = String.Empty;
            //    //ajaxClickFunction += String.Format("{0}.purgeListeners('click');", ClientJavascriptID);
            //    ajaxClickFunction += String.Format("{0}.un('click', X.{0}.initialConfig.listeners.click);", XID);
            //    ajaxClickFunction += String.Format("{0}.on('click',{1});", XID, clickScriptFunction);

            //    AddAjaxPropertyChangedScript(ajaxClickFunction);
            //}

            //OB.Listeners.AddProperty(OptionName.Click, String.Format("{0}_click", ClientJavascriptID), true);


            //OB.AddProperty(OptionName.Handler, "function(){alert('sss');}", true);



            //string style = String.Empty;

            //if (CssStyle == "" || !CssStyle.ToLower().Contains("display"))
            //{
            //    style += CssStyle + "display:inline;";
            //}

            //OB.RemoveProperty(OptionName.Style);
            //OB.AddProperty(OptionName.Style, style);

            //AddExtraStyle("display", "inline");

            #endregion

            #region Menu

            if (_menu != null && Menu.Items.Count > 0)
            {
                OB.AddProperty("menu", Menu.XID, true);
            }
            else if (!String.IsNullOrEmpty(MenuID))
            {
                Menu contextMenu = ControlUtil.FindControlInUserControlOrPage(this, MenuID) as Menu;
                if (contextMenu != null)
                {
                    OB.AddProperty("menu", contextMenu.XID, true);
                }
            }


            #endregion

            #region Type

            string submitButtonScript = String.Empty;
            if (Type == ButtonType.Submit)
            {
                submitButtonScript = String.Format("F.submitbutton='{0}';", ClientID);
            }
            else if (Type == ButtonType.Reset)
            {
                OB.AddProperty("handler", JsHelper.GetFunction("F.util.reset();"), true);
            }

            #endregion

            string createScript = String.Format("var {0}=Ext.create('Ext.button.Button',{1});", XID, OB.ToString());
            AddStartupScript(submitButtonScript + createScript);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 渲染 HTML 之前调用(页面第一次加载或者普通回发)
        /// </summary>
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();


            #region validate properties

            if (Required)
            {
                OB.AddProperty("allowBlank", false);
                if (!String.IsNullOrEmpty(RequiredMessage))
                {
                    OB.AddProperty("blankText", RequiredMessage);
                }
            }

            if (MaxLength != null)
            {
                OB.AddProperty("maxLength", MaxLength.Value);
                if (!String.IsNullOrEmpty(MaxLengthMessage))
                {
                    OB.AddProperty("maxLengthText", MaxLengthMessage);
                }
            }
            if (MinLength != null)
            {
                OB.AddProperty("minLength", MinLength.Value);
                if (!String.IsNullOrEmpty(MinLengthMessage))
                {
                    OB.AddProperty("minLengthText", MinLengthMessage);
                }
            }

            // Calculate regex expression via RegexPattern and Regex
            string regexStr = String.Empty;
            if (RegexPattern != RegexPattern.None)
            {
                regexStr = RegexPatternHelper.GetRegexValue(RegexPattern);
            }
            else if (!String.IsNullOrEmpty(Regex))
            {
                regexStr = Regex;
            }

            if (!String.IsNullOrEmpty(regexStr))
            {
                string ignoreCaseStr = String.Empty;
                if (RegexIgnoreCase)
                {
                    ignoreCaseStr = ",'i'";
                }

                OB.AddProperty("regex", String.Format("new RegExp({0}{1})", JsHelper.Enquote(regexStr), ignoreCaseStr), true);
                if (!String.IsNullOrEmpty(RegexMessage))
                {
                    OB.AddProperty("regexText", RegexMessage);
                }
            }

            #endregion

            //OB.AddProperty("enableKeyEvents", true);

            #region NextFocusControl

            if (!String.IsNullOrEmpty(NextFocusControl))
            {
                ControlBase nextControl = ControlUtil.FindControlInUserControlOrPage(this, NextFocusControl) as ControlBase;

                if (nextControl != null)
                {
                    //// true to enable the proxying of key events for the HTML input field (defaults to false)
                    //OB.AddProperty("enableKeyEvents", true);
                    // Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed.
                    //OB.Listeners.AddProperty("specialkey", String.Format("function(field,e){{if(e.getKey()==e.ENTER){{{0}.focus(true,10);e.stopEvent();}}}}", (nextControl as ControlBase).XID), true);

                    string enterScript = String.Empty;

                    if (nextControl is Button)
                    {
                        enterScript = String.Format("{0}.el.dom.click();", nextControl.XID);
                    }
                    else
                    {
                        enterScript = String.Format("{0}.focus(true,10);", nextControl.XID);
                    }

                    AddListener("specialkey", String.Format("if(e.getKey()==e.ENTER){{{0}e.stopEvent();}}", enterScript), "field", "e");
                }
            }

            #endregion

            #region ControlToCompare

            string compareValue = String.Empty;
            // 如果CompareControl 和 CompareValue 同时存在,则 CompareControl 拥有更高的优先级
            if (!String.IsNullOrEmpty(CompareControl))
            {
                Control compareControl = ControlUtil.FindControlInUserControlOrPage(this, CompareControl);
                if (compareControl != null && compareControl is ControlBase)
                {
                    compareValue = String.Format("F.fieldValue({0})", JsHelper.Enquote((compareControl as ControlBase).ClientID));
                }
            }
            else if (!String.IsNullOrEmpty(CompareValue))
            {
                compareValue = CompareValue;
                if (CompareType == CompareType.String)
                {
                    compareValue = JsHelper.Enquote(compareValue);
                }
            }

            // Check whether compareValue exist, which may produced from CompareControl or CompareValue.
            if (!String.IsNullOrEmpty(compareValue))
            {
                string compareOperatorJs       = OperatorHelper.GetName(CompareOperator);
                string compareExpressionScript = String.Empty;
                if (CompareType == CompareType.String)
                {
                    compareExpressionScript = String.Format("value{0}{1}", compareOperatorJs, compareValue);
                }
                else if (CompareType == CompareType.Int)
                {
                    compareExpressionScript = String.Format("parseInt(value,10){0}parseInt({1},10)", compareOperatorJs, compareValue);
                }
                else if (CompareType == CompareType.Float)
                {
                    compareExpressionScript = String.Format("parseFloat(value){0}parseFloat({1})", compareOperatorJs, compareValue);
                }

                string compareScript = String.Format("if({0}){{return true;}}else{{return {1};}}", compareExpressionScript, JsHelper.Enquote(CompareMessage));
                OB.AddProperty("validator", String.Format("function(){{var value=F.fieldValue(this);{0}}}", compareScript), true);
            }

            #endregion
        }