Exemple #1
0
        //private JArray GetItemsJArray()
        //{
        //    JArray ja = new JArray();
        //    int itemIndex = 0;
        //    foreach (RadioItem item in Items)
        //    {
        //        JObject jo = new JObject();
        //        jo.Add("inputValue", item.Value);
        //        jo.Add("boxLabel", item.Text);
        //        jo.Add("name", UniqueID);
        //        if (item.Selected)
        //        {
        //            jo.Add("checked", true);
        //        }

        //        ja.Add(jo);

        //        itemIndex++;
        //    }

        //    return ja;
        //}

        #endregion

        #endregion

        #region DataBind

        /// <summary>
        /// 绑定到数据源
        /// </summary>
        public override void DataBind()
        {
            base.DataBind();

            if (_dataSource != null)
            {
                // 1. 首先清空 Items 属性
                Items.Clear();

                // 2. 绑定到数据源
                if (_dataSource is IDataReader)
                {
                    DataTable dataTable = new DataTable();
                    dataTable.Load(_dataSource as IDataReader);

                    DataBindToDataTable(dataTable);
                }
                else if (_dataSource is DataView || _dataSource is DataSet || _dataSource is DataTable)
                {
                    DataTable dataTable = null;
                    if (_dataSource is DataView)
                    {
                        dataTable = ((DataView)_dataSource).ToTable();
                    }
                    else if (_dataSource is DataSet)
                    {
                        dataTable = ((DataSet)_dataSource).Tables[0];
                    }
                    else
                    {
                        dataTable = ((DataTable)_dataSource);
                    }

                    DataBindToDataTable(dataTable);
                }
                else if (_dataSource is IEnumerable)
                {
                    DataBindToEnumerable((IEnumerable)_dataSource);
                }
                else
                {
                    throw new Exception("DataSource doesn't support data type: " + _dataSource.GetType().ToString());
                }

                // X_Items属性不是ServerAjaxProperty,所以只在页面第一次加载时判断是否改变
                if (!Page.IsPostBack)
                {
                    XState.AddModifiedProperty("X_Items");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 渲染 HTML 之前调用(页面第一次加载或者普通回发)
        /// </summary>
        protected override void OnFirstPreRender()
        {
            // 确保 X_Items 和 SelectedValue 在页面第一次加载时都存在于x_state中
            XState.AddModifiedProperty("X_Items");
            XState.AddModifiedProperty("SelectedValue");

            base.OnFirstPreRender();


            #region options

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


            OB.RemoveProperty("name");

            if (ColumnNumber <= 0)
            {
                OB.AddProperty("columns", "auto");
            }
            else
            {
                OB.AddProperty("columns", ColumnNumber);
            }

            if (ColumnVertical)
            {
                OB.AddProperty("vertical", true);
            }

            #endregion

            #region Items
            /*
            string xstateName = String.Format("{0}_xstate", XID);
            string xitemsName = String.Format("{0}_xitems", XID);
            string hasDataName = xstateName;

            string xstate = OB.GetProperty("x_state");
            OB.AddProperty("x_state", xstateName, true);

            string jsState = String.Format("var {0}={1};", xstateName, xstate);

            if (!XState.ModifiedProperties.Contains("X_Items"))
            {
                xstate = ConvertPropertiesToJObject(new List<string> { "X_Items", "SelectedValue" }).ToString(Formatting.None);
                jsState += String.Format("var {0}={1};", xitemsName, xstate);
                hasDataName = xitemsName;
            }

            
            OB.AddProperty("items", String.Format("X.util.resolveCheckBoxGroup('{0}',{1},true)", UniqueID, hasDataName), true);
            */

            OB.AddProperty("items", String.Format("X.util.resolveCheckBoxGroup('{0}',{1},true)", UniqueID, GetXStateScriptID()), true);


            if (Items.Count == 0)
            {
                OB.Listeners.AddProperty("afterrender", JsHelper.GetFunction("cmp.x_toBeDeleted();", "cmp"), true);
            }

            #endregion

            #region AutoPostBack

            if (AutoPostBack)
            {
                // This event will be triggered twice, so we must filter the actually change.
                // If the current checked radio is losing focus, this function will alse be called and the radio parameter is true.
                // 改变选中项时,这个事件会被触发两次。
                // 当前选中项失去焦点时,这个回调函数也会被触发并设置radio为true。
                OB.Listeners.AddProperty("change", String.Format("function(group,radio){{if(typeof(radio)!=='boolean'){{{0}}}}}", GetPostBackEventReference()), true);
            }

            //if (!String.IsNullOrEmpty(SelectedValue))
            //{
            //    OB.AddProperty("value", SelectedValue);
            //} 

            #region old code
            //string autoPostBackScript = String.Empty;
            //if (AutoPostBack)
            //{
            //    //// change 事件只有在失去焦点时才触发,是不及时的
            //    //OB.Listeners.RemoveProperty(OptionName.Change);
            //    //OB.Listeners.AddProperty(OptionName.Check, String.Format("function(newValue,oldValue){{\r\nbox_pageStateChange();alert(newValue+':'+oldValue);\r\n}}"), true);

            //    string selectScript = String.Format("function(newValue,oldValue){{\r\nalert(newValue+':'+oldValue);\r\n}}");
            //    selectScript = String.Format("{0}.on('{1}',{2},box,{{delay:0}});", ClientID, OptionName.Check, selectScript);

            //    autoPostBackScript += selectScript;
            //} 

            //string backgroundColorStyle = String.Empty;
            //if (EnableBackgroundColor)
            //{
            //    backgroundColorStyle = AboutConfig.GetDefaultBackgroundColor(PageManagerInstance.Theme.ToString());
            //}
            //else if (EnableLightBackgroundColor)
            //{
            //    backgroundColorStyle = AboutConfig.GetLightBackgroundColor(PageManagerInstance.Theme.ToString());
            //}

            //if (!String.IsNullOrEmpty(backgroundColorStyle))
            //{
            //    string backgroundColorScript = String.Format("Ext.each(X.{0}.el.query('.x-panel-body'),function(item,index){{Ext.get(item).setStyle('background-color','{1}');}});", ClientJavascriptID, backgroundColorStyle);

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

            #endregion

            #endregion

            string jsContent = String.Format("var {0}=new Ext.form.RadioGroup({1});", XID, OB.ToString());
            AddStartupScript(jsContent);
        }
Exemple #3
0
        /// <summary>
        /// 渲染 HTML 之前调用(页面第一次加载或者普通回发)
        /// </summary>
        protected override void OnFirstPreRender()
        {
            // 确保 X_Items 和 SelectedValue 在页面第一次加载时都存在于x_state中
            XState.AddModifiedProperty("X_Items");
            XState.AddModifiedProperty("SelectedValue");

            base.OnFirstPreRender();

            #region examples

            //var nextStepList = [
            //    ['审核', '1'],
            //    ['不审核', '2']
            //];
            //var nextStepStore = new Ext.data.SimpleStore({
            //    fields: ['text', 'value'],
            //    data: nextStepList
            //});
            //{
            //    xtype:'combo',
            //    store: nextStepStore,
            //    displayField:'text',
            //    valueField:'value',
            //    typeAhead: true,
            //    mode: 'local',
            //    triggerAction: 'all',
            //    value:'1',
            //    emptyText:'请选择下一步',
            //    selectOnFocus:true,
            //    allowBlank:false,
            //    fieldLabel: '下一步',
            //    labelSeparator:'&nbsp;<span style="color:red;vertical-align:text-bottom;">*</span>',
            //    name: 'nextStep',
            //    anchor:'95%'
            //}

            #endregion

            #region Properties

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

            if (!ForceSelection)
            {
                OB.AddProperty("forceSelection", false);
            }

            if (Resizable)
            {
                OB.AddProperty("resizable", true);
            }

            OB.AddProperty("hiddenName", UniqueID);
            //OB.RemoveProperty("name");
            OB.AddProperty("store", "new Ext.data.ArrayStore({fields:['value','text','enabled','prefix']})", true);

            OB.AddProperty("tpl", "X.util.ddlTPL", true);

            OB.AddProperty("mode", "local");
            OB.AddProperty("triggerAction", "all");
//            mode: "local",
//        triggerAction: "all",


            #region old code
            //OB.AddProperty("mode", "local");
            //// 点击下拉按钮时显示全部内容
            //OB.AddProperty("triggerAction", "all");
            //// 必须选中一个值,不能自己输入内容
            //OB.AddProperty("forceSelection", true);
            //// 此下拉列表控件不可以编辑
            //OB.AddProperty("editable", false);

            //OB.AddProperty(OptionName.Title, "Title");
            //if (TypeAhead) OB.AddProperty(OptionName.TypeAhead, true);
            //OB.AddProperty(OptionName.SelectOnFocus, true);

            //// SelectedValue可以为空
            //if (!String.IsNullOrEmpty(SelectedValue))
            //{
            //    OB.AddProperty("value", SelectedValue);
            //}
            #endregion

            #endregion

            #region old code

            //string hiddenFieldsScript = String.Empty;
            //if (AutoPostBack)
            //{
            //    hiddenFieldsScript += GetSetHiddenFieldValueScript(LastSelectedValueHiddenID, SelectedValue);
            //}

            //string disableSelectRowIndexsString = GetDisableSelectRowIndexsString();
            //string disableSelectRowIndexsScript = GetSetHiddenFieldValueScript(DisableRowIndexsHiddenID, disableSelectRowIndexsString);

            //// TODO:
            //// 这个要放在加载数据的前面,因为加载数据时需要渲染UI,渲染UI时需要用到这个隐藏字段的值
            //if (AjaxPropertyChanged("DisableSelectRowIndexsString", disableSelectRowIndexsString))
            //{
            //    AddAjaxPropertyChangedScript(disableSelectRowIndexsScript);
            //}


            // 不管是不是disableSelectFields.Count > 0,都要执行下面的语句,因为可能页面加载时为0,在Ajax后不为零
            //if (disableSelectFields.Count > 0)
            //OB.AddProperty(OptionName.Tpl, String.Format("'<tpl for=\".\"><div class=\"x-combo-list-item {{[X.util.isHiddenFieldContains(\"{0}\",xindex-1) ? \"box-combo-list-item-disable-select\" : \"\"]}}\">{{text}}</div></tpl>'", DisableSelectRowIndexsHiddenID), true);
            //var tplStr = "'<tpl for=\".\"><div class=\"x-combo-list-item\">{text}</div></tpl>'";
            //var tplStr = "new Ext.XTemplate('<tpl for=\".\"><div class=\"x-combo-list-item\">{text}</div></tpl>')";

            //var tplStr = "<tpl for=\".\"><div class=\"x-combo-list-item <tpl if=\"!enabled\">x-combo-list-item-disable</tpl>\">{prefix}{text}</div></tpl>";
            //OB.AddProperty("tpl", tplStr);
            //OB.AddProperty("tpl", tplStr.Replace("#DisableRowIndexsHiddenID#", DisableRowIndexsHiddenID), true);


            //string setSimulateTreeTextFunctionScript = String.Empty;
            //string setSimulateTreeTextScript = String.Empty;
            //if (EnableSimulateTree)
            //{
            //    string setSimulateTextScript = String.Format("var text=Ext.get('{0}').dom.value;if(text.lastIndexOf('<img')>=0){{Ext.get('{0}').dom.value=X.util.stripHtmlTags(text);}}", ClientID);
            //    setSimulateTreeTextFunctionScript = String.Format("{0}_setSimulateText=function(){{{1}}};", ClientJavascriptID, setSimulateTextScript);

            //    // 加载完毕后,显示选中的值
            //    //AddAbsoluteStartupScript(String.Format("{0}_setSimulateText();", ClientJavascriptID));
            //    // 下拉列表加载完毕后,立即去掉前面图片的HTML标签
            //    string renderScript = JsHelper.GetDeferScript(String.Format("{0}_setSimulateText();", ClientJavascriptID), 20); // "(function(){" + String.Format("{0}_setSimulateText();", ClientJavascriptID) + "}).defer(20);";
            //    OB.Listeners.AddProperty(OptionName.EVENT_RENDER, "function(component){" + renderScript + "}", true);
            //}


            //string simulateTreeAllScript = String.Empty;
            //if (EnableSimulateTree)
            //{
            //    // 在选中一项后,立即去掉前面图片的HTML标签
            //    simulateTreeAllScript += "\r\n";
            //    //string simulateTreeScript = String.Format("function(ddl,record,index){{var text=record.data.text;var startDivIndex=text.lastIndexOf('</div>');text=text.substr(startDivIndex+6);Ext.get('{0}').dom.value=text;}}", ClientID);
            //    string simulateTreeScript = String.Format("function(ddl,record,index){{X.{0}_setSimulateText();}}", ClientJavascriptID);
            //    simulateTreeScript = String.Format("{0}.on('{1}',{2},box,{{delay:0}});", ClientJavascriptID, OptionName.Select, simulateTreeScript);
            //    //AddAbsoluteStartupScript( simulateTreeScript);
            //    simulateTreeAllScript += simulateTreeScript;

            //    simulateTreeAllScript += "\r\n";
            //    string simulateTreeBlurScript = String.Format("function(ddl){{X.{0}_setSimulateText();}}", ClientJavascriptID);
            //    simulateTreeBlurScript = String.Format("{0}.on('{1}',{2},box,{{delay:10}});", ClientJavascriptID, OptionName.Blur, simulateTreeBlurScript);
            //    //AddAbsoluteStartupScript( simulateTreeBlurScript);
            //    simulateTreeAllScript += simulateTreeBlurScript;
            //}



            // These are default values, which are assignment in extender.js.
            //OB.AddProperty("displayField", "text");
            //OB.AddProperty("valueField", "value");
            //OB.AddProperty("store", "new Ext.data.ArrayStore({fields:['value','text','enabled','prefix']})", true);

            //string dataScript = String.Empty;
            //string fields = "['value','text','enabled','prefix']";
            //string storeScript = "new Ext.data.ArrayStore({fields:['value','text','enabled','prefix']})";//", fields, GetDataArrayString()); // GetDataArrayString()

            //OB.AddProperty(OptionName.Store, String.Format("new Ext.data.ArrayStore({{fields:['value','text'],data:{0}}})", dataArrayString), true);
            //OB.AddProperty("store", String.Format("{0}_data", XID), true);
            //string dataScript = String.Format("{0}_data=new Ext.data.ArrayStore({{fields:['value','text'],data:{1}}});", ClientJavascriptID, dataArrayString);
            //sb.AppendFormat("this.{0}_store=new Ext.data.SimpleStore({{fields:['text', 'value'],data:this.{0}_data}});", ClientJavascriptID);
            #endregion

            #region AutoPostBack

            StringBuilder beforeselectSB = new StringBuilder();
            // 是否能选中一项(如果此项不能选中,则点击没用)
            //beforeselectSB.AppendFormat("if(X.util.isHiddenFieldContains('{0}',index)){{return false;}}", DisableRowIndexsHiddenID);
            beforeselectSB.Append("if(!record.data.enabled){return false;}");

            if (AutoPostBack)
            {
                beforeselectSB.Append("cmp.x_tmp_lastvalue=cmp.getValue();");

                string selectScript = "if(cmp.x_tmp_lastvalue!==cmp.getValue()){" + GetPostBackEventReference() + "}";
                OB.Listeners.AddProperty("select", JsHelper.GetFunction(selectScript, "cmp"), true);
            }

            OB.Listeners.AddProperty("beforeselect", JsHelper.GetFunction(beforeselectSB.ToString(), "cmp", "record", "index"), true);

            #region old code
            //if (AutoPostBack)
            //{
            //    // Note: we can't use change event, because it get triggered when the combox lost focus, which is not in time.
            //    // Beforeselect - If current select item is not changed, don't PostBack.
            //    string beforeselectScript = String.Format("function(ddl,record,index){{Ext.get('{0}').dom.value=Ext.get('{1}').dom.value;}}", LastSelectedValueHiddenID, SelectedValueHiddenID);
            //    beforeselectScript = String.Format("{0}.on('{1}',{2},X,{{delay:0}});", XID, "beforeselect", beforeselectScript);
            //    //AddAbsoluteStartupScript( beforeselectScript);
            //    autoPostBackScript += beforeselectScript;

            //    // Select
            //    string selectScript = String.Format("function(ddl,record,index){{if(record.data.value!=Ext.get('{0}').dom.value){{{1}}}}}", LastSelectedValueHiddenID, GetPostBackEventReference());
            //    selectScript = String.Format("{0}.on('{1}',{2},X,{{delay:0}});", XID, "select", selectScript);
            //    //AddAbsoluteStartupScript( selectScript);
            //    autoPostBackScript += selectScript;


            //    //OB.Listeners.RemoveProperty(OptionName.Change);
            //    //OB.Listeners.AddProperty(OptionName.Change, String.Format("function(ddl,newValue,oldValue){{box_pageStateChange();alert(newValue+':'+oldValue);}}"), true);
            //}
            #endregion

            #endregion

            #region Listeners - render

            string renderScript = "cmp.x_loadData();cmp.x_setValue();";

            OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript, "cmp"), true);

            #endregion

            #region AddStartupScript

            string contentScript = String.Format("var {0}=new Ext.form.ComboBox({1});", XID, OB.ToString());

            AddStartupScript(contentScript);

            #region old code
            //List<string> totalModifiedProperties = XState.GetTotalModifiedProperties();
            //StringBuilder loadDataSB = new StringBuilder();
            //if (totalModifiedProperties.Contains("X_Items"))
            //{
            //    loadDataSB.AppendFormat("{0}.x_loadData();", XID);
            //}
            //else
            //{
            //    loadDataSB.AppendFormat("{0}.store.loadData({1});", XID, X_Items.ToString());
            //}

            //if (totalModifiedProperties.Contains("SelectedValue"))
            //{
            //    loadDataSB.AppendFormat("{0}.x_setValue();", XID);
            //}
            //else
            //{
            //    loadDataSB.AppendFormat("{0}.x_setValue({1});", XID, JsHelper.Enquote(SelectedValue));
            //}
            #endregion

            #endregion
        }