示例#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));
        }
示例#2
0
文件: Confirm.cs 项目: xlfj5211/esb
        /// <summary>
        /// 获取显示确认对话框的客户端脚本
        /// </summary>
        /// <param name="message">对话框消息</param>
        /// <param name="title">对话框标题</param>
        /// <param name="icon">对话框图标</param>
        /// <param name="okScriptstring">点击确定按钮执行的客户端脚本</param>
        /// <param name="cancelScript">点击取消按钮执行的客户端脚本</param>
        /// <param name="target">弹出对话框的目标页面</param>
        /// <returns>客户端脚本</returns>
        public static string GetShowReference(string message, string title, MessageBoxIcon icon, string okScriptstring, string cancelScript, Target target)
        {
            //string msgBoxScript = "var msgBox=Ext.MessageBox;";
            //msgBoxScript += "if(parent!=window){msgBox=parent.window.Ext.MessageBox;}";
            if (String.IsNullOrEmpty(title))
            {
                title = "X.util.confirmTitle";
            }
            else
            {
                title = JsHelper.GetJsString(title.Replace("\r\n", "\n").Replace("\n", "<br/>"));
            }
            message = message.Replace("\r\n", "\n").Replace("\n", "<br/>");


            JsObjectBuilder ob = new JsObjectBuilder();

            ob.AddProperty("title", title, true);
            ob.AddProperty("msg", JsHelper.GetJsStringWithScriptTag(message), true);
            ob.AddProperty("buttons", "Ext.MessageBox.OKCANCEL", true);
            ob.AddProperty("icon", String.Format("{0}", MessageBoxIconHelper.GetName(icon)), true);
            ob.AddProperty("fn", String.Format("function(btn){{if(btn=='cancel'){{{0}}}else{{{1}}}}}", cancelScript, okScriptstring), true);

            string targetName = "window";

            if (target != Target.Self)
            {
                targetName = TargetHelper.GetScriptName(target);
            }
            return(String.Format("{0}.Ext.MessageBox.show({1});", targetName, ob.ToString()));
        }
示例#3
0
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();

            #region Reset ActiveIndex

            // ActiveIndex has been changed, reset Panes's Collapsed property.
            if (_activeIndex != -1)
            {
                foreach (AccordionPane pane in Panes)
                {
                    pane.Collapsed = true;
                }
                Panes[_activeIndex].Collapsed = false;
            }

            #endregion

            #region Panes

            if (Panes.Count > 0)
            {
                JsArrayBuilder ab = new JsArrayBuilder();
                foreach (AccordionPane item in Panes)
                {
                    if (item.Visible)
                    {
                        ab.AddProperty(String.Format("{0}", item.XID), true);
                    }
                }
                OB.AddProperty("items", ab.ToString(), true);
            }

            #endregion

            #region LayoutConfig

            JsObjectBuilder configBuilder = new JsObjectBuilder();
            configBuilder.AddProperty("animate", false);
            configBuilder.AddProperty("activeOnTop", EnableActiveOnTop);
            configBuilder.AddProperty("fill", EnableFill);
            configBuilder.AddProperty("hideCollapseTool", !ShowCollapseTool);
            //configBuilder.AddProperty(OptionName.TitleCollapse, true);
            //if (EnableLargeHeader)
            //{
            //    // 删除对CtCls的定义
            //    OB.RemoveProperty(OptionName.CtCls);
            //    configBuilder.AddProperty(OptionName.ExtraCls, "box-panel-big-header");
            //}

            OB.AddProperty("layoutConfig", configBuilder);

            #endregion



            //string activeScript = String.Empty;
            //activeScript += String.Format("var panel=Ext.getCmp(Ext.get(linkId).findParent('div.x-panel','{0}').id);panel.expand();", ClientID);
            //activeScript += String.Format("Ext.each(Ext.get('{0}').query('ul.box-accrodion-link-ul li'),function(ele){{Ext.get(ele).removeClass('box-accrodion-link-select');}});", ClientID);
            //activeScript += "Ext.get(Ext.get(linkId).findParent('li')).addClass('box-accrodion-link-select');";

            //string boxActiveFunction = String.Format("function(linkId){{{0}}}", activeScript);
            //OB.AddProperty("box_active", boxActiveFunction, true);



            string jsContent = String.Format("var {0}=new Ext.Panel({1});", XID, OB.ToString());
            AddStartupScript(jsContent);
        }
示例#4
0
文件: TabStrip.cs 项目: g992com/esb
        /// <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);
        }
示例#5
0
文件: Accordion.cs 项目: g992com/esb
        protected override void OnFirstPreRender()
        {
            base.OnFirstPreRender();

            #region Reset ActiveIndex

            // ActiveIndex has been changed, reset Panes's Collapsed property.
            if (_activeIndex != -1)
            {
                foreach (AccordionPane pane in Panes)
                {
                    pane.Collapsed = true;
                }
                Panes[_activeIndex].Collapsed = false;
            }

            #endregion

            #region Panes

            if (Panes.Count > 0)
            {
                JsArrayBuilder ab = new JsArrayBuilder();
                foreach (AccordionPane item in Panes)
                {
                    if (item.Visible)
                    {
                        ab.AddProperty(String.Format("{0}", item.XID), true);
                    }
                }
                OB.AddProperty("items", ab.ToString(), true);
            }

            #endregion

            #region LayoutConfig

            JsObjectBuilder configBuilder = new JsObjectBuilder();
            configBuilder.AddProperty("animate", false);
            configBuilder.AddProperty("activeOnTop", EnableActiveOnTop);
            configBuilder.AddProperty("fill", EnableFill);
            configBuilder.AddProperty("hideCollapseTool", !ShowCollapseTool);
            //configBuilder.AddProperty(OptionName.TitleCollapse, true);
            //if (EnableLargeHeader)
            //{
            //    // 删除对CtCls的定义
            //    OB.RemoveProperty(OptionName.CtCls);
            //    configBuilder.AddProperty(OptionName.ExtraCls, "box-panel-big-header");
            //}

            OB.AddProperty("layoutConfig", configBuilder);

            #endregion



            //string activeScript = String.Empty;
            //activeScript += String.Format("var panel=Ext.getCmp(Ext.get(linkId).findParent('div.x-panel','{0}').id);panel.expand();", ClientID);
            //activeScript += String.Format("Ext.each(Ext.get('{0}').query('ul.box-accrodion-link-ul li'),function(ele){{Ext.get(ele).removeClass('box-accrodion-link-select');}});", ClientID);
            //activeScript += "Ext.get(Ext.get(linkId).findParent('li')).addClass('box-accrodion-link-select');";

            //string boxActiveFunction = String.Format("function(linkId){{{0}}}", activeScript);
            //OB.AddProperty("box_active", boxActiveFunction, true);



            string jsContent = String.Format("var {0}=new Ext.Panel({1});", XID, OB.ToString());
            AddStartupScript(jsContent);
        }
示例#6
0
文件: Grid.cs 项目: g992com/esb
        private string GetGridStore()
        {
            JsObjectBuilder storeBuilder = new JsObjectBuilder();

            // store - fields
            JsArrayBuilder fieldsBuidler = new JsArrayBuilder();
            foreach (GridColumn column in AllColumns)
            {
                #region old code
                //JsObjectBuilder fieldBuilder = new JsObjectBuilder();
                //fieldBuilder.AddProperty("name", column.ColumnID);
                ////fieldBuilder.AddProperty(OptionName.Mapping, columnIndex);
                ////fieldBuilder.AddProperty(OptionName.Type, column.GetFieldType());

                //fieldsBuidler.AddProperty(fieldBuilder);
                //columnIndex++; 
                #endregion
                if (column is TemplateField && (column as TemplateField).RenderAsRowExpander)
                {
                    fieldsBuidler.AddProperty(Render_GridRowExpanderID);
                }
                else
                {
                    fieldsBuidler.AddProperty(column.ColumnID);
                }
            }

            //// 如果Grid启用RowExpander,需要附加额外的数据
            //if (!String.IsNullOrEmpty(RowExpander.DataFormatString))
            //{
            //    foreach (string field in RowExpander.DataFields)
            //    {
            //        fieldsBuidler.AddProperty(field);
            //    }
            //}

            storeBuilder.AddProperty("fields", fieldsBuidler, true);

            return String.Format("var {0}=new Ext.data.ArrayStore({1});", Render_GridStoreID, storeBuilder.ToString());

            #region old code

            //storeBuilder.AddProperty("remoteSort", true);
            //storeBuilder.AddProperty("proxy", String.Format("new Ext.ux.AspNetProxy('{0}')", ClientID), true);

            //storeBuilder.AddProperty("autoLoad", "{params:{start:0,limit:" + PageSize + "}}", true);
            //storeBuilder.AddProperty("data", GetDatas());

            //if (AllowSorting)
            //{
            //    // Default sort info
            //    if (SortColumnIndex >= 0 && SortColumnIndex < Columns.Count)
            //    {
            //        JsObjectBuilder sortInfoBuilder = new JsObjectBuilder();
            //        sortInfoBuilder.AddProperty("field", Columns[SortColumnIndex].ColumnID);
            //        sortInfoBuilder.AddProperty("direction", SortDirection);

            //        storeBuilder.AddProperty("sortInfo", sortInfoBuilder);
            //    }
            //}


            //return String.Format("var {0}=new Ext.data.ArrayStore({1});", Render_GridStoreID, storeBuilder.ToString());


            //#region store - data
            ////string dataArrayString = GetDataArrayString(startEndRowIndex[0], startEndRowIndex[1]);



            //int[] startEndRowIndex = GetStartEndRowIndex();
            //// 计算完要渲染到前台的数据的条数,就要检查当前选中的项是不是有越界的
            //ResolveSelectedRowIndexArray(startEndRowIndex[1] - startEndRowIndex[0]);

            //#endregion 
            #endregion

            #region old code

            //JsArrayBuilder rowIndexBuilder = new JsArrayBuilder();

            //if (SelectedRowIndexArray != null && SelectedRowIndexArray.Length > 0)
            //{
            //    foreach (int rowIndex in SelectedRowIndexArray)
            //    {
            //        rowIndexBuilder.AddProperty(rowIndex);
            //    }
            //}
            //string selectRowScript = String.Format("{0}.selectRows({1});", Render_SelectModelID, rowIndexBuilder);
            //// 选中哪些行,这个必须要defer(100),否则选不中,晕(10ms就不行)
            //selectRowScript = String.Format("(function(){{{0}}}).defer(100);", selectRowScript);

            //storeBuilder.AddProperty("listeners", String.Format("{{load:{0}}}", String.Format("function(){{{0}}}", selectRowScript)), true);

            #endregion

            #region old code

            // TODO
            //string selectedRowIndexArrayString = StringUtil.GetStringFromIntArray(SelectedRowIndexArray);
            //// ExtAspNetAjax回发并且Columns发生变化,需要重新
            //if (_ExtAspNetAjaxColumnsChanged)
            //{
            //    string reconfigScript = String.Empty;
            //    reconfigScript += gridStoreScript;
            //    reconfigScript += String.Format("{0}.reconfigure({1},{2});", XID, Render_GridStoreID, Render_GridColumnModelID);
            //    reconfigScript += String.Format("{0}.load();", Render_GridStoreID);
            //    // 重新加载数据后要更新input选中哪些项(因为可能选中项也会变化)
            //    reconfigScript += GetSetHiddenFieldValueScript(SelectedRowIndexArrayHiddenFieldID, selectedRowIndexArrayString);

            //    AddAjaxPropertyChangedScript(reconfigScript);
            //}
            //else
            //{
            //    bool reloadData = false;
            //    string updateSelectRowScript = selectRowScript + GetSetHiddenFieldValueScript(SelectedRowIndexArrayHiddenFieldID, selectedRowIndexArrayString);
            //    if (AjaxPropertyChanged("DataArrayString", dataArrayString))
            //    {
            //        string reloadDataScript = String.Format("{0}.loadData({1});", Render_GridStoreID, dataArrayString);
            //        // 虽然有可能“不需要修改隐藏字段的值,因为SelectedRowIndexArray其实并没有变化,只是重新加载数据(reloadData)导致选中项丢失了”
            //        // 但是我们还是修改了input的值,这没有什么影响
            //        reloadDataScript += updateSelectRowScript;

            //        AddAjaxPropertyChangedScript(reloadDataScript);

            //        reloadData = true;
            //    }

            //    // 不管SelectedRowIndexArray==null或者是不为空,都要做这一步
            //    // 在Ajax回发中,selectedRowIndexArrayString改变了,并且没有重新加载数据
            //    if (AjaxPropertyChanged("SelectedRowIndexArrayString", selectedRowIndexArrayString) && !reloadData)
            //    {
            //        AddAjaxPropertyChangedScript(updateSelectRowScript);
            //    }

            //} 
            #endregion

            #region old code

            //gridStoreScript += "\r\n";
            //if (EnableClientPaging)
            //{

            //    // 进行分页时,改变隐藏input的值,以在回发时保持状态
            //    // 同时注意:客户端分页时,清空选中的值
            //    JsObjectBuilder listenersBuilder = new JsObjectBuilder();
            //    listenersBuilder.AddProperty(OptionName.Load, String.Format("function(store,records,options){{Ext.get('{0}').dom.value=options.params.start;Ext.get('{1}').dom.value='';}}", EnableClientPagingStartRowIndexID, SelectedRowsHiddenFieldID), true);
            //    storeBuilder.AddProperty("listeners", listenersBuilder);
            //}

            // 每次都是加载全部
            //loadStoreScript = String.Format("{0}.load({1});", gridStoreId, "{params:{start:0,limit:" + (endRowIndex - startRowIndex + 1) + "}}");


            //// load store
            ////string loadStoreScript = String.Empty;
            //if (EnableClientPaging)
            //{
            //    loadStoreScript = String.Format("{0}.load({1});", gridStoreId, "{params:{start:" + EnableClientPagingStartRowIndex + ",limit:" + PageSize + "}}");
            //}
            //else
            //{
            //    loadStoreScript = String.Format("{0}.load({1});", gridStoreId, "{params:{start:0,limit:" + Rows.Count + "}}");
            //}

            //gridStoreScript += loadStoreScript; 
            #endregion
        }
示例#7
0
文件: Grid.cs 项目: g992com/esb
        private string GetGroupColumnScript()
        {
            if (Columns.Count > 0)
            {
                return String.Empty;
            }

            List<List<GridGroupColumn>> resolvedGroups = new List<List<GridGroupColumn>>();
            ResolveGroupColumns(GroupColumns, 0, resolvedGroups);

            JsArrayBuilder groupHeaderBuilder = new JsArrayBuilder();

            foreach (List<GridGroupColumn> groups in resolvedGroups)
            {
                JsArrayBuilder groupsBuilder = new JsArrayBuilder();
                foreach (GridGroupColumn group in groups)
                {
                    JsObjectBuilder groupBuilder = new JsObjectBuilder();
                    groupBuilder.AddProperty("header", group.HeaderText);
                    if (group.TextAlign != TextAlign.Left)
                    {
                        groupBuilder.AddProperty("align", TextAlignName.GetName(group.TextAlign));
                    }

                    int groupColumnCount = 0;
                    ResolveColumnCount(group, ref groupColumnCount);
                    groupBuilder.AddProperty("colspan", groupColumnCount);

                    groupsBuilder.AddProperty(groupBuilder);
                }

                groupHeaderBuilder.AddProperty(groupsBuilder);
            }

            return String.Format("var {0}=new Ext.ux.grid.ColumnHeaderGroup({{rows:{1}}});", Render_GridGroupColumnID, groupHeaderBuilder.ToString());

        }
示例#8
0
文件: Grid.cs 项目: g992com/esb
        private string GetGridSelectModel()
        {
            JsObjectBuilder selectOB = new JsObjectBuilder();
            selectOB.AddProperty("singleSelect", !EnableMultiSelect);
            //selectOB.AddProperty("checkOnly", true);

            //selectOB.AddProperty("listeners", "{beforerowselect:function(){return false;}}", true);

            if (EnableCheckBoxSelect)
            {
                return String.Format("var {0}=new Ext.grid.CheckboxSelectionModel({1});", Render_SelectModelID, selectOB);
            }
            else
            {
                return String.Format("var {0}=new Ext.grid.RowSelectionModel({1});", Render_SelectModelID, selectOB);
            }

            #region old code
            //// 选中行,不选中行
            //JsObjectBuilder selectListenersBuilder = new JsObjectBuilder();
            //selectListenersBuilder.AddProperty("rowselect", String.Format("function(sm,rowIndex,record){{X.util.addValueToHiddenField('{0}',rowIndex);}}", SelectedRowsHiddenFieldID), true);
            //selectListenersBuilder.AddProperty("rowdeselect", String.Format("function(sm,rowIndex,record){{X.util.removeValueFromHiddenField('{0}',rowIndex);}}", SelectedRowsHiddenFieldID), true);

            //selectOptionBuilder.AddProperty("listeners", selectListenersBuilder); 
            #endregion
        }
示例#9
0
文件: Grid.cs 项目: g992com/esb
        private JsObjectBuilder GetPagingBuilder()
        {
            JsObjectBuilder pagingBuilder = new JsObjectBuilder();
            pagingBuilder.AddProperty("pageSize", PageSize);
            pagingBuilder.AddProperty("pageIndex", PageIndex);
            pagingBuilder.AddProperty("recordCount", RecordCount);
            pagingBuilder.AddProperty("pageCount", PageCount);

            int startRowIndex, endRowIndex;
            ResolveStartEndRowIndex(out startRowIndex, out endRowIndex);
            pagingBuilder.AddProperty("x_startRowIndex", startRowIndex);
            pagingBuilder.AddProperty("x_endRowIndex", endRowIndex);


            return pagingBuilder;
        }
示例#10
0
文件: Grid.cs 项目: g992com/esb
        private string GetGridColumnScript()
        {
            string selectModelID = Render_SelectModelID;
            string gridColumnID = Render_GridColumnModelID;
            // columns
            JsArrayBuilder columnsBuilder = new JsArrayBuilder();

            //string expanderScript = String.Empty;
            //if (!String.IsNullOrEmpty(RowExpander.DataFormatString))
            //{
            //    string tplStr = String.Format(RowExpander.DataFormatString.Replace("{", "{{{").Replace("}", "}}}"), RowExpander.DataFields);
            //    expanderScript = String.Format("var {0}=new Ext.ux.grid.RowExpander({{tpl:new Ext.Template({1})}});", Render_GridRowExpanderID, JsHelper.Enquote(tplStr));
            //    columnsBuilder.AddProperty(Render_GridRowExpanderID, true);
            //}

            // 如果启用行序号,则放在第一列
            if (EnableRowNumber)
            {
                columnsBuilder.AddProperty("new Ext.grid.RowNumberer()", true);
            }
            // 如果启用CheckBox,则放在第二列
            if (EnableCheckBoxSelect)
            {
                columnsBuilder.AddProperty(selectModelID, true);
            }

            string groupColumnScript = GetGroupColumnScript();

            string expanderScript = String.Empty;
            int columnIndex = 0;
            foreach (GridColumn column in AllColumns)
            {
                if (column is TemplateField && (column as TemplateField).RenderAsRowExpander)
                {
                    //string tplStr = String.Format(RowExpander.DataFormatString.Replace("{", "{{{").Replace("}", "}}}"), RowExpander.DataFields);
                    //expanderScript = String.Format("var {0}=new Ext.ux.grid.RowExpander({{tpl:new Ext.Template({1})}});", Render_GridRowExpanderID, JsHelper.Enquote(tplStr));
                    expanderScript = String.Format("var {0}=new Ext.ux.grid.RowExpander({{tpl:new Ext.Template(\"{{{1}}}\")}});", Render_GridRowExpanderID, Render_GridRowExpanderID);

                    columnsBuilder.AddProperty(Render_GridRowExpanderID, true);

                }
                else
                {
                    JsObjectBuilder columnBuilder = new JsObjectBuilder();
                    columnBuilder.AddProperty("header", String.IsNullOrEmpty(column.HeaderText) ? "&nbsp;" : column.HeaderText);
                    if (column.Hidden)
                    {
                        columnBuilder.AddProperty("hidden", true);
                    }

                    if (AllowSorting)
                    {
                        if (!String.IsNullOrEmpty(column.SortField))
                        {
                            //// 自定义JavaScript变量
                            columnBuilder.AddProperty("x_serverSortable", true);
                            //columnBuilder.AddProperty("sortable", true);
                        }
                    }

                    if (column.PersistState)
                    {
                        columnBuilder.AddProperty("x_persistState", true);
                        columnBuilder.AddProperty("x_persistStateType", "checkbox");
                    }

                    #region old code

                    // The following config will be in defaults
                    //columnBuilder.AddProperty(OptionName.Sortable, false);
                    //columnBuilder.AddProperty("menuDisabled", true);
                    //columnBuilder.AddProperty("hideable", false);

                    //// 如果启用服务器端排序,则禁用客户端排序
                    //if (EnableServerSort)
                    //{
                    //    columnBuilder.AddProperty(OptionName.Sortable, false);
                    //}
                    //else if (EnableClientSort)
                    //{
                    //    columnBuilder.AddProperty(OptionName.Sortable, true);
                    //}
                    //else
                    //{
                    //    columnBuilder.AddProperty(OptionName.Sortable, false);
                    //}
                    //    // 客户端排序,如果没有定义SortField,则不启用服务器端排序
                    //    if (!String.IsNullOrEmpty(column.SortField))
                    //    {
                    //        columnBuilder.AddProperty(OptionName.Sortable, true);
                    //    }
                    //    else
                    //    {
                    //        columnBuilder.AddProperty(OptionName.Sortable, false);
                    //    }
                    //}
                    //if (!String.IsNullOrEmpty(column.SortField))
                    //{
                    //    columnBuilder.AddProperty(OptionName.Sortable, true);
                    //}
                    //else
                    //{
                    //    columnBuilder.AddProperty(OptionName.Sortable, false);
                    //}

                    #endregion

                    ////If not specified, the column's index is used as an index into the Record's data Array.
                    //columnBuilder.AddProperty(OptionName.DataIndex, field.DataField);
                    columnBuilder.AddProperty("dataIndex", column.ColumnID);
                    columnBuilder.AddProperty("id", column.ColumnID);

                    if (column.TextAlign != TextAlign.Left)
                    {
                        columnBuilder.AddProperty("align", TextAlignName.GetName(column.TextAlign));
                    }

                    if (column.Width != Unit.Empty)
                    {
                        columnBuilder.AddProperty("width", column.Width.Value);
                    }

                    columnsBuilder.AddProperty(columnBuilder);
                }

                columnIndex++;
            }

            // 为Grid添加plugin属性
            JsArrayBuilder pluginBuilder = new JsArrayBuilder();

            if (!String.IsNullOrEmpty(expanderScript))
            {
                pluginBuilder.AddProperty(Render_GridRowExpanderID, true);
            }

            if (!String.IsNullOrEmpty(groupColumnScript))
            {
                pluginBuilder.AddProperty(Render_GridGroupColumnID, true);
            }

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



            JsObjectBuilder defaultsBuilder = new JsObjectBuilder();
            // 这是Extjs默认的客户端排序
            //defaultsBuilder.AddProperty("sortable", false);
            //defaultsBuilder.AddProperty("menuDisabled", true);
            defaultsBuilder.AddProperty("width", 100);

            string columnModelScript = String.Format("var {0}=new Ext.grid.ColumnModel({{columns:{1},defaults:{2}}});", gridColumnID, columnsBuilder, defaultsBuilder);

            return expanderScript + groupColumnScript + columnModelScript;
        }
示例#11
0
文件: Grid.cs 项目: g992com/esb
        protected override void OnFirstPreRender()
        {
            // 确保 X_Rows 在页面第一次加载时都存在于x_state中
            XState.AddModifiedProperty("X_Rows");

            base.OnFirstPreRender();

            ResourceManager.Instance.AddJavaScriptComponent("grid");

            //OB.Listeners.AddProperty("rowmousedown", "function(){alert('ok');}", true);

            #region selectModel/gridStore/gridColumn

            #region old code
            //string dataScript = "var grid_data=[['My_Item1The id of a column in this grid that should expand to fill unused space. This id can not be 0.','1','2008'],['My_Item2','2','2007']];";
            //string storeScript = "var grid_store = new Ext.data.SimpleStore({fields:[{name:'name1'},{name:'value'},{name:'year'}]});\r\ngrid_store.loadData(grid_data);";
            //string storeScript = "var grid_store = new Ext.data.SimpleStore({fields:['name1','value1','year1'],data:[['My_Item1The id of a column in this grid that should expand to fill unused space. This id can not be 0.','1','2008'],['My_Item2','2','2007']]});";
            //OB.AddProperty(OptionName.Columns, "[{id:'name2', header: 'Price', sortable: true},{header: 'Price2', sortable: true},{header: 'Price3', sortable: true}]", true);

            #endregion

            string gridSelectModelScript = GetGridSelectModel();
            OB.AddProperty("sm", Render_SelectModelID, true);
            //OB.AddProperty("disableSelection", true);

            string gridColumnsScript = GetGridColumnScript();
            OB.AddProperty("cm", Render_GridColumnModelID, true);
            //if (!String.IsNullOrEmpty(RowExpander.DataFormatString))
            //{
            //    OB.AddProperty("plugins", Render_GridRowExpanderID, true);
            //}

            string gridStoreScript = GetGridStore();
            OB.AddProperty("store", Render_GridStoreID, true);

            //Console.WriteLine(RowExpander.DataFields);

            #endregion

            #region Width

            if (MinColumnWidth != Unit.Empty)
            {
                OB.AddProperty("minColumnWidth", MinColumnWidth.Value);
            }

            string autoExpandColumnID = AutoExpandColumn; // GetAutoExpandColumnID();
            if (String.IsNullOrEmpty(autoExpandColumnID))
            {
                autoExpandColumnID = GetAutoExpandColumnID();  
            }

            if (!String.IsNullOrEmpty(autoExpandColumnID))
            {
                OB.AddProperty("autoExpandColumn", autoExpandColumnID);

                if (AutoExpandColumnMax != Unit.Empty)
                {
                    OB.AddProperty("autoExpandMax", AutoExpandColumnMax.Value);
                }

                if (AutoExpandColumnMin != Unit.Empty)
                {
                    OB.AddProperty("autoExpandMin", AutoExpandColumnMin.Value);
                }
            }


            JsObjectBuilder viewBuilder = new JsObjectBuilder();
            if(ForceFitAllTime)
            {
                viewBuilder.AddProperty("forceFit", true);
            }
            if (ForceFitFirstTime)
            {
                viewBuilder.AddProperty("autoFill", true);
            }

            if (VerticalScrollWidth != Unit.Empty)
            {
                viewBuilder.AddProperty("scrollOffset", VerticalScrollWidth.Value);
            }

            if (viewBuilder.Count > 0)
            {
                OB.AddProperty("viewConfig", viewBuilder);
            }

            #endregion

            #region Properties

            //if (!EnableHeaderMenu)
            //{
            //    OB.AddProperty("enableHdMenu", false);
            //}
            //if (!EnableColumnHide)
            //{
            //    OB.AddProperty("enableColumnHide", false);
            //}

            OB.AddProperty("enableHdMenu", false);

            if (EnableAlternateRowColor)
            {
                OB.AddProperty("stripeRows", true);
            }

            if (!ShowGridHeader)
            {
                OB.AddProperty("hideHeaders", true);
            }

            if (!EnableMouseOverColor)
            {
                OB.AddProperty("trackMouseOver", false);
            }

            // 延迟渲染
            if (!EnableDelayRender)
            {
                OB.AddProperty("deferRowRender", false);
            }

            

            #endregion

            #region AutoPostBack

            if (AutoPostBack || EnableRowClick)
            {
                string validateScript = "var args='RowClick$'+rowIndex;";
                validateScript += GetPostBackEventReference("#RowClick#").Replace("'#RowClick#'", "args");

                string rowClickScript = String.Format("function(grid,rowIndex,e){{{0}}}", validateScript);


                OB.Listeners.AddProperty("rowclick", rowClickScript, true);
            }

            if (EnableRowDoubleClick)
            {
                string validateScript = "var args='RowDoubleClick$'+rowIndex;";
                validateScript += GetPostBackEventReference("#RowDoubleClick#").Replace("'#RowDoubleClick#'", "args");

                string rowClickScript = String.Format("function(grid,rowIndex,e){{{0}}}", validateScript);

                OB.Listeners.AddProperty("rowdblclick", rowClickScript, true);
            }

            #endregion

            #region AllowPaging

            string pagingScript = String.Empty;
            if (AllowPaging)
            {
                JsObjectBuilder pagingBuilder = GetPagingBuilder();

                pagingBuilder.AddProperty("displayInfo", true);
                //pagingBuilder.AddProperty("store", Render_GridStoreID, true);
                //// Hide refresh button, we don't implement this logic now.
                //pagingBuilder.Listeners.AddProperty("beforerender", JsHelper.GetFunction("this.x_hideRefresh();"), true);

                string postbackScript = String.Empty;
                postbackScript = GetPostBackEventReference("#PLACEHOLDER#");
                string loadPageScript = JsHelper.GetFunction(postbackScript.Replace("'#PLACEHOLDER#'", "'Page$'+pageIndex"), "pageIndex");

                pagingBuilder.AddProperty("onLoadPage", loadPageScript, true);


                pagingScript = String.Format("var {0}=new Ext.ux.SimplePagingToolbar({1});", Render_PagingID, pagingBuilder);

                OB.AddProperty("bbar", Render_PagingID, true);
            }

            #endregion

            #region old code

            //string checkBoxFieldScript = String.Empty;
            //int columnIndex = 0;
            //List<int> needPersistStateColumnIndexList = new List<int>();
            //foreach (GridColumn column in Columns)
            //{
            //    if (column is CheckBoxField)
            //    {
            //        CheckBoxField checkBoxField = column as CheckBoxField;

            //        if (!checkBoxField.RenderAsStaticField)
            //        {
            //            // check -> uncheck
            //            //string checkScript = String.Format("ele.toggleClass('box-grid-checkbox-uncheck');var domValue=Ext.get('{0}').dom.value;var rowValueIndex=domValue.indexOf(rowIndex+',');if(rowValueIndex>=0){{Ext.get('{0}').dom.value=domValue.replace(rowIndex+',','');}}else{{return;}}", GetNeedPersistStateColumnIndexID(columnIndex));
            //            //string uncheckScript = String.Format("ele.toggleClass('box-grid-checkbox-uncheck');var domValue=Ext.get('{0}').dom.value;var rowValueIndex=domValue.indexOf(rowIndex+',');if(rowValueIndex>=0){{return;}}else{{Ext.get('{0}').dom.value+=rowIndex+',';}}", GetNeedPersistStateColumnIndexID(columnIndex));

            //            //string checkScript = String.Format("ele.toggleClass('box-grid-checkbox-uncheck');X.util.removeValueFromHiddenField('{0}',rowIndex);", GetNeedPersistStateColumnIndexID(columnIndex));
            //            //string uncheckScript = String.Format("ele.toggleClass('box-grid-checkbox-uncheck');X.util.addValueToHiddenField('{0}',rowIndex);", GetNeedPersistStateColumnIndexID(columnIndex));

            //            string checkScript = "ele.toggleClass('box-grid-checkbox-uncheck');";
            //            string uncheckScript = "ele.toggleClass('box-grid-checkbox-uncheck');";


            //            checkBoxFieldScript += String.Format("{0}_checkbox{1}=function(e,ele,rowIndex){{var ele=Ext.get(ele);if(ele.hasClass('box-grid-checkbox-uncheck')){{{2}}}else{{{3}}}}};", XID, columnIndex, uncheckScript, checkScript);
            //            //checkBoxFieldScript += "\r\n";

            //            needPersistStateColumnIndexList.Add(columnIndex);
            //        }
            //    }
            //    columnIndex++;
            //}

            //NeedPersistStateColumnIndexArray = needPersistStateColumnIndexList.ToArray();

            #endregion

            #region old code

            //string hiddenFieldsScript = String.Empty;

            //hiddenFieldsScript += GetSetHiddenFieldValueScript(SelectedRowIndexArrayHiddenFieldID, StringUtil.GetStringFromIntArray(SelectedRowIndexArray));

            //// 有这些列需要保存状态
            //if (NeedPersistStateColumnIndexArray != null && NeedPersistStateColumnIndexArray.Length > 0)
            //{
            //    foreach (int needStateColumnIndex in NeedPersistStateColumnIndexArray)
            //    {
            //        hiddenFieldsScript += GetSetHiddenFieldValueScript(GetNeedPersistStateColumnIndexID(needStateColumnIndex), Columns[needStateColumnIndex].SaveColumnState());
            //    }
            //}

            //hiddenFieldsScript += "\r\n";
            #endregion

            #region remove fx

            OB.AddProperty("draggable", false);
            OB.AddProperty("enableColumnMove", false);
            OB.AddProperty("enableDragDrop", false);

            #endregion

            #region old code

            //JsObjectBuilder viewConfigBuilder = new JsObjectBuilder();
            //viewConfigBuilder.AddProperty("autoFill", true);
            //viewConfigBuilder.AddProperty("deferEmptyText", true);
            //viewConfigBuilder.AddProperty("emptyText", "没有数据需要显示");

            //OB.AddProperty("viewConfig", viewConfigBuilder);

            #endregion

            #region AllowSorting

            // 如果启用服务器端排序,则需要注册headerclick事件处理
            if (AllowSorting)
            {
                #region old code
                ////string argumentStr = "var field=sortInfo.field.substr(sortInfo.field.indexOf('__')+2);var args='Sort$'+field+'$'+ sortInfo.direction;";
                //string argumentStr = "var args='Sort$'+sortInfo.field;";
                //string postBackReference = String.Format("{1}__doPostBack('{0}',args);return false;", ClientID, argumentStr);

                //string sortChangeScript = String.Format("function(grid,sortInfo){{{0}}}", postBackReference);
                //OB.Listeners.AddProperty(OptionName.Sortchange, sortChangeScript, true); 


                // 下面这个规则不再使用,因为会引入中文,导致Ext.get('Grid1').select 函数出错
                // 还要进行验证:序号列和多选框列不能排序,没有设置SortField的列也不能排序
                // 规则:如果此列的dataIndex为空,表示不是数据列(就是序号列或多选框列),
                // 如果dataIndex为"c0__MyText",表示排序字段是"MyText",如果dataIndex为"c2",表示没有定义排序列
                //string validateScript = "var dataIndex=grid.initialConfig.columns[columnIndex].dataIndex;if(dataIndex==''||dataIndex.indexOf('__')<0){return false;}";

                //string validateScript = "var dataIndex=grid.getColumnModel().getDataIndex(columnIndex);if(dataIndex==''||dataIndex.indexOf('__')<0){return false;}";
                #endregion

                string headerClickScript = "if(!cmp.getColumnModel().config[columnIndex].x_serverSortable){return false;}";
                headerClickScript += "var args='Sort$'+columnIndex;";
                headerClickScript += GetPostBackEventReference("#SORT#").Replace("'#SORT#'", "args");

                //string headerClickScript = String.Format("function(grid,columnIndex){{{0}}}", validateScript);
                OB.Listeners.AddProperty("headerclick", JsHelper.GetFunction(headerClickScript, "cmp", "columnIndex"), true);

                #region old code
                //string sortIconScript = GetSortIconScript();

                //if (_ExtAspNetAjaxColumnsChanged)
                //{
                //    // 如果列都发生了变化,需要重新设置图标
                //    AddAjaxPropertyChangedScript(sortIconScript);
                //}
                //else
                //{
                //    if (AjaxPropertyChanged("SortIconScript", sortIconScript))
                //    {
                //        AddAjaxPropertyChangedScript(sortIconScript);
                //    }
                //}

                //renderSB.Append(sortIconScript);


                //// For these columns need sorted, show the cursor pointer.
                //List<string> columnIDList = new List<string>();
                //foreach (GridColumn column in Columns)
                //{
                //    if (!String.IsNullOrEmpty(column.SortField))
                //    {
                //        columnIDList.Add(column.ColumnID);
                //    }
                //}

                //// 存在需要排序的列
                //if (columnIDList.Count > 0)
                //{
                //    string cursorScript = String.Format("Ext.each({0},{1});", JsHelper.GetJsStringArray(columnIDList.ToArray()),
                //        String.Format("function(item){{Ext.get('{0}').select('.x-grid3-hd-row .x-grid3-td-'+item).addClass('cursor-pointer');}}", ClientID));


                //    renderSB.Append(cursorScript);

                //    if (_ExtAspNetAjaxColumnsChanged)
                //    {
                //        // 如果列都发生了变化,需要重新需要排序的列,显示为手型的光标
                //        AddAjaxPropertyChangedScript(cursorScript);
                //    }
                //} 
                #endregion
            }

            #endregion

            #region Listeners - render - viewready

            StringBuilder viewreadySB = new StringBuilder();

            // Note: this.x_state['X_Rows']['Values'] will always rendered to the client side.
            //viewreadySB.Append("cmp.x_updateTpls();");

            if (AllowSorting)
            {
                // After the grid is rendered, then we can apply sort icon to grid header.
                viewreadySB.AppendFormat("cmp.x_setSortIcon({0}, '{1}');", SortColumnIndex, SortDirection);
            }
            viewreadySB.Append("cmp.x_selectRows();");


            // 展开所有的行扩展列
            if (ExpandAllRowExpanders)
            {
                viewreadySB.Append("cmp.x_expandAllRows();");
            }

            if (EnableTextSelection)
            {
                OB.AddProperty("cls", CssClass + " x-grid-selectable");

                viewreadySB.Append("cmp.x_enableTextSelection();");
            }

            OB.Listeners.AddProperty("viewready", JsHelper.GetFunction(viewreadySB.ToString(), "cmp"), true);


            #endregion

            #region Listeners - render

            StringBuilder renderSB = new StringBuilder();


            renderSB.Append("cmp.x_loadData();");

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


            #endregion

            StringBuilder sb = new StringBuilder();
            sb.Append(gridSelectModelScript + gridStoreScript + gridColumnsScript + pagingScript);
            sb.AppendFormat("var {0}=new Ext.grid.GridPanel({1});", XID, OB);

            AddStartupScript(sb.ToString());

            #region old code

            ////List<string> totalModifiedProperties = XState.GetTotalModifiedProperties();
            ////if (SelectedRowIndexArray.Length > 0)
            ////{
            ////    string selectScript = String.Empty;
            ////    if (totalModifiedProperties.Contains("SelectedRowIndexArray"))
            ////    {
            ////        selectScript = String.Format("{0}.x_selectRows();", XID);
            ////    }
            ////    else
            ////    {
            ////        selectScript = String.Format("{0}.selectRows({1});", Render_SelectModelID, new JArray(SelectedRowIndexArray));
            ////    }
            ////    sb.Append(JsHelper.GetDeferScript(selectScript, 200));
            ////}

            //// Make sure SelectedRowIndexArray property exist in X_STATE during page's first load.
            //sb.Append(JsHelper.GetDeferScript(String.Format("{0}.x_selectRows();", XID), 200));

            #endregion
        }
示例#12
0
文件: Confirm.cs 项目: g992com/esb
        /// <summary>
        /// 获取显示确认对话框的客户端脚本
        /// </summary>
        /// <param name="message">对话框消息</param>
        /// <param name="title">对话框标题</param>
        /// <param name="icon">对话框图标</param>
        /// <param name="okScriptstring">点击确定按钮执行的客户端脚本</param>
        /// <param name="cancelScript">点击取消按钮执行的客户端脚本</param>
        /// <param name="target">弹出对话框的目标页面</param>
        /// <returns>客户端脚本</returns>
        public static string GetShowReference(string message, string title, MessageBoxIcon icon, string okScriptstring, string cancelScript, Target target)
        {
            //string msgBoxScript = "var msgBox=Ext.MessageBox;";
            //msgBoxScript += "if(parent!=window){msgBox=parent.window.Ext.MessageBox;}";
            if (String.IsNullOrEmpty(title))
            {
                title = "X.util.confirmTitle";
            }
            else
            {
                title = JsHelper.GetJsString(title.Replace("\r\n", "\n").Replace("\n", "<br/>"));
            }
            message = message.Replace("\r\n", "\n").Replace("\n", "<br/>");


            JsObjectBuilder ob = new JsObjectBuilder();
            ob.AddProperty("title", title, true);
            ob.AddProperty("msg", JsHelper.GetJsStringWithScriptTag(message), true);
            ob.AddProperty("buttons", "Ext.MessageBox.OKCANCEL", true);
            ob.AddProperty("icon", String.Format("{0}", MessageBoxIconHelper.GetName(icon)), true);
            ob.AddProperty("fn", String.Format("function(btn){{if(btn=='cancel'){{{0}}}else{{{1}}}}}", cancelScript, okScriptstring), true);

            string targetName = "window";
            if (target != Target.Self)
            {
                targetName = TargetHelper.GetScriptName(target);
            }
            return String.Format("{0}.Ext.MessageBox.show({1});", targetName, ob.ToString());
        }
示例#13
0
文件: Tree.cs 项目: g992com/esb
        protected override void OnFirstPreRender()
        {
            // 确保 X_Nodes 在页面第一次加载时都存在于 X_STATE 中,因为客户端需要这个数据来渲染树控件
            // 并且这个代码要放在 base.OnFirstPreRender(); 之前,因为在那里面会生成 X_STATE
            XState.AddModifiedProperty("X_Nodes");

            base.OnFirstPreRender();

            ResourceManager.Instance.AddJavaScriptComponent("tree");


            #region options

            OB.AddProperty("useArrows", EnableArrows);
            OB.AddProperty("animate", EnableAnimate);

            OB.AddProperty("singleExpand", EnableSingleExpand);
            OB.AddProperty("lines", EnableLines);

            if (!EnableIcons)
            {
                //bodyCssClass: 'x-tree-noicon'
                OB.AddProperty("bodyCls", "x-tree-noicon");
            }


            // 这个为了在客户端生成 PostBack 脚本,比如 __doPostBack('RegionPanel1$TreePanel1','')
            OB.AddProperty("name", UniqueID);

            #endregion

            #region oldcode

            //string hiddenFieldsScript = String.Empty;

            //// 选中的行
            //hiddenFieldsScript += GetSetHiddenFieldValueScript(SelectedNodeHiddenFieldID, SelectedNode == null ? "" : SelectedNode.NodeID);

            //// 展开的行
            //hiddenFieldsScript += GetSetHiddenFieldValueScript(ExpandedNodesHiddenFieldID, StringUtil.GetStringFromStringArray(GetExpandedNodeIDs()));

            //// 选中的行
            //hiddenFieldsScript += GetSetHiddenFieldValueScript(CheckedNodesHiddenFieldID, StringUtil.GetStringFromStringArray(GetCheckedNodeIDs()));


            #endregion

            #region Loader

            string loaderScript = String.Empty;

            JsObjectBuilder loaderBuilder = new JsObjectBuilder();
            //if (!String.IsNullOrEmpty(DataCallbackUrl))
            //{
            //    loaderBuilder.AddProperty("baseParams",String.Format("{{treeClientId:'{0}'}}", ClientID), true);
            //    loaderBuilder.AddProperty("dataUrl", DataCallbackUrl); 

            //    JsObjectBuilder listenersBuilder = new JsObjectBuilder();
            //    listenersBuilder.AddProperty("load", String.Format("function(loader,node,response){{\r\nvar i =0;\r\n}}"), true);

            //    listenersBuilder.AddProperty(OptionName.Scope, "box", true);
            //    loaderBuilder.AddProperty("listeners", listenersBuilder);
            //}

            JsObjectBuilder listenersBuilder = new JsObjectBuilder();

            string paramStr = String.Format("Expand${0}", "#ID#");
            string postBackScript = GetPostBackEventReference(paramStr);
            postBackScript = postBackScript.Replace("#ID#'", "'+node.id");
            listenersBuilder.AddProperty("beforeload", String.Format("function(loader,node,callback){{{0}return false;}}", postBackScript), true);

            //listenersBuilder.AddProperty(OptionName.Scope, "box", true);
            loaderBuilder.AddProperty("listeners", listenersBuilder);
            // 必须添加dataUrl,才会引发beforeload事件
            loaderBuilder.AddProperty("dataUrl", "about:blank");
            loaderBuilder.AddProperty("preloadChildren", true);
            //loaderBuilder.AddProperty("clearOnLoad", false);

            loaderScript = String.Format("var {0}=new Ext.tree.TreeLoader({1});", Render_LoaderID, loaderBuilder);

            OB.AddProperty("loader", Render_LoaderID, true);

            #endregion

            #region selectModel

            string selectModelScript = String.Empty;
            if (EnableMultiSelect)
            {
                selectModelScript = "new Ext.tree.MultiSelectionModel()";
            }
            else
            {
                selectModelScript = "new Ext.tree.DefaultSelectionModel()";
            }
            OB.AddProperty("selModel", selectModelScript, true);

            #endregion

            #region old code

            // nodes
            //string nodesScript = Render_NodesId + "=[{'text':'Audi','id':100,'leaf':false,'cls':'folder','children':[{'text':'A3','id':1000,'leaf':false,'cls':'folder','children':[{'text':'FuelEconomy','id':'100000','leaf':true,'cls':'file'},{'text':'Invoice','id':'100001','leaf':true,'cls':'file'},{'text':'MSRP','id':'100002','leaf':true,'cls':'file'},{'text':'Options','id':'100003','leaf':true,'cls':'file'},{'text':'Specifications','id':'100004','leaf':true,'cls':'file'}]},{'text':'TT','id':1000,'leaf':false,'cls':'folder','children':[{'text':'FuelEconomy','id':'100000','leaf':true,'cls':'file'},{'text':'Invoice','id':'100001','leaf':true,'cls':'file'},{'text':'MSRP','id':'100002','leaf':true,'cls':'file'},{'text':'Options','id':'100003','leaf':true,'cls':'file'},{'text':'Specifications','id':'100004','leaf':true,'cls':'file'}]}]},{'text':'Cadillac','id':300,'leaf':false,'cls':'folder','children':[{'text':'CTS','id':1000,'leaf':false,'cls':'folder','children':[{'text':'FuelEconomy','id':'100000','leaf':true,'cls':'file'},{'text':'Invoice','id':'100001','leaf':true,'cls':'file'},{'text':'MSRP','id':'100002','leaf':true,'cls':'file'},{'text':'Options','id':'100003','leaf':true,'cls':'file'},{'text':'Specifications','id':'100004','leaf':true,'cls':'file'}]},{'text':'CTS-V','id':1000,'leaf':false,'cls':'folder','children':[{'text':'FuelEconomy','id':'100000','leaf':true,'cls':'file'},{'text':'Invoice','id':'100001','leaf':true,'cls':'file'},{'text':'MSRP','id':'100002','leaf':true,'cls':'file'},{'text':'Options','id':'100003','leaf':true,'cls':'file'},{'text':'Specifications','id':'100004','leaf':true,'cls':'file'}]}]}];";
            //string nodesJsArray = GetNodesJsArray2(Nodes).ToString();
            //string nodesScript = String.Format("{0}={1};", Render_NodesID, nodesJsArray);

            #endregion

            #region Root

            //JsObjectBuilder rootBuilder = new JsObjectBuilder();
            ////rootBuilder.AddProperty(OptionName.Id, "root");
            ////rootBuilder.AddProperty(OptionName.Text, "root");
            ////rootBuilder.AddProperty("loaded", false);
            //rootBuilder.AddProperty(OptionName.Children, Render_NodesId, true);

            //string rootNodeScript = String.Format("var {0}=new Ext.tree.AsyncTreeNode({1});", Render_RootId, rootBuilder.ToString());
            //rootNodeScript += "\r\n";


            //OB.AddProperty("root", "new Ext.tree.AsyncTreeNode()", true);
            OB.AddProperty("rootVisible", false);

            #endregion

            #region renderScript

            //string renderScript = String.Empty;
            ////renderScript += "cmp.x_loadData();";
            //if (SelectedNodeIDArray.Length > 0)
            //{
            //    renderScript += "var model=cmp.getSelectionModel();";
            //    foreach (string nodeId in SelectedNodeIDArray)
            //    {
            //        renderScript += String.Format("model.select(cmp.getNodeById('{0}'),null,true);", nodeId);
            //    }
            //}

            ////renderScript = "function(cmp){window.setTimeout(function(){ cmp.x_loadData(); },1000);}";

            OB.Listeners.AddProperty("beforerender", JsHelper.GetFunction("cmp.x_loadData();", "cmp"), true);

            OB.Listeners.AddProperty("afterrender", JsHelper.GetFunction("cmp.x_selectNodes();", "cmp"), true);

            #endregion

            #region AddStartupScript
            //// 展开,折叠,点击,选中CheckBox事件处理函数,
            //// 因为这些函数会被几乎每个节点使用,所以提取出公共的方法来
            //scripts.AppendFormat("{0}=function(node){{X.util.addValueToHiddenField('{1}',node.id);}};", Render_NodeExpandScriptID, ExpandedNodesHiddenFieldID);
            //scripts.AppendFormat("{0}=function(node){{X.util.removeValueFromHiddenField('{1}',node.id);}};", Render_NodeCollapseScriptID, ExpandedNodesHiddenFieldID);
            //scripts.AppendFormat("{0}=function(node,checked){{if(checked){{X.util.addValueToHiddenField('{1}',node.id);}}else{{X.util.removeValueFromHiddenField('{1}',node.id);}}}};", Render_NodeCheckChangeScriptID, CheckedNodesHiddenFieldID);
            //scripts.AppendFormat("{0}=function(node){{Ext.get('{1}').dom.value=node.id;}};", Render_NodeClickScriptID, SelectedNodeHiddenFieldID);

            //scripts.AppendLine(hiddenFieldsScript);


            StringBuilder scripts = new StringBuilder();

            scripts.AppendLine(loaderScript);
            scripts.AppendFormat("{0}=new Ext.tree.TreePanel({1});", XID, OB);

            AddStartupScript(scripts.ToString());

            #endregion
        }
示例#14
0
        /// <summary>
        /// 添加列
        /// </summary>
        /// <param name="ab"></param>
        /// <param name="startLineIndex">开始行的索引(包含)</param>
        /// <param name="endLineIndex">结束行的索引(包含)</param>
        /// <param name="columnCount">行的列数</param>
        private string AddColumnScript(JsArrayBuilder rowIdsBuilder, int startLineIndex, int endLineIndex, int columnCount)
        {
            // 注意,注册脚本的控件应该是最后一个 Row
            // 假如有从上之下这些控件: Row1(Field1,Field2), Row2(Field3,Field4),Row3(Field5)
            // 则渲染时,JS脚本的执行顺序为:Field1,Field2,Row1,Field3,Field4,Row2,Field5,Row3
            // 所以,如果column Panel的脚本注册为控件 Row3,则能保证所有的子控件已经初始化
            // 需要注意的是:在此设置脚本内容到 Row3 控件
            // 现在已经不是这样的了!!!,Row不在是一个控件

            #region examples


            //            {
            //                    layout: 'column',
            //                    border:false,
            //                    items:[{
            //                        columnWidth: .5,
            //                        layout: 'form',
            //                        border:false,
            //                        items:[{
            //                            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%'
            //                        }]
            //                    },{
            //                        columnWidth: .5,
            //                        layout: 'form',
            //                        border:false,
            //                        items:[{
            //                            xtype:'combo',
            //                            store: executePersonStore,
            //                            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: 'executePerson',
            //                            anchor:'95%'
            //                        }]
            //                    }]
            //          }


            #endregion


            // 最后一行
            FormRow endLineRow = Rows[endLineIndex];
            string  rowId      = String.Format("{0}_row{1}", XID, endLineIndex);



            #region bodyStyleStr

            // 如果Form有背景色,这里也增加背景色
            string bodyStyleStr = String.Empty;
            if (EnableBackgroundColor)
            {
                bodyStyleStr = GlobalConfig.GetDefaultBackgroundColor();
            }
            //else if (EnableLightBackgroundColor)
            //{
            //    bodyStyleStr = GlobalConfig.GetLightBackgroundColor(PageManager.Instance.Theme.ToString());
            //}

            if (!String.IsNullOrEmpty(bodyStyleStr))
            {
                bodyStyleStr = String.Format("background-color:{0};", bodyStyleStr);
            }
            #endregion


            string   defaultColumnWidthStr = (1.0 / columnCount).ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
            string[] columnWidths          = ResolveColumnWidths(columnCount, Rows[startLineIndex].ColumnWidths, defaultColumnWidthStr);

            // row_column
            JsArrayBuilder rowColumnScriptsBuilder = new JsArrayBuilder();
            for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
            {
                #region 计算每一列的值

                // 循环每一列
                JsArrayBuilder fieldsAB = new JsArrayBuilder();
                for (int rowIndex = startLineIndex; rowIndex <= endLineIndex; rowIndex++)
                {
                    FormRow currentRow = Rows[rowIndex];

                    if (columnIndex <= GetRowColumnCount(currentRow) - 1)
                    {
                        ControlBase component = GetRowColumnControl(currentRow, columnIndex);
                        if (component != null)
                        {
                            fieldsAB.AddProperty(String.Format("{0}", component.XID), true);
                        }
                    }
                }

                // 当前列的创建JS
                JsObjectBuilder columnOB    = new JsObjectBuilder();
                string          columnWidth = columnWidths[columnIndex];
                if (Convert.ToDouble(columnWidth) <= 1.0)
                {
                    columnOB.AddProperty("columnWidth", columnWidths[columnIndex], true);
                }
                else
                {
                    columnOB.AddProperty("width", columnWidths[columnIndex], true);
                }

                columnOB.AddProperty("layout", "form");
                columnOB.AddProperty("border", false);
                columnOB.AddProperty("bodyStyle", bodyStyleStr);
                columnOB.AddProperty("labelWidth", LabelWidth.Value);
                columnOB.AddProperty("id", rowId + "_column" + columnIndex.ToString());

                // 有可能为空
                if (fieldsAB.Count > 0)
                {
                    columnOB.AddProperty("items", fieldsAB.ToString(), true);
                }


                rowColumnScriptsBuilder.AddProperty(columnOB.ToString(), true);

                // 现在采取的是安全的ajax,不会出现下面的情况
                //// 所有Layout=form的地方必须用Ext.FormPanel,否则删除时不会把FieldLabek删除掉
                //rowColumnScriptsBuilder.AddProperty(String.Format("new Ext.FormPanel({0})", columnOB.ToString()), true);

                #endregion
            }

            // 外面的JS(X.__Panel1_UpdatePanelConnector1_Panel7_Form5_row0)
            JsObjectBuilder rowBuilder = new JsObjectBuilder();
            rowBuilder.AddProperty("layout", "column");
            rowBuilder.AddProperty("border", false);
            rowBuilder.AddProperty("bodyStyle", bodyStyleStr);

            // 有可能为空
            if (rowColumnScriptsBuilder.Count > 0)
            {
                rowBuilder.AddProperty("items", rowColumnScriptsBuilder.ToString(), true);
            }


            // 把当前节点添加到结果集合中
            rowIdsBuilder.AddProperty(String.Format("{0}", rowId), true);
            rowBuilder.AddProperty("id", rowId);

            // 注意要注册 最后 一个 Row的脚本
            return(String.Format("var {0}=new Ext.Panel({1});", rowId, rowBuilder.ToString()));
        }
示例#15
0
文件: Form.cs 项目: g992com/esb
        /// <summary>
        /// 添加列
        /// </summary>
        /// <param name="ab"></param>
        /// <param name="startLineIndex">开始行的索引(包含)</param>
        /// <param name="endLineIndex">结束行的索引(包含)</param>
        /// <param name="columnCount">行的列数</param>
        private string AddColumnScript(JsArrayBuilder rowIdsBuilder, int startLineIndex, int endLineIndex, int columnCount)
        {
            // 注意,注册脚本的控件应该是最后一个 Row
            // 假如有从上之下这些控件: Row1(Field1,Field2), Row2(Field3,Field4),Row3(Field5)
            // 则渲染时,JS脚本的执行顺序为:Field1,Field2,Row1,Field3,Field4,Row2,Field5,Row3
            // 所以,如果column Panel的脚本注册为控件 Row3,则能保证所有的子控件已经初始化
            // 需要注意的是:在此设置脚本内容到 Row3 控件
            // 现在已经不是这样的了!!!,Row不在是一个控件

            #region examples


            //            {
            //                    layout: 'column',
            //                    border:false,
            //                    items:[{
            //                        columnWidth: .5,
            //                        layout: 'form',
            //                        border:false,
            //                        items:[{
            //                            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%'
            //                        }]
            //                    },{
            //                        columnWidth: .5,
            //                        layout: 'form',
            //                        border:false,
            //                        items:[{
            //                            xtype:'combo',
            //                            store: executePersonStore,
            //                            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: 'executePerson',
            //                            anchor:'95%'
            //                        }]
            //                    }]
            //          }


            #endregion


            // 最后一行
            FormRow endLineRow = Rows[endLineIndex];
            string rowId = String.Format("{0}_row{1}", XID, endLineIndex);



            #region bodyStyleStr

            // 如果Form有背景色,这里也增加背景色
            string bodyStyleStr = String.Empty;
            if (EnableBackgroundColor)
            {
                bodyStyleStr = GlobalConfig.GetDefaultBackgroundColor();
            }
            //else if (EnableLightBackgroundColor)
            //{
            //    bodyStyleStr = GlobalConfig.GetLightBackgroundColor(PageManager.Instance.Theme.ToString());
            //}

            if (!String.IsNullOrEmpty(bodyStyleStr))
            {
                bodyStyleStr = String.Format("background-color:{0};", bodyStyleStr);
            }
            #endregion


            string defaultColumnWidthStr = (1.0 / columnCount).ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
            string[] columnWidths = ResolveColumnWidths(columnCount, Rows[startLineIndex].ColumnWidths, defaultColumnWidthStr);

            // row_column
            JsArrayBuilder rowColumnScriptsBuilder = new JsArrayBuilder();
            for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
            {
                #region 计算每一列的值

                // 循环每一列
                JsArrayBuilder fieldsAB = new JsArrayBuilder();
                for (int rowIndex = startLineIndex; rowIndex <= endLineIndex; rowIndex++)
                {
                    FormRow currentRow = Rows[rowIndex];

                    if (columnIndex <= GetRowColumnCount(currentRow) - 1)
                    {
                        ControlBase component = GetRowColumnControl(currentRow, columnIndex);
                        if (component != null)
                        {
                            fieldsAB.AddProperty(String.Format("{0}", component.XID), true);
                        }
                    }
                }

                // 当前列的创建JS
                JsObjectBuilder columnOB = new JsObjectBuilder();
                string columnWidth = columnWidths[columnIndex];
                if (Convert.ToDouble(columnWidth) <= 1.0)
                {
                    columnOB.AddProperty("columnWidth", columnWidths[columnIndex], true);
                }
                else
                {
                    columnOB.AddProperty("width", columnWidths[columnIndex], true);
                }

                columnOB.AddProperty("layout", "form");
                columnOB.AddProperty("border", false);
                columnOB.AddProperty("bodyStyle", bodyStyleStr);
                columnOB.AddProperty("labelWidth", LabelWidth.Value);
                columnOB.AddProperty("id", rowId + "_column" + columnIndex.ToString());

                // 有可能为空
                if (fieldsAB.Count > 0)
                {
                    columnOB.AddProperty("items", fieldsAB.ToString(), true);
                }


                rowColumnScriptsBuilder.AddProperty(columnOB.ToString(), true);

                // 现在采取的是安全的ajax,不会出现下面的情况
                //// 所有Layout=form的地方必须用Ext.FormPanel,否则删除时不会把FieldLabek删除掉
                //rowColumnScriptsBuilder.AddProperty(String.Format("new Ext.FormPanel({0})", columnOB.ToString()), true);

                #endregion
            }

            // 外面的JS(X.__Panel1_UpdatePanelConnector1_Panel7_Form5_row0)
            JsObjectBuilder rowBuilder = new JsObjectBuilder();
            rowBuilder.AddProperty("layout", "column");
            rowBuilder.AddProperty("border", false);
            rowBuilder.AddProperty("bodyStyle", bodyStyleStr);

            // 有可能为空
            if (rowColumnScriptsBuilder.Count > 0)
            {
                rowBuilder.AddProperty("items", rowColumnScriptsBuilder.ToString(), true);
            }


            // 把当前节点添加到结果集合中
            rowIdsBuilder.AddProperty(String.Format("{0}", rowId), true);
            rowBuilder.AddProperty("id", rowId);

            // 注意要注册 最后 一个 Row的脚本
            return String.Format("var {0}=new Ext.Panel({1});", rowId, rowBuilder.ToString());
        }