/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); #region Regions if (Regions.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Region item in Regions) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } #endregion string jsContent = String.Format("var {0}=Ext.create('Ext.panel.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); }
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 jsContent = String.Format("var {0}=new Ext.Panel({1});", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); #region Reset ActiveIndex // 重置面板的 Collapsed 属性 if (ActivePane != null) { foreach (AccordionPane pane in Panes) { pane.Collapsed = true; } ActivePane.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 OB.RemoveProperty("layout"); JsObjectBuilder configBuilder = new JsObjectBuilder(); configBuilder.AddProperty("animate", false); configBuilder.AddProperty("activeOnTop", EnableActiveOnTop); configBuilder.AddProperty("fill", EnableFill); configBuilder.AddProperty("hideCollapseTool", !ShowCollapseTool); configBuilder.AddProperty("type", "accordion"); //configBuilder.AddProperty("multi", true); OB.AddProperty("layout", configBuilder); #endregion string jsContent = String.Format("var {0}=Ext.create('Ext.panel.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); if (EnableFrame) { OB.AddProperty("frame", true); } #region Items // 如果是 ContentPanel, 启用 IFrame 或者包含 Content, 则不生成 items if (RenderChildrenAsContent || EnableIFrame || (Content != null)) { if (RenderChildrenAsContent || (Content != null)) { OB.AddProperty("contentEl", String.Format("{0}", ContentID)); } } else { if (Items.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in Items) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } } #endregion #region Toolbars //JsArrayBuilder dockItems = new JsArrayBuilder(); //foreach (Toolbar bar in Toolbars) //{ // dockItems.AddProperty(bar.XID, true); //} //if (this is Grid) //{ // Grid grid = this as Grid; // if (grid.AllowPaging) // { // dockItems.AddProperty(grid.Render_PagingID, true); // } //} Dictionary <string, JsArrayBuilder> bars = new Dictionary <string, JsArrayBuilder>(); foreach (Toolbar bar in Toolbars) { string barPosition = ToolbarPositionHelper.GetExtName(bar.Position); if (!bars.ContainsKey(barPosition)) { bars[barPosition] = new JsArrayBuilder(); } bars[barPosition].AddProperty(bar.XID, true); } // 将底部工具栏的顺序反转 if (bars.ContainsKey("bottom")) { bars["bottom"].Reverse(); } // 表格的分页工具栏 if (this is Grid) { Grid grid = this as Grid; if (grid.AllowPaging) { if (!bars.ContainsKey("bottom")) { bars["bottom"] = new JsArrayBuilder(); } bars["bottom"].AddProperty(grid.Render_PagingID, true); } } JsArrayBuilder dockItems = new JsArrayBuilder(); foreach (string barPosition in bars.Keys) { foreach (string barItem in bars[barPosition].Properties) { dockItems.AddProperty(barItem, true); } } OB.AddProperty("dockedItems", dockItems); #endregion #region BodyStyle/ShowBorder string bodyStyleStr = BodyStyle; if (!bodyStyleStr.Contains("padding")) { if (!String.IsNullOrEmpty(BodyPadding)) { bodyStyleStr += String.Format("padding:{0};", StyleUtil.GetMarginPaddingStyle(BodyPadding)); } } //if (EnableBackgroundColor) //{ // if (!bodyStyleStr.Contains("background-color")) // { // string backgroundColorStyleStr = GlobalConfig.GetDefaultBackgroundColor(); // if (!String.IsNullOrEmpty(backgroundColorStyleStr)) // { // bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr); // } // } //} OB.AddProperty("bodyStyle", bodyStyleStr); OB.AddProperty("border", ShowBorder); #endregion #region MinHeight/MinHeight if (MinHeight != Unit.Empty) { OB.AddProperty("minHeight", MinHeight.Value); } if (MinWidth != Unit.Empty) { OB.AddProperty("minWidth", MinWidth.Value); } if (MaxHeight != Unit.Empty) { OB.AddProperty("maxHeight", MaxHeight.Value); } if (MaxWidth != Unit.Empty) { OB.AddProperty("maxWidth", MaxWidth.Value); } //// 对于Panel,如果宽度/高度没有定义 //if (Width == Unit.Empty && AutoWidth) //{ // OB.AddProperty("autoWidth", true); //} //if (Height == Unit.Empty && AutoHeight) //{ // OB.AddProperty("autoHeight", true); //} //// 如果父控件是容器控件(不是ContentPanel),并且Layout != LayoutType.Container, //// 则设置AutoWidth/AutoHeight都为false //if (Parent is PanelBase) //{ // PanelBase parent = Parent as PanelBase; // if (!(parent is ContentPanel) && parent.Layout != Layout.Container) // { // OB.RemoveProperty("autoHeight"); // OB.RemoveProperty("autoWidth"); // } //} if (AutoScroll) { OB.AddProperty("autoScroll", true); } #region old code //// 如果是 PageLayout 中的Panel,不能设置AutoWidth //if (Parent is PageLayout) //{ // // region // if (Region != Region_Default) OB.AddProperty(OptionName.Region, RegionTypeName.GetName(Region.Value)); //} //else //{ // // 对于Panel,如果宽度/高度没有定义,则使用自动宽度和高度 // if (Width == Unit.Empty) // { // OB.AddProperty(OptionName.AutoWidth, true); // } // if (Height == Unit.Empty) // { // OB.AddProperty(OptionName.AutoHeight, true); // } //} //// 如果父控件是容器控件,并且Layout=Fit,则设置AutoWidth/AutoHeight都为false //if (Parent is PanelBase) //{ // PanelBase parentPanel = Parent as PanelBase; // if (parentPanel.Layout == LayoutType.Fit // || parentPanel.Layout == LayoutType.Anchor // || parentPanel.Layout == LayoutType.Border) // { // OB.RemoveProperty(OptionName.AutoHeight); // OB.RemoveProperty(OptionName.AutoWidth); // } //} #endregion #endregion #region EnableIFrame if (EnableIFrame) { #region old code //string iframeJsContent = String.Empty; //string frameUrl = ResolveUrl(IFrameUrl); //JsObjectBuilder iframeBuilder = new JsObjectBuilder(); //if (IFrameDelayLoad) //{ // iframeBuilder.AddProperty(OptionName.Src, "#"); //} //else //{ // iframeBuilder.AddProperty(OptionName.Src, frameUrl); //} //iframeBuilder.AddProperty(OptionName.LoadMask, false); //iframeJsContent += String.Format("var {0}=new Ext.ux.ManagedIFrame('{0}',{1});", IFrameID, iframeBuilder.ToString()); //if (IFrameDelayLoad) //{ // iframeJsContent += String.Format("{0}_url='{1}';", IFrameID, frameUrl); //} //iframeJsContent += "\r\n"; //AddStartupScript(this, iframeJsContent); #endregion // 注意: // 如下依附于现有对象的属性名称的定义规则:x_property1 // 存储于当前对象实例中 OB.AddProperty("f_iframe", true); OB.AddProperty("f_iframe_url", IFrameUrl); OB.AddProperty("f_iframe_name", IFrameName); // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 if (!String.IsNullOrEmpty(IFrameUrl)) { //_writeIframeToHtmlDocument = true; OB.AddProperty("f_iframe_loaded", true); // 直接添加iframe属性 OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); } else { //_writeIframeToHtmlDocument = false; OB.AddProperty("f_iframe_loaded", false); } #region old code //// If current panel is Tab, then process the IFrameDelayLoad property. //Tab tab = this as Tab; //if (tab != null && tab.IFrameDelayLoad) //{ // // 如果是Tab,并且此Tab不是激活的,则不添加iframe // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); //} //else //{ // // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 // if (!String.IsNullOrEmpty(IFrameUrl)) // { // //_writeIframeToHtmlDocument = true; // OB.AddProperty("box_property_iframe_loaded", true); // // 直接添加iframe属性 // OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); // } // else // { // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); // } //} #endregion } #endregion #region RoundBorder //if (RoundBorder) OB.AddProperty(OptionName.Frame, true); #endregion #region oldcode //if (EnableLargeHeader) //{ // OB.AddProperty("cls", "f-panel-big-header"); //} //OB.AddProperty("animCollapse", false); #endregion #region ContentEl //string finallyScript = String.Empty; if (RenderChildrenAsContent) { OB.AddProperty("contentEl", ContentID); // 在页面元素渲染完成后,才显示容器控件的内容 //string renderScript = String.Format("Ext.get('{0}').show();", ContentID); //OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript), true); //string beforerenderScript = String.Format("Ext.get('{0}').setStyle('display','');", ChildrenContentID); //OB.Listeners.AddProperty("beforerender", "function(component){" + beforerenderScript + "}", true); // 这一段的逻辑(2008-9-1): // 如果是页面第一次加载 + 此Panel在Tab中 + 此Tab不是当前激活Tab + 此Tab的TabStrip启用了延迟加载 // 那么在页面加载完毕后,把此Panel给隐藏掉,等此Panel渲染到页面中时再显示出来 //Tab tab = ControlUtil.FindParentControl(this, typeof(Tab)) as Tab; //if (tab != null) //{ // TabStrip tabStrip = tab.Parent as TabStrip; // if (tabStrip.EnableDeferredRender && tabStrip.Tabs[tabStrip.ActiveTabIndex] != tab) // { // // 页面第一次加载时,在显示(控件的render事件)之前要先隐藏 // AddStartupAbsoluteScript(String.Format("Ext.get('{0}').setStyle('display','none');", ContentID)); // } //} } #endregion }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); OB.AddProperty("border", false); OB.AddProperty("header", false); Form parentForm = Parent as Form; if (parentForm == null) { return; } int formrowItemsSpace = Convert.ToInt32(parentForm.FormRowItemsSpace.Value); if (Items.Count > 0) { #region oldcode /* * 增加中间的分割面板,会对显示隐藏表单字段造成影响 int currentItemCount = 0; JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in Items) { if (item.Visible) { if (currentItemCount > 0) { OptionBuilder separatorOB = new OptionBuilder(); separatorOB.AddProperty("type", "panelbase"); separatorOB.AddProperty("width", 8); ab.AddProperty(String.Format("{0}", separatorOB), true); } ab.AddProperty(String.Format("{0}", item.XID), true); currentItemCount++; } } OB.AddProperty("items", ab.ToString(), true); */ #endregion // 为子项添加布局属性 int columnCount = Items.Count; string defaultColumnWidthStr = (1.0 / columnCount).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); List<string> columnWidths = GetTrimedColumnWidths(); // 用户自定义ColumnWidths是否和Items的个数匹配 bool isColumnWidthsMatch = false; if (columnWidths.Count == columnCount) { isColumnWidthsMatch = true; } Dictionary<string, JsObjectBuilder> buttonOptions = new Dictionary<string, JsObjectBuilder>(); for (int i = 0; i < columnCount; i++) { var comp = Items[i] as Component; // 如果FormRow的子项是 Button,则用一个面板将其包裹起来,否则按钮的宽度会很长 bool isbutton = false; JsObjectBuilder buttonPanelOB = new JsObjectBuilder(); if (comp is Button) { isbutton = true; buttonPanelOB.AddProperty("xtype", "panel"); buttonPanelOB.AddProperty("header", false); buttonPanelOB.AddProperty("border", false); buttonPanelOB.AddProperty("items", String.Format("[{0}]", comp.XID), true); } #region Component if (comp != null) { // 不是最后一列的话,加上空白间隔 if (columnCount > 1 && i != columnCount - 1) { if (isbutton) { //buttonOB.AddProperty("marginRight", formrowItemsSpace); buttonPanelOB.AddProperty("style", String.Format("margin-right:{0}px;", formrowItemsSpace)); } else { //// 如果尚未设置 MarginRight //if (comp.MarginRight == Unit.Empty) //{ // comp.MarginRight = Unit.Pixel(formrowItemsSpace); //} //if (String.IsNullOrEmpty(comp.Margin)) //{ // comp.Margin = String.Format("0 {0} 0 0", formrowItemsSpace); //} comp.CssStyle += String.Format("margin-right:{0}px;", formrowItemsSpace); } } } #endregion #region BoxComponent var boxcomp = comp as BoxComponent; if (boxcomp != null) { if (isColumnWidthsMatch) { string columnWidth = StringUtil.ConvertPercentageToDecimalString(columnWidths[i]); if (Convert.ToDouble(columnWidth) <= 1.0) { if (isbutton) { buttonPanelOB.AddProperty("columnWidth", columnWidth, true); } else { boxcomp.ColumnWidth = columnWidth; } } else { Unit unitColumnWidth = Unit.Parse(columnWidth); if (isbutton) { buttonPanelOB.AddProperty("width", unitColumnWidth.Value); } else { boxcomp.Width = unitColumnWidth; } } } else { if (isbutton) { buttonPanelOB.AddProperty("columnWidth", defaultColumnWidthStr, true); } else { boxcomp.ColumnWidth = defaultColumnWidthStr; } } } #endregion if (isbutton) { buttonOptions.Add(comp.XID, buttonPanelOB); } } JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in Items) { if (item.Visible) { string itemXID = item.XID; if (buttonOptions.ContainsKey(itemXID)) { itemXID = buttonOptions[itemXID].ToString(); } ab.AddProperty(itemXID, true); } } OB.AddProperty("items", ab.ToString(), true); } // 自定义样式 OB.AddProperty("cls", "f-formrow"); string jsContent = String.Format("var {0}=Ext.create('Ext.panel.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); ////// 目的:子控件的JS代码在父控件的前面 ////AddStartupScript(this, String.Empty); //AddStartupScript(String.Empty); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); if (EnableFrame) { OB.AddProperty("frame", true); } #region Items // 如果是 ContentPanel 或者启用 IFrame,则不生成 items if (!RenderChildrenAsContent && !EnableIFrame) { if (Items.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in Items) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } } #endregion #region Toolbars foreach (Toolbar bar in Toolbars) { string toolbarID = String.Format("{0}", bar.XID); string barKey = ToolbarPositionHelper.GetName(bar.Position); OB.AddProperty(barKey, toolbarID, true); } #endregion #region BodyStyle/ShowBorder string bodyStyleStr = BodyStyle; if (!bodyStyleStr.Contains("padding")) { if (!String.IsNullOrEmpty(BodyPadding)) { bodyStyleStr += String.Format("padding:{0};", BodyPadding); } } //if (EnableBackgroundColor) //{ // if (!bodyStyleStr.Contains("background-color")) // { // string backgroundColorStyleStr = GlobalConfig.GetDefaultBackgroundColor(); // if (!String.IsNullOrEmpty(backgroundColorStyleStr)) // { // bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr); // } // } //} OB.AddProperty("bodyStyle", bodyStyleStr); OB.AddProperty("border", ShowBorder); #endregion #region Width/Height //// 对于Panel,如果宽度/高度没有定义 //if (Width == Unit.Empty && AutoWidth) //{ // OB.AddProperty("autoWidth", true); //} //if (Height == Unit.Empty && AutoHeight) //{ // OB.AddProperty("autoHeight", true); //} //// 如果父控件是容器控件(不是ContentPanel),并且Layout != LayoutType.Container, //// 则设置AutoWidth/AutoHeight都为false //if (Parent is PanelBase) //{ // PanelBase parent = Parent as PanelBase; // if (!(parent is ContentPanel) && parent.Layout != Layout.Container) // { // OB.RemoveProperty("autoHeight"); // OB.RemoveProperty("autoWidth"); // } //} if (AutoScroll) { OB.AddProperty("autoScroll", true); } #region old code //// 如果是 PageLayout 中的Panel,不能设置AutoWidth //if (Parent is PageLayout) //{ // // region // if (Region != Region_Default) OB.AddProperty(OptionName.Region, RegionTypeName.GetName(Region.Value)); //} //else //{ // // 对于Panel,如果宽度/高度没有定义,则使用自动宽度和高度 // if (Width == Unit.Empty) // { // OB.AddProperty(OptionName.AutoWidth, true); // } // if (Height == Unit.Empty) // { // OB.AddProperty(OptionName.AutoHeight, true); // } //} //// 如果父控件是容器控件,并且Layout=Fit,则设置AutoWidth/AutoHeight都为false //if (Parent is PanelBase) //{ // PanelBase parentPanel = Parent as PanelBase; // if (parentPanel.Layout == LayoutType.Fit // || parentPanel.Layout == LayoutType.Anchor // || parentPanel.Layout == LayoutType.Border) // { // OB.RemoveProperty(OptionName.AutoHeight); // OB.RemoveProperty(OptionName.AutoWidth); // } //} #endregion #endregion #region EnableIFrame if (EnableIFrame) { #region old code //string iframeJsContent = String.Empty; //string frameUrl = ResolveUrl(IFrameUrl); //JsObjectBuilder iframeBuilder = new JsObjectBuilder(); //if (IFrameDelayLoad) //{ // iframeBuilder.AddProperty(OptionName.Src, "#"); //} //else //{ // iframeBuilder.AddProperty(OptionName.Src, frameUrl); //} //iframeBuilder.AddProperty(OptionName.LoadMask, false); //iframeJsContent += String.Format("var {0}=new Ext.ux.ManagedIFrame('{0}',{1});", IFrameID, iframeBuilder.ToString()); //if (IFrameDelayLoad) //{ // iframeJsContent += String.Format("{0}_url='{1}';", IFrameID, frameUrl); //} //iframeJsContent += "\r\n"; //AddStartupScript(this, iframeJsContent); #endregion // 注意: // 如下依附于现有对象的属性名称的定义规则:x_property1 // 存储于当前对象实例中 OB.AddProperty("f_iframe", true); OB.AddProperty("f_iframe_url", IFrameUrl); OB.AddProperty("f_iframe_name", IFrameName); // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 if (!String.IsNullOrEmpty(IFrameUrl)) { //_writeIframeToHtmlDocument = true; OB.AddProperty("f_iframe_loaded", true); // 直接添加iframe属性 OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); } else { //_writeIframeToHtmlDocument = false; OB.AddProperty("f_iframe_loaded", false); } #region old code //// If current panel is Tab, then process the IFrameDelayLoad property. //Tab tab = this as Tab; //if (tab != null && tab.IFrameDelayLoad) //{ // // 如果是Tab,并且此Tab不是激活的,则不添加iframe // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); //} //else //{ // // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 // if (!String.IsNullOrEmpty(IFrameUrl)) // { // //_writeIframeToHtmlDocument = true; // OB.AddProperty("box_property_iframe_loaded", true); // // 直接添加iframe属性 // OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); // } // else // { // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); // } //} #endregion } #endregion #region RoundBorder //if (RoundBorder) OB.AddProperty(OptionName.Frame, true); #endregion #region oldcode //if (EnableLargeHeader) //{ // OB.AddProperty("cls", "f-panel-big-header"); //} //OB.AddProperty("animCollapse", false); #endregion #region ContentEl //string finallyScript = String.Empty; if (RenderChildrenAsContent) { OB.AddProperty("contentEl", ContentID); // 在页面元素渲染完成后,才显示容器控件的内容 //string renderScript = String.Format("Ext.get('{0}').show();", ContentID); //OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript), true); //string beforerenderScript = String.Format("Ext.get('{0}').setStyle('display','');", ChildrenContentID); //OB.Listeners.AddProperty("beforerender", "function(component){" + beforerenderScript + "}", true); // 这一段的逻辑(2008-9-1): // 如果是页面第一次加载 + 此Panel在Tab中 + 此Tab不是当前激活Tab + 此Tab的TabStrip启用了延迟加载 // 那么在页面加载完毕后,把此Panel给隐藏掉,等此Panel渲染到页面中时再显示出来 Tab tab = ControlUtil.FindParentControl(this, typeof(Tab)) as Tab; if (tab != null) { TabStrip tabStrip = tab.Parent as TabStrip; if (tabStrip.EnableDeferredRender && tabStrip.Tabs[tabStrip.ActiveTabIndex] != tab) { // 页面第一次加载时,在显示(控件的render事件)之前要先隐藏 AddStartupAbsoluteScript(String.Format("Ext.get('{0}').setStyle('display','none');", ContentID)); } } } #endregion }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("tab"); //if (EnableTabCloseMenu) //{ // ResourceManager.Instance.AddJavaScriptComponent("menu"); //} #region Tabs if (Tabs.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Tab tab in Tabs) { if (tab.Visible) { ab.AddProperty(String.Format("{0}", tab.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } #endregion #region options // 删除Layout配置参数 OB.RemoveProperty("layout"); //OB.AddProperty(OptionName.TabMargin, TabMargin.Value); OB.AddProperty("tabPosition", TabPositionHelper.GetName(TabPosition)); //if (!EnableTitleBackgroundColor) //{ // OB.AddProperty("plain", true); //} // 全部渲染,否则没有访问的Tab的内容渲染的位置不正确。 OB.AddProperty("deferredRender", false); //OB.AddProperty("bufferResize", true); //// 在切换Tab时重新布局Tab的内容 //OB.AddProperty("layoutOnTabChange", true); //OB.AddProperty("enableTabScroll", true); if (EnableTabCloseMenu) { OB.AddProperty("plugins", "Ext.create('Ext.ux.TabCloseMenu')", true); } ////Note: By default, a tab's close tool destroys the child tab Component and all its descendants. //// This makes the child tab Component, and all its descendants unusable. //// To enable re-use of a tab, configure the TabPanel with autoDestroy: false. //OB.AddProperty("autoDestroy", false); #endregion #region ActiveTabIndex/IFrameDelayLoad OB.AddProperty("activeTab", ActiveTabIndex); //for (int i = 0; i < Tabs.Count; i++) //{ // Tab tab = Tabs[i]; // if (tab.EnableIFrame && i != ActiveTabIndex) // { // // 拥有IFrame的Tab如果不是激活Tab,则不设置Url,只有在激活时才设置Url // tab.IFrameDelayLoad = true; // } // else // { // tab.IFrameDelayLoad = false; // } //} #endregion #region Listeners #region old code // 如果存在Tabs集合 //if (Tabs.Count > 0) //{ // JsArrayBuilder ab = new JsArrayBuilder(); // foreach (Tab tab in Tabs) // { // ab.AddProperty(String.Format("{0}", tab.ClientID), true); // } // OB.AddProperty(OptionName.Items, ab.ToString(), true); //} // listeners //JsObjectBuilder listenersBuilder = new JsObjectBuilder(); //listenersBuilder.AddProperty(OptionName.Tabchange, String.Format("function(tabPanel, activeTab){{Ext.get('{0}').dom.value=tabPanel.items.indexOf(activeTab);}}", ActiveTabHiddenField.ClientID), true); //OBuilder.AddProperty("listeners", listenersBuilder.ToString(), true); #endregion // 如果要激活的Tab含有IFrame,则需要加载IFrame // 改变Tab需要回发的脚本 // Make sure X_AutoPostBackTabs property exist in F_STATE during page's first load. //string tabchangeScript2 = String.Format("if(tabPanel.f_autoPostBackTabsContains(tab.id)){{{0}}}", GetPostBackEventReference()); string tabchangeScript = "F.wnd.updateIFrameNode(tab);"; string postbackScript = String.Empty; if (AutoPostBack) { tabchangeScript += "if(!tab.f_dynamic_added_tab){" + GetPostBackEventReference("TabIndexChanged") + "}"; } // 如果是动态添加的Tab,不做任何处理(在js/box/extender.js中) //string tabchangeScript = "F.wnd.updateIFrameNode(tab);if(!tab.f_dynamic_added_tab){" + postbackScript + "}"; //OB.Listeners.AddProperty("tabchange", JsHelper.GetFunction(tabchangeScript, "tabPanel", "tab"), true); AddListener("tabchange", tabchangeScript, "tabPanel", "tab"); #endregion #region old code //// 添加隐藏字段 //string needPostBackTabIDsScript = GetNeedPostBackTabIDsScript(); //hiddenFieldsScript += needPostBackTabIDsScript; //if (AjaxPropertyChanged("NeedPostBackTabIdsScript", needPostBackTabIDsScript)) //{ // AddAjaxPropertyChangedScript(needPostBackTabIDsScript); //} //hiddenFieldsScript += GetSetHiddenFieldValueScript(ActiveTabHiddenFieldID, ActiveTabIndex.ToString().ToLower()); #endregion #region old code //// An bug in IE. //string renderScript = "if(Ext.isIE){(function(){this.getActiveTab().removeClass('x-hide-display');}).defer(20,this);}"; //OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript), true); #endregion string jsContent = String.Format("var {0}=Ext.create('Ext.tab.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); #region Regions if (Regions.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Region item in Regions) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } #endregion string jsContent = String.Format("var {0}=Ext.create('Ext.panel.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 获取按钮客户端点击事件的脚本 /// </summary> /// <param name="validateForms">验证表单列表</param> /// <param name="validateTarget">表单验证提示消息目标页面</param> /// <param name="validateMessageBox">是否显示表单验证提示对话框</param> /// <param name="enablePostBack">启用回发</param> /// <param name="postBackEventReference">回发脚本</param> /// <param name="confirmText">确认对话框消息</param> /// <param name="confirmTitle">确认对话框标题</param> /// <param name="confirmIcon">确认对话框图标</param> /// <param name="confirmTarget">确认对话框目标页面</param> /// <param name="onClientClick">自定义客户端点击脚本</param> /// <param name="disableControlJavascriptID">需要禁用的控件客户端ID</param> /// <returns>客户端脚本</returns> internal static string ResolveClientScript(string[] validateForms, Target validateTarget, bool validateMessageBox, bool enablePostBack, string postBackEventReference, string confirmText, string confirmTitle, MessageBoxIcon confirmIcon, Target confirmTarget, string onClientClick, string disableControlJavascriptID) { // 1. 表单验证 string validateScript = String.Empty; if (validateForms != null && validateForms.Length > 0) { JsArrayBuilder array = new JsArrayBuilder(); foreach (string formID in validateForms) { Control control = ControlUtil.FindControl(formID); if (control != null && control is ControlBase) { array.AddProperty((control as ControlBase).ClientID); } } validateScript = String.Format("if(!X.util.validForms({0},'{1}',{2})){{return false;}}", array.ToString(), TargetHelper.GetName(validateTarget), validateMessageBox.ToString().ToLower()); } // 2. 用户自定义脚本 string clientClickScript = onClientClick; if (!String.IsNullOrEmpty(clientClickScript) && !clientClickScript.EndsWith(";")) { clientClickScript += ";"; } // 3. 回发脚本 string postBackScript = String.Empty; if (enablePostBack) { if (!String.IsNullOrEmpty(disableControlJavascriptID)) { postBackScript += String.Format("X.disable('{0}');", disableControlJavascriptID); } postBackScript += postBackEventReference; } // 确认对话框 if (!String.IsNullOrEmpty(confirmText)) { postBackScript = Confirm.GetShowReference(confirmText, confirmTitle, confirmIcon, postBackScript, "", confirmTarget); } return(validateScript + clientClickScript + postBackScript); }
/// <summary> /// 处理列 /// </summary> /// <returns></returns> private void ResolveRows(ref string rowScriptsStr, ref string rowIdsStr) { JsArrayBuilder rowIdsBuilder = new JsArrayBuilder(); // 上一行的列数 int lastRowColumnCount = 1; // 上一行的列数 string lastRowColumnWidths = String.Empty; // 是否已经开始多列 bool isMultiColumnStarted = false; // 多列的开始行的序号 int multiColumnStartLineIndex = 0; for (int i = 0, rowCount = Rows.Count; i < rowCount; i++) { FormRow currentRow = Rows[i]; int currentRowColumnCount = GetRowColumnCount(currentRow); string currentRowColumnWidths = currentRow.ColumnWidths; if (currentRowColumnCount == 0) { // 如果当前行为空,则跳过此行 continue; } else if (currentRowColumnCount == 1) { if (isMultiColumnStarted) { // 如果上一行是多列行,则添加本行之上的所有行 rowScriptsStr += AddColumnScript(rowIdsBuilder, multiColumnStartLineIndex, i - 1, lastRowColumnCount); //rowScriptsStr += "\r\n"; // 开始重置记录本行为多列的开始 isMultiColumnStarted = false; multiColumnStartLineIndex = 0; } // 如果当前行的列数为1,则直接添加Field元素 //AddItemScript(ab, currentRow.Fields[0].ClientID); ControlBase component = GetRowColumnControl(currentRow, 0); if (component != null) { rowIdsBuilder.AddProperty(String.Format("{0}", component.XID), true); } } else { // 如果本行是多列 if (!isMultiColumnStarted) { // 如果上一行还是单列的话,则开始多列 isMultiColumnStarted = true; multiColumnStartLineIndex = i; } else { if (lastRowColumnCount == currentRowColumnCount && lastRowColumnWidths == currentRowColumnWidths) { // 如果上一行的列数和本行的列数相同(并且上一行每列的宽度和本行的每列宽度也一样),则继续下一行 } else { // 如果上一行的列数和本行的列数不相同,则添加本行之上的所有行 rowScriptsStr += AddColumnScript(rowIdsBuilder, multiColumnStartLineIndex, i - 1, lastRowColumnCount); //rowScriptsStr += "\r\n"; // 开始重新记录本行为多列的开始 isMultiColumnStarted = true; multiColumnStartLineIndex = i; } } } lastRowColumnCount = currentRowColumnCount; lastRowColumnWidths = currentRowColumnWidths; } // 还要判断一下(如果最后一行是两列的情况) if (isMultiColumnStarted) { rowScriptsStr += AddColumnScript(rowIdsBuilder, multiColumnStartLineIndex, Rows.Count - 1, lastRowColumnCount); //rowScriptsStr += "\r\n"; } rowIdsStr = rowIdsBuilder.ToString(); }
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()); }
protected override void OnFirstPreRender() { // 确保 X_Rows 在页面第一次加载时都存在于x_state中 XState.AddModifiedProperty("X_Rows"); // 因为可以在 ASPX 中指定列的 Hidden 属性 // 如果在 ASPX 中指定了列的 Hidden 属性,但是 HiddenColumnIndexArray 不在改变的属性列表中, // 为了在客户端初始化隐藏的列,需要手工将 HiddenColumnIndexArray 添加到改变的属性列表中,以便使其存在于 x_state 属性中。 if (HiddenColumnIndexArray.Length > 0) { XState.AddModifiedProperty("HiddenColumnIndexArray"); } // 不需要手工添加 SelectedRowIndexArray 属性,是因为只能通过代码设置此属性 base.OnFirstPreRender(); ResourceManager.Instance.AddJavaScriptComponent("grid"); // 分页工具栏使用了 Ext.form.NumberField 组件,所以必须引入 form 的JavaScript if (AllowPaging) { ResourceManager.Instance.AddJavaScriptComponent("form"); } //OB.Listeners.AddProperty("rowmousedown", "function(){alert('ok');}", true); string cls = CssClass; #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); } } #endregion #region viewConfig 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 (!String.IsNullOrEmpty(EmptyText)) { viewBuilder.AddProperty("deferEmptyText", false); viewBuilder.AddProperty("emptyText", EmptyText); } if (viewBuilder.Count > 0) { OB.AddProperty("viewConfig", viewBuilder); } #endregion #region Properties if (EnableColumnLines) { OB.AddProperty("columnLines", true); } OB.AddProperty("enableHdMenu", EnableHeaderMenu); if (EnableHeaderMenu) { // 启用标题栏菜单,但是不启用标题栏菜单中的隐藏列功能 if (!EnableColumnHide) { OB.AddProperty("enableColumnHide", 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 EnableRowClickEvent if (EnableRowClickEvent) { 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 (EnableRowDoubleClickEvent) { 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); if (PageItems.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in PageItems) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } pagingBuilder.AddProperty("items", ab.ToString(), 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 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].sortable){return false;}"; headerClickScript += "var args='Sort$'+columnIndex;"; headerClickScript += GetPostBackEventReference("#SORT#").Replace("'#SORT#'", "args"); // 告诉 store 本次排序已经处理了,不要重复处理了 headerClickScript += "cmp.getStore().headerclickprocessed=true;"; //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 (_FineUIAjaxColumnsChanged) //{ // // 如果列都发生了变化,需要重新设置图标 // 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 (_FineUIAjaxColumnsChanged) // { // // 如果列都发生了变化,需要重新需要排序的列,显示为手型的光标 // 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); } if (!AllowCellEditing) { viewreadySB.Append("cmp.x_selectRows();"); } if (EnableTextSelection) { //OB.AddProperty("cls", CssClass + " x-grid-selectable"); cls += " x-grid-selectable"; viewreadySB.Append("cmp.x_enableTextSelection();"); } OB.Listeners.AddProperty("viewready", JsHelper.GetFunction(viewreadySB.ToString(), "cmp"), true); #endregion #region cls if (RowVerticalAlign != VerticalAlign.Middle) { cls += String.Format("row-align-{0}", VerticalAlignName.GetName(RowVerticalAlign)); } cls = cls.Trim(); if (!String.IsNullOrEmpty(cls)) { OB.AddProperty("cls", cls); } #endregion #region Listeners - render StringBuilder renderSB = new StringBuilder(); // 加载表格数据 renderSB.Append("cmp.x_loadData();"); // 隐藏列 if (HiddenColumnIndexArray != null && HiddenColumnIndexArray.Length > 0) { renderSB.Append("cmp.x_updateColumnsHiddenStatus();"); } // 展开所有的行扩展列 if (ExpandAllRowExpanders) { renderSB.Append("cmp.x_expandAllRows();"); } OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderSB.ToString(), "cmp"), true); #endregion #region AllowCellEditing if (AllowCellEditing) { if (ClicksToEdit != 2) { OB.AddProperty("clicksToEdit", ClicksToEdit); } //OB.Listeners.AddProperty("beforeedit", JsHelper.GetFunction("console.log(e);", "e"), true); //OB.Listeners.AddProperty("afteredit", JsHelper.GetFunction("console.log(e);", "e"), true); OB.AddProperty("x_newAddedRows", "[]", true); } #endregion StringBuilder sb = new StringBuilder(); sb.Append(gridSelectModelScript + gridStoreScript + pagingScript + gridColumnsScript); sb.AppendFormat("var {0}=new Ext.grid.{2}({1});", XID, OB, AllowCellEditing ? "EditorGridPanel" : "GridPanel"); 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 }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("form"); #region Options #endregion #region ResolveRows //// 包含行的列脚本 //string rowScriptStr = String.Empty; //// 行的集合 //string rowItemScriptStr = String.Empty; //// 如果存在Rows集合 //if (Rows.Count > 0) //{ // // rowScriptStr // // rowItemScriptStr: [X.__Panel1_UpdatePanelConnector1_Panel7_Form5_row0,X.__Panel1_UpdatePanelConnector1_Panel7_Form5_row2] // ResolveRows(ref rowScriptStr, ref rowItemScriptStr); // // 添加Items // OB.RemoveProperty("items"); // OB.AddProperty("items", rowItemScriptStr, true); //} ////rowScriptStr += "\r\n"; #endregion #region Rows if (Rows.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (FormRow row in Rows) { if (row.Visible) { ab.AddProperty(String.Format("{0}", row.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } #endregion AddListener("dirtychange", "F.util.setPageStateChanged(dirty);", "form", "dirty"); string formPanelScript = String.Format("var {0}=Ext.create('Ext.form.Panel',{1});", XID, OB.ToString()); //string jsContent = rowScriptStr + formPanelScript; AddStartupScript(formPanelScript); }
/// <summary> /// 生成按钮客户端点击事件的脚本 /// </summary> /// <param name="validateForms"></param> /// <param name="validateTarget"></param> /// <param name="enablePostBack"></param> /// <param name="postBackEventReference"></param> /// <param name="confirmText"></param> /// <param name="confirmTitle"></param> /// <param name="confirmIcon"></param> /// <param name="confirmTarget"></param> /// <param name="onClientClick"></param> /// <param name="disableControlJavascriptID"></param> /// <returns></returns> internal static string ResolveClientScript(string[] validateForms, Target validateTarget, bool validateMessageBox, bool enablePostBack, string postBackEventReference, string confirmText, string confirmTitle, MessageBoxIcon confirmIcon, Target confirmTarget, string onClientClick, string disableControlJavascriptID) { // 1. validateScript string validateScript = String.Empty; if (validateForms != null && validateForms.Length > 0) { #region old code //StringBuilder sb = new StringBuilder(); //sb.Append("var forms=[];"); //foreach (string formId in validateForms) //{ // Control control = ControlUtil.FindControl(formId); // if (control != null && control is ControlBase) // { // sb.AppendFormat("forms.push(X.{0});", (control as ControlBase).ClientJavascriptID); // } //} ////sb.Append("if(!box_validForms(forms,'表单不完整','请为 “{0}” 提供有效值!')){return false;}"); //sb.AppendFormat("var validResult=X.util.validForms(forms);if(!validResult[0]){{{0}return false;}}", // Alert.GetShowReference("请为 “'+validResult[1].fieldLabel+'” 提供有效值!", "表单不完整")); #endregion JsArrayBuilder array = new JsArrayBuilder(); foreach (string formID in validateForms) { Control control = ControlUtil.FindControl(formID); if (control != null && control is ControlBase) { array.AddProperty((control as ControlBase).ClientID); } } validateScript = String.Format("if(!X.util.validForms({0},'{1}',{2})){{return false;}}", array.ToString(), TargetHelper.GetName(validateTarget), validateMessageBox.ToString().ToLower()); } // 2. 用户自定义脚本 string clientClickScript = onClientClick; if (!String.IsNullOrEmpty(clientClickScript) && !clientClickScript.EndsWith(";")) { clientClickScript += ";"; } // 3. 回发脚本 string postBackScript = String.Empty; if (enablePostBack) { if (!String.IsNullOrEmpty(disableControlJavascriptID)) { postBackScript += String.Format("X.disable('{0}');", disableControlJavascriptID); //postBackScript += String.Format("X.util.setHiddenFieldValue('{0}','{1}');", ResourceManager.DISABLED_CONTROL_BEFORE_POSTBACK, disableControlClientId); //postBackScript += String.Format("X.util.setDisabledControlBeforePostBack('{0}');", disableControlJavascriptID); } postBackScript += postBackEventReference; } if (!String.IsNullOrEmpty(confirmText)) { #region old code // 对confirm进行处理,对<script></script>包含的内容做js代码处理 //string confirmText = ConfirmText.Replace("'", "\""); //if (confirmText.Contains("<script>")) //{ // confirmText = confirmText.Replace("<script>", "'+"); // confirmText = confirmText.Replace("</script>", "+'"); //} //confirmText = String.Format("'{0}'", confirmText); //JsObjectBuilder ob = new JsObjectBuilder(); //ob.AddProperty(OptionName.Title, String.Format("'{0}'", confirmTitle), true); //ob.AddProperty(OptionName.Msg, String.Format("'{0}'", JsHelper.GetStringWithJsBlock(confirmText)), true); //ob.AddProperty(OptionName.Buttons, "Ext.MessageBox.OKCANCEL", true); //ob.AddProperty(OptionName.Icon, String.Format("'{0}'", MessageBoxIconName.GetName(confirmIcon)), true); //ob.AddProperty(OptionName.Fn, String.Format("function(btn){{if(btn=='cancel'){{return false;}}else{{{0}}}}}", postBackScript), true); //postBackScript = String.Format("Ext.MessageBox.show({0});", ob.ToString()); #endregion postBackScript = Confirm.GetShowReference(confirmText, confirmTitle, confirmIcon, postBackScript, "return false;", confirmTarget); } return validateScript + clientClickScript + postBackScript; }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("toolbar"); #region Items // 重新设置Items if (Controls.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Control item in Controls) { if (item is ControlBase && item.Visible) { #region old code //// 如果是分隔符 //if (item is ToolbarSeparator) //{ // ab.AddProperty("'-'", true); //} //else if (item is ToolbarText) //{ // ab.AddProperty(String.Format("'{0}'", (item as ToolbarText).Text), true); //} //if (item is ToolbarFill) //{ // ab.AddProperty("'->'", true); //} //else //{ //ab.AddProperty(String.Format("{0}", (item as ControlBase).ClientJavascriptID), true); //} #endregion ab.AddProperty(String.Format("{0}", (item as ControlBase).XID), true); } } if (ab.Count > 0) { OB.AddProperty("items", ab.ToString(), true); } } #endregion JsObjectBuilder layoutOB = new JsObjectBuilder(); layoutOB.AddProperty("pack", ToolbarAlignHelper.GetName(ToolbarAlign)); OB.AddProperty("layout", layoutOB, true); OB.AddProperty("xtype", "toolbar"); OB.AddProperty("dock", ToolbarPositionHelper.GetExtName(Position)); //string jsContent = String.Format("var {0}=Ext.create('Ext.toolbar.Toolbar',{1});", XID, OB.ToString()); //string jsContent = String.Format("var {0}={1};", XID, OB.GetProperty("items")); string jsContent = String.Format("var {0}={1};", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 处理列 /// </summary> /// <returns></returns> private void ResolveRows(ref string rowScriptsStr, ref string rowIdsStr) { JsArrayBuilder rowIdsBuilder = new JsArrayBuilder(); // 上一行的列数 int lastRowColumnCount = 1; // 上一行的列数 string lastRowColumnWidths = String.Empty; // 是否已经开始多列 bool isMultiColumnStarted = false; // 多列的开始行的序号 int multiColumnStartLineIndex = 0; for (int i = 0, rowCount = Rows.Count; i < rowCount; i++) { FormRow currentRow = Rows[i]; int currentRowColumnCount = GetRowColumnCount(currentRow); string currentRowColumnWidths = currentRow.ColumnWidths; if (currentRowColumnCount == 0) { // 如果当前行为空,则跳过此行 continue; } else if (currentRowColumnCount == 1) { if (isMultiColumnStarted) { // 如果上一行是多列行,则添加本行之上的所有行 rowScriptsStr += AddColumnScript(rowIdsBuilder, multiColumnStartLineIndex, i - 1, lastRowColumnCount); //rowScriptsStr += "\r\n"; // 开始重置记录本行为多列的开始 isMultiColumnStarted = false; multiColumnStartLineIndex = 0; } // 如果当前行的列数为1,则直接添加Field元素 //AddItemScript(ab, currentRow.Fields[0].ClientID); ControlBase component = GetRowColumnControl(currentRow, 0); if (component != null) { rowIdsBuilder.AddProperty(String.Format("{0}", component.XID), true); } } else { // 如果本行是多列 if (!isMultiColumnStarted) { // 如果上一行还是单列的话,则开始多列 isMultiColumnStarted = true; multiColumnStartLineIndex = i; } else { if (lastRowColumnCount == currentRowColumnCount && lastRowColumnWidths == currentRowColumnWidths) { // 如果上一行的列数和本行的列数相同(并且上一行每列的宽度和本行的每列宽度也一样),则继续下一行 } else { // 如果上一行的列数和本行的列数不相同,则添加本行之上的所有行 rowScriptsStr += AddColumnScript(rowIdsBuilder, multiColumnStartLineIndex, i - 1, lastRowColumnCount); //rowScriptsStr += "\r\n"; // 开始重新记录本行为多列的开始 isMultiColumnStarted = true; multiColumnStartLineIndex = i; } } } lastRowColumnCount = currentRowColumnCount; lastRowColumnWidths = currentRowColumnWidths; } // 还要判断一下(如果最后一行是两列的情况) if (isMultiColumnStarted) { rowScriptsStr += AddColumnScript(rowIdsBuilder, multiColumnStartLineIndex, Rows.Count - 1, lastRowColumnCount); //rowScriptsStr += "\r\n"; } rowIdsStr = rowIdsBuilder.ToString(); }
/// <summary> /// 添加列 /// </summary> /// <param name="rowIdsBuilder">行ID集合</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:' <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:' <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 //string bodyStyleStr = String.Empty; //if (EnableBackgroundColor) //{ // bodyStyleStr = GlobalConfig.GetDefaultBackgroundColor(); //} //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", "anchor"); 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}=Ext.create('Ext.panel.Panel',{1});", rowId, rowBuilder.ToString()); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); #region Reset ActiveIndex // 重置面板的 Collapsed 属性 if (ActivePane != null) { foreach (AccordionPane pane in Panes) { pane.Collapsed = true; } ActivePane.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 OB.RemoveProperty("layout"); JsObjectBuilder configBuilder = new JsObjectBuilder(); configBuilder.AddProperty("animate", false); configBuilder.AddProperty("activeOnTop", EnableActiveOnTop); configBuilder.AddProperty("fill", EnableFill); configBuilder.AddProperty("hideCollapseTool", !ShowCollapseTool); configBuilder.AddProperty("type", "accordion"); //configBuilder.AddProperty("multi", true); OB.AddProperty("layout", configBuilder); #endregion string jsContent = String.Format("var {0}=Ext.create('Ext.panel.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); }
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) { JsObjectBuilder rowNumberBuilder = new JsObjectBuilder(); if (RowNumberWidth != Unit.Empty) { rowNumberBuilder.AddProperty("width", RowNumberWidth.Value); } if (AllowPaging) { rowNumberBuilder.AddProperty("x_paging", Render_PagingID, true); } if (EnableRowNumberPaging) { rowNumberBuilder.AddProperty("x_paging_enabled", EnableRowNumberPaging); } columnsBuilder.AddProperty(String.Format("new Ext.grid.RowNumberer({0})", rowNumberBuilder.ToString()), true); } // 如果启用CheckBox,则放在第二列 // 如果启用单元格编辑,则EnableCheckBoxSelect属性失效 if (EnableCheckBoxSelect && !AllowCellEditing) { columnsBuilder.AddProperty(selectModelID, true); } string groupColumnScript = GetGroupColumnScript(); string expanderXID = String.Empty; foreach (GridColumn column in AllColumns) { if (column is TemplateField && (column as TemplateField).RenderAsRowExpander) { expanderXID = column.XID; } columnsBuilder.AddProperty(column.XID, true); } // 为Grid添加plugin属性 JsArrayBuilder pluginBuilder = new JsArrayBuilder(); if (!String.IsNullOrEmpty(expanderXID)) { pluginBuilder.AddProperty(expanderXID, 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 groupColumnScript + columnModelScript; }
protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("toolbar"); #region Items // 重新设置Items if (Controls.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Control item in Controls) { if (item is ControlBase && item.Visible) { #region old code //// 如果是分隔符 //if (item is ToolbarSeparator) //{ // ab.AddProperty("'-'", true); //} //else if (item is ToolbarText) //{ // ab.AddProperty(String.Format("'{0}'", (item as ToolbarText).Text), true); //} //if (item is ToolbarFill) //{ // ab.AddProperty("'->'", true); //} //else //{ //ab.AddProperty(String.Format("{0}", (item as ControlBase).ClientJavascriptID), true); //} #endregion ab.AddProperty(String.Format("{0}", (item as ControlBase).XID), true); } } if (ab.Count > 0) { OB.AddProperty("items", ab.ToString(), true); } } #endregion //#region IsPageMenu //// 如果是页面的菜单,使用特殊的样式 //if (IsPageMenu) //{ // OB.AddProperty(OptionName.Cls, "box-toolbar-pagemenu"); // // 这个样式在CSS中设置会被覆盖 // string style = CssStyle + "border:0px;"; // OB.AddProperty(OptionName.Style, style); //} //#endregion string jsContent = String.Format("var {0}=new Ext.Toolbar({1});", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 生成按钮客户端点击事件的脚本 /// </summary> /// <param name="validateForms"></param> /// <param name="validateTarget"></param> /// <param name="enablePostBack"></param> /// <param name="postBackEventReference"></param> /// <param name="confirmText"></param> /// <param name="confirmTitle"></param> /// <param name="confirmIcon"></param> /// <param name="confirmTarget"></param> /// <param name="onClientClick"></param> /// <param name="disableControlJavascriptID"></param> /// <returns></returns> internal static string ResolveClientScript(string[] validateForms, Target validateTarget, bool validateMessageBox, bool enablePostBack, string postBackEventReference, string confirmText, string confirmTitle, MessageBoxIcon confirmIcon, Target confirmTarget, string onClientClick, string disableControlJavascriptID) { // 1. validateScript string validateScript = String.Empty; if (validateForms != null && validateForms.Length > 0) { #region old code //StringBuilder sb = new StringBuilder(); //sb.Append("var forms=[];"); //foreach (string formId in validateForms) //{ // Control control = ControlUtil.FindControl(formId); // if (control != null && control is ControlBase) // { // sb.AppendFormat("forms.push(X.{0});", (control as ControlBase).ClientJavascriptID); // } //} ////sb.Append("if(!box_validForms(forms,'表单不完整','请为 “{0}” 提供有效值!')){return false;}"); //sb.AppendFormat("var validResult=X.util.validForms(forms);if(!validResult[0]){{{0}return false;}}", // Alert.GetShowReference("请为 “'+validResult[1].fieldLabel+'” 提供有效值!", "表单不完整")); #endregion JsArrayBuilder array = new JsArrayBuilder(); foreach (string formID in validateForms) { Control control = ControlUtil.FindControl(formID); if (control != null && control is ControlBase) { array.AddProperty((control as ControlBase).ClientID); } } validateScript = String.Format("if(!X.util.validForms({0},'{1}',{2})){{return false;}}", array.ToString(), TargetHelper.GetName(validateTarget), validateMessageBox.ToString().ToLower()); } // 2. 用户自定义脚本 string clientClickScript = onClientClick; if (!String.IsNullOrEmpty(clientClickScript) && !clientClickScript.EndsWith(";")) { clientClickScript += ";"; } // 3. 回发脚本 string postBackScript = String.Empty; if (enablePostBack) { if (!String.IsNullOrEmpty(disableControlJavascriptID)) { postBackScript += String.Format("X.disable('{0}');", disableControlJavascriptID); //postBackScript += String.Format("X.util.setHiddenFieldValue('{0}','{1}');", ResourceManager.DISABLED_CONTROL_BEFORE_POSTBACK, disableControlClientId); //postBackScript += String.Format("X.util.setDisabledControlBeforePostBack('{0}');", disableControlJavascriptID); } postBackScript += postBackEventReference; } if (!String.IsNullOrEmpty(confirmText)) { #region old code // 对confirm进行处理,对<script></script>包含的内容做js代码处理 //string confirmText = ConfirmText.Replace("'", "\""); //if (confirmText.Contains("<script>")) //{ // confirmText = confirmText.Replace("<script>", "'+"); // confirmText = confirmText.Replace("</script>", "+'"); //} //confirmText = String.Format("'{0}'", confirmText); //JsObjectBuilder ob = new JsObjectBuilder(); //ob.AddProperty(OptionName.Title, String.Format("'{0}'", confirmTitle), true); //ob.AddProperty(OptionName.Msg, String.Format("'{0}'", JsHelper.GetStringWithJsBlock(confirmText)), true); //ob.AddProperty(OptionName.Buttons, "Ext.MessageBox.OKCANCEL", true); //ob.AddProperty(OptionName.Icon, String.Format("'{0}'", MessageBoxIconName.GetName(confirmIcon)), true); //ob.AddProperty(OptionName.Fn, String.Format("function(btn){{if(btn=='cancel'){{return false;}}else{{{0}}}}}", postBackScript), true); //postBackScript = String.Format("Ext.MessageBox.show({0});", ob.ToString()); #endregion postBackScript = Confirm.GetShowReference(confirmText, confirmTitle, confirmIcon, postBackScript, "return false;", confirmTarget); } return(validateScript + clientClickScript + postBackScript); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //if (Items.Count > 0) //{ // ResourceManager.Instance.AddJavaScriptComponent("menu"); //} #region Items if (Items.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (BaseMenuItem item in Items) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } //if (item.Visible) //{ // ab.AddProperty(String.Format("{0}", item.ClientJavascriptID), true); //} //// 如果Item是否显示隐藏发生变化 //if (HashCodeChanged(item.ID + "", item.Visible)) //{ // if (item.Visible) // { // item.AjaxForceCompleteUpdate = true; // AddAjaxPartialUpdateScript(String.Format("{0}.insert({1},X.{2});", ClientJavascriptID, ab.Count - 1, item.ClientJavascriptID)); // } // else // { // AddAjaxPartialUpdateScript(String.Format("{0}.remove(X.{1});", ClientJavascriptID, item.ClientJavascriptID)); // } //} } if (ab.Count > 0) { OB.AddProperty("items", ab.ToString(), true); } } #region old code //if (HashCodeChanged("Items", itemsString)) //{ // StringBuilder ajaxUpdateBuilder = new StringBuilder(); // StringBuilder preUpdateBuilder = new StringBuilder(); // ajaxUpdateBuilder.AppendFormat("{0}.removeAll();", ClientJavascriptID); // foreach (BaseMenuItem item in Items) // { // if (item.Visible) // { // if (item is MenuSeparator) // { // ajaxUpdateBuilder.AppendFormat("{0}.addSeparator();", ClientJavascriptID); // } // else if (item is MenuText) // { // ajaxUpdateBuilder.AppendFormat("{0}.addText({1});", ClientJavascriptID, JsHelper.Enquote((item as MenuText).Text)); // } // else // { // preUpdateBuilder.AppendFormat("{0}_config=X.{0}.cloneConfig();", item.ClientJavascriptID); // ajaxUpdateBuilder.AppendFormat("{1}=new Ext.menu.Item(X.{1}_config);X.{0}.addItem(X.{1});", ClientJavascriptID, item.ClientJavascriptID); // } // } // } // AddAjaxPartialUpdateScript(preUpdateBuilder.ToString() + ajaxUpdateBuilder.ToString()); //} #endregion #endregion if (Items.Count > 0) { string jsContent = String.Format("var {0}=Ext.create('Ext.menu.Menu',{1});", XID, OB.ToString()); AddStartupScript(jsContent); } }
/// <summary> /// 添加列 /// </summary> /// <param name="rowIdsBuilder">行ID集合</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:' <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:' <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 //string bodyStyleStr = String.Empty; //if (EnableBackgroundColor) //{ // bodyStyleStr = GlobalConfig.GetDefaultBackgroundColor(); //} //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", "anchor"); 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}=Ext.create('Ext.panel.Panel',{1});", rowId, rowBuilder.ToString())); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("toolbar"); #region Items // 重新设置Items if (Controls.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Control item in Controls) { if (item is ControlBase && item.Visible) { #region old code //// 如果是分隔符 //if (item is ToolbarSeparator) //{ // ab.AddProperty("'-'", true); //} //else if (item is ToolbarText) //{ // ab.AddProperty(String.Format("'{0}'", (item as ToolbarText).Text), true); //} //if (item is ToolbarFill) //{ // ab.AddProperty("'->'", true); //} //else //{ //ab.AddProperty(String.Format("{0}", (item as ControlBase).ClientJavascriptID), true); //} #endregion ab.AddProperty(String.Format("{0}", (item as ControlBase).XID), true); } } if (ab.Count > 0) { OB.AddProperty("items", ab.ToString(), true); } } #endregion JsObjectBuilder layoutOB = new JsObjectBuilder(); layoutOB.AddProperty("pack", ToolbarAlignHelper.GetName(ToolbarAlign)); OB.AddProperty("layout", layoutOB, true); //string jsContent = String.Format("var {0}=Ext.create('Ext.toolbar.Toolbar',{1});", XID, OB.ToString()); //string jsContent = String.Format("var {0}={1};", XID, OB.GetProperty("items")); string jsContent = String.Format("var {0}={1};", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { // 确保 F_Rows 在页面第一次加载时都存在于f_state中 FState.AddModifiedProperty("F_Rows"); if (EnableSummary) { FState.AddModifiedProperty("SummaryData"); } if (SelectedRowIDArray.Length > 0) { FState.AddModifiedProperty("SelectedRowIDArray"); } // 不需要手工添加 SelectedRowIndexArray 属性,是因为只能通过代码设置此属性 // 只要通过代码设置了 SelectedRowIndexArray 属性,则一定会存在于 F_States base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("grid"); JsArrayBuilder pluginBuilder = new JsArrayBuilder(); #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("selModel", Render_SelectModelID, true); string gridColumnsScript = GetGridColumnScript(pluginBuilder); OB.AddProperty("columns", Render_GridColumnsID, true); string gridStoreScript = GetGridStore(); OB.AddProperty("store", Render_GridStoreID, true); OB.AddProperty("f_fields", Render_GridFieldsID, 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); // } //} #endregion #region viewConfig JsObjectBuilder viewBuilder = new JsObjectBuilder(); if (!String.IsNullOrEmpty(EmptyText)) { viewBuilder.AddProperty("deferEmptyText", false); viewBuilder.AddProperty("emptyText", EmptyText); } if (!EnableAlternateRowColor) { viewBuilder.AddProperty("stripeRows", false); } if (EnableTextSelection) { viewBuilder.AddProperty("enableTextSelection", true); } viewBuilder.AddProperty("getRowClass", JsHelper.GetFunction("return 'f-grid-row';"), true); //viewBuilder.AddProperty("selectedItemCls", "x-grid-row-selected f-grid-row-selected"); if (viewBuilder.Count > 0) { OB.AddProperty("viewConfig", viewBuilder); } #endregion #region Properties if (!String.IsNullOrEmpty(DataIDField)) { OB.AddProperty("f_idField", DataIDField); } if (EnableColumnLines) { OB.AddProperty("columnLines", true); } if (!EnableRowLines) { OB.AddProperty("rowLines", false); } if (ForceFit) { OB.AddProperty("forceFit", true); } //OB.AddProperty("enableHdMenu", EnableHeaderMenu); //if (EnableHeaderMenu) //{ // // 启用标题栏菜单,但是不启用标题栏菜单中的隐藏列功能 // if (!EnableColumnHide) // { // OB.AddProperty("enableColumnHide", false); // } //} if (!ShowGridHeader) { OB.AddProperty("hideHeaders", true); } if (!EnableMouseOverColor) { OB.AddProperty("trackMouseOver", false); } // 延迟渲染 if (!EnableDelayRender) { OB.AddProperty("deferRowRender", false); } #endregion #region EnableRowClickEvent if (EnableRowClickEvent) { string validateScript = "var args='RowClick$'+record.getId();"; validateScript += GetPostBackEventReference("#RowClick#").Replace("'#RowClick#'", "args"); //string rowClickScript = JsHelper.GetFunction(validateScript, "grid", "record", "item", "index"); // String.Format("function(grid,rowIndex,e){{{0}}}", validateScript); //OB.Listeners.AddProperty("itemclick", rowClickScript, true); AddListener("itemclick", validateScript, "grid", "record", "item", "index"); } if (EnableRowDoubleClickEvent) { string validateScript = "var args='RowDoubleClick$'+record.getId();"; validateScript += GetPostBackEventReference("#RowDoubleClick#").Replace("'#RowDoubleClick#'", "args"); //string rowClickScript = JsHelper.GetFunction(validateScript, "grid", "record", "item", "index"); //String.Format("function(grid,rowIndex,e){{{0}}}", validateScript); //OB.Listeners.AddProperty("itemdblclick", rowClickScript, true); AddListener("itemdblclick", validateScript, "grid", "record", "item", "index"); } #endregion #region AllowPaging string pagingScript = String.Empty; if (AllowPaging) { OptionBuilder pagingBuilder = GetPagingBuilder(); if (!ShowPagingMessage) { pagingBuilder.AddProperty("displayInfo", false); } else { 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.f_hideRefresh();"), true); string postbackScript = String.Empty; postbackScript = GetPostBackEventReference("#PLACEHOLDER#"); string loadPageScript = JsHelper.GetFunction(postbackScript.Replace("'#PLACEHOLDER#'", "'Page$'+(pageNum-1)") + "return false;", "bar", "pageNum"); pagingBuilder.Listeners.AddProperty("beforechange", loadPageScript, true); if (PageItems.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in PageItems) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } pagingBuilder.AddProperty("items", ab.ToString(), true); } pagingBuilder.AddProperty("xtype", "simplepagingtoolbar"); pagingBuilder.AddProperty("dock", "bottom"); pagingScript = String.Format("var {0}={1};", Render_PagingID, pagingBuilder); //OB.AddProperty("bbar", Render_PagingID, true); } #endregion #region remove fx OB.AddProperty("draggable", false); //OB.AddProperty("enableColumnMove", false); OB.AddProperty("enableDragDrop", false); if (!EnableColumnResize) { OB.AddProperty("enableColumnResize", false); } #endregion #region AllowSorting //// 如果启用服务器端排序,则需要注册headerclick事件处理 //if (AllowSorting) //{ // string headerClickScript = "if(!cmp.getColumnModel().config[columnIndex].sortable){return false;}"; // headerClickScript += "var args='Sort$'+columnIndex;"; // headerClickScript += GetPostBackEventReference("#SORT#").Replace("'#SORT#'", "args"); // // 告诉 store 本次排序已经处理了,不要重复处理了 // headerClickScript += "cmp.getStore().headerclickprocessed=true;"; // //string headerClickScript = String.Format("function(grid,columnIndex){{{0}}}", validateScript); // OB.Listeners.AddProperty("headerclick", JsHelper.GetFunction(headerClickScript, "cmp", "columnIndex"), true); //} // add by wz if (!AllowSorting) { OB.AddProperty("sortableColumns", false); } #endregion // add by wz #region enableColumnHide if (!EnableColumnHide) OB.AddProperty("enableColumnHide", false); #endregion // mod by wz #region EnableSummary //JsArrayBuilder features = new JsArrayBuilder(); //if (EnableSummary) //{ // JsObjectBuilder summaryFeature = new JsObjectBuilder(); // summaryFeature.AddProperty("ftype", "summary"); // summaryFeature.AddProperty("id", "summary"); // if (SummaryPosition != SummaryPosition.Flow) // { // summaryFeature.AddProperty("dock", SummaryPositionHelper.GetName(SummaryPosition)); // } // //if (SummaryHidden) // //{ // // summaryFeature.AddProperty("showSummaryRow", false); // //} // features.AddProperty(summaryFeature); //} //if (features.Count > 0) //{ // OB.AddProperty("features", features); //} #endregion // add by wz #region Enable Group & Summary JsArrayBuilder features = new JsArrayBuilder(); if (EnableGroup && EnableSummary) { JsObjectBuilder groupingSummaryFeature = new JsObjectBuilder(); groupingSummaryFeature.AddProperty("ftype", "groupingsummary"); groupingSummaryFeature.AddProperty("id", "groupingsummary"); //if (SummaryPosition != SummaryPosition.Flow) //{ // groupingSummaryFeature.AddProperty("dock", SummaryPositionHelper.GetName(SummaryPosition)); //} if (!string.IsNullOrEmpty(GroupHeader)) groupingSummaryFeature.AddProperty("groupHeaderTpl", GroupHeader, true); if (!EnableGroupCollapse) groupingSummaryFeature.AddProperty("collapsible", EnableGroupCollapse); if (!EnableGroupMenu) groupingSummaryFeature.AddProperty("enableGroupingMenu", EnableGroupMenu); if (GroupStartCollapsed) groupingSummaryFeature.AddProperty("startCollapsed", GroupStartCollapsed); features.AddProperty(groupingSummaryFeature); } else if (EnableSummary) { JsObjectBuilder summaryFeature = new JsObjectBuilder(); summaryFeature.AddProperty("ftype", "summary"); summaryFeature.AddProperty("id", "summary"); if (SummaryPosition != SummaryPosition.Flow) { summaryFeature.AddProperty("dock", SummaryPositionHelper.GetName(SummaryPosition)); } //if (SummaryHidden) //{ // summaryFeature.AddProperty("showSummaryRow", false); //} features.AddProperty(summaryFeature); } else if (EnableGroup) { JsObjectBuilder groupFeature = new JsObjectBuilder(); groupFeature.AddProperty("ftype", "grouping"); groupFeature.AddProperty("id", "grouping"); if (!string.IsNullOrEmpty(GroupHeader)) groupFeature.AddProperty("groupHeaderTpl", GroupHeader, true); if (!EnableGroupCollapse) groupFeature.AddProperty("collapsible", EnableGroupCollapse); if (!EnableGroupMenu) groupFeature.AddProperty("enableGroupingMenu", EnableGroupMenu); if (GroupStartCollapsed) groupFeature.AddProperty("startCollapsed", GroupStartCollapsed); features.AddProperty(groupFeature); } if (features.Count > 0) { OB.AddProperty("features", features); } #endregion #region Listeners - afterrender StringBuilder viewreadySB = new StringBuilder(); // Note: this.f_state['F_Rows']['Values'] will always rendered to the client side. //viewreadySB.Append("cmp.f_updateTpls();"); if (AllowSorting) { viewreadySB.AppendFormat("cmp.f_initSortHeaders();"); } if (!AllowCellEditing) { viewreadySB.Append("cmp.f_selectRows();"); } //if (EnableTextSelection) //{ // cls += " x-grid-selectable"; // viewreadySB.Append("cmp.f_enableTextSelection();"); //} // 展开所有的行扩展列 if (ExpandAllRowExpanders) { viewreadySB.Append("cmp.f_expandAllRows();"); } if (AllowColumnLocking) { // 必须延时调用 doLayout,否则显示不正常 viewreadySB.Append("cmp.doLayout();"); } string viewreadyScript = viewreadySB.ToString(); if (!String.IsNullOrEmpty(viewreadyScript)) { viewreadyScript = "window.setTimeout(function(){" + viewreadyScript + "},200);"; // viewready在enableLocking时不会触发,只好改成afterrender //OB.Listeners.AddProperty("afterrender", JsHelper.GetFunction(viewreadyScript, "cmp"), true); AddListener("afterrender", viewreadyScript, "cmp"); } #endregion #region cls string cls = CssClass; if (RowVerticalAlign != VerticalAlign.Middle) { cls += String.Format("row-align-{0}", VerticalAlignName.GetName(RowVerticalAlign)); } cls = cls.Trim(); if (!String.IsNullOrEmpty(cls)) { OB.AddProperty("cls", cls); } #endregion #region Listeners - render StringBuilder renderSB = new StringBuilder(); // 加载表格数据 renderSB.Append("cmp.f_loadData();"); //// 隐藏列 //if (HiddenColumnIndexArray != null && HiddenColumnIndexArray.Length > 0) //{ // renderSB.Append("cmp.f_updateColumnsHiddenStatus();"); //} //OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderSB.ToString(), "cmp"), true); AddListener("render", renderSB.ToString(), "cmp"); #endregion #region AllowCellEditing string cellEditScript = String.Empty; if (AllowCellEditing) { string pluginId = String.Format("{0}_cellEditing", XID); JsObjectBuilder cellEditBuilder = new JsObjectBuilder(); cellEditBuilder.AddProperty("pluginId", pluginId); cellEditBuilder.AddProperty("clicksToEdit", ClicksToEdit); cellEditScript = String.Format("var {0}=Ext.create('Ext.grid.plugin.CellEditing',{1});", pluginId, cellEditBuilder); pluginBuilder.AddProperty(pluginId, true); if (EnableAfterEditEvent) { string validateScript = "var args='AfterEdit$'+e.record.getId()+'$'+e.column.id;"; validateScript += GetPostBackEventReference("#AfterEdit#").Replace("'#AfterEdit#'", "args"); //string rowClickScript = String.Format("function(editor,e){{{0}}}", validateScript); //OB.Listeners.AddProperty("edit", rowClickScript, true); AddListener("edit", validateScript, "editor", "e"); } OB.AddProperty("f_cellEditing", pluginId, true); } if (AllowColumnLocking) { OB.AddProperty("enableLocking", true); } else { OB.AddProperty("enableLocking", false); } #endregion #region pluginBuilder if (pluginBuilder.Count > 0) { OB.AddProperty("plugins", pluginBuilder.ToString(), true); } #endregion StringBuilder sb = new StringBuilder(); sb.Append(gridSelectModelScript + gridStoreScript + pagingScript + gridColumnsScript + cellEditScript); sb.AppendFormat("var {0}=Ext.create('Ext.grid.Panel',{1});", XID, OB); AddStartupScript(sb.ToString()); #region old code ////List<string> totalModifiedProperties = FState.GetTotalModifiedProperties(); ////if (SelectedRowIndexArray.Length > 0) ////{ //// string selectScript = String.Empty; //// if (totalModifiedProperties.Contains("SelectedRowIndexArray")) //// { //// selectScript = String.Format("{0}.f_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 F_STATE during page's first load. //sb.Append(JsHelper.GetDeferScript(String.Format("{0}.f_selectRows();", XID), 200)); #endregion // add by wz #region GroupEvent if (EnableGroupCollapseEvent) { string function = "var args='GroupCollapse$'+group;"; function += GetPostBackEventReference("#GroupCollapse#").Replace("'#GroupCollapse#'", "args"); string script = string.Format("{0}.getView().on('groupcollapse', function(view, node, group){{ {1} }});", XID, function); PageContext.RegisterStartupScript(script); } if (EnableGroupExpandEvent) { string function = "var args='GroupExpand$'+group;"; function += GetPostBackEventReference("#GroupExpand$#").Replace("'#GroupExpand$#'", "args"); string script = string.Format("{0}.getView().on('groupexpand', function(view, node, group){{ {1} }});", XID, function); PageContext.RegisterStartupScript(script); } if (EnableGroupClickEvent) { string function = "var args='GroupClick$'+group;"; function += GetPostBackEventReference("#GroupClick#").Replace("'#GroupClick#'", "args"); string script = string.Format("{0}.getView().on('groupclick', function(view, node, group){{ {1} }});", XID, function); PageContext.RegisterStartupScript(script); } if (EnableGroupDoubleClickEvent) { string function = "var args='GroupDoubleClick$'+group;"; function += GetPostBackEventReference("#GroupDoubleClick#").Replace("'#GroupDoubleClick#'", "args"); string script = string.Format("{0}.getView().on('groupdblclick', function(view, node, group){{ {1} }});", XID, function); PageContext.RegisterStartupScript(script); } #endregion }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //if (Items.Count > 0) //{ // ResourceManager.Instance.AddJavaScriptComponent("menu"); //} #region Items if (Items.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (BaseMenuItem item in Items) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } //if (item.Visible) //{ // ab.AddProperty(String.Format("{0}", item.ClientJavascriptID), true); //} //// 如果Item是否显示隐藏发生变化 //if (HashCodeChanged(item.ID + "", item.Visible)) //{ // if (item.Visible) // { // item.AjaxForceCompleteUpdate = true; // AddAjaxPartialUpdateScript(String.Format("{0}.insert({1},X.{2});", ClientJavascriptID, ab.Count - 1, item.ClientJavascriptID)); // } // else // { // AddAjaxPartialUpdateScript(String.Format("{0}.remove(X.{1});", ClientJavascriptID, item.ClientJavascriptID)); // } //} } if (ab.Count > 0) { OB.AddProperty("items", ab.ToString(), true); } } #region old code //if (HashCodeChanged("Items", itemsString)) //{ // StringBuilder ajaxUpdateBuilder = new StringBuilder(); // StringBuilder preUpdateBuilder = new StringBuilder(); // ajaxUpdateBuilder.AppendFormat("{0}.removeAll();", ClientJavascriptID); // foreach (BaseMenuItem item in Items) // { // if (item.Visible) // { // if (item is MenuSeparator) // { // ajaxUpdateBuilder.AppendFormat("{0}.addSeparator();", ClientJavascriptID); // } // else if (item is MenuText) // { // ajaxUpdateBuilder.AppendFormat("{0}.addText({1});", ClientJavascriptID, JsHelper.Enquote((item as MenuText).Text)); // } // else // { // preUpdateBuilder.AppendFormat("{0}_config=X.{0}.cloneConfig();", item.ClientJavascriptID); // ajaxUpdateBuilder.AppendFormat("{1}=new Ext.menu.Item(X.{1}_config);X.{0}.addItem(X.{1});", ClientJavascriptID, item.ClientJavascriptID); // } // } // } // AddAjaxPartialUpdateScript(preUpdateBuilder.ToString() + ajaxUpdateBuilder.ToString()); //} #endregion #endregion if (Items.Count > 0) { string jsContent = String.Format("var {0}=Ext.create('Ext.menu.Menu',{1});", XID, OB.ToString()); AddStartupScript(jsContent); } }
protected override void OnFirstPreRender() { base.OnFirstPreRender(); if (EnableFrame) { OB.AddProperty("frame", true); } if (FooterBarAlign != FooterBarAlign.Right) { OB.AddProperty("buttonAlign", FooterBarAlignHelper.GetName(FooterBarAlign)); } #region Items if (!RenderChildrenAsContent) { if (Items.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in Items) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } } #endregion #region Toolbars foreach (Toolbar bar in Toolbars) { string toolbarID = String.Format("{0}", bar.XID); if (bar.Position == ToolbarPosition.Top) { OB.AddProperty("tbar", toolbarID, true); } else if (bar.Position == ToolbarPosition.Bottom) { OB.AddProperty("bbar", toolbarID, true); } else if (bar.Position == ToolbarPosition.Footer) { OB.AddProperty("fbar", toolbarID, true); } } #endregion #region BodyStyle/ShowBorder string bodyStyleStr = BodyStyle; if (!bodyStyleStr.Contains("padding")) { if (!String.IsNullOrEmpty(BodyPadding)) { bodyStyleStr += String.Format("padding:{0};", BodyPadding); } } if (EnableBackgroundColor) { if (!bodyStyleStr.Contains("background-color")) { string backgroundColorStyleStr = GlobalConfig.GetDefaultBackgroundColor(); if (!String.IsNullOrEmpty(backgroundColorStyleStr)) { bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr); } } } //else if (EnableLightBackgroundColor) //{ // if (!bodyStyleStr.Contains("background-color")) // { // string backgroundColorStyleStr = GlobalConfig.GetLightBackgroundColor(PageManager.Instance.Theme.ToString()); // bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr); // } //} OB.AddProperty("bodyStyle", bodyStyleStr); OB.AddProperty("border", ShowBorder); #endregion #region Width/Height // 对于Panel,如果宽度/高度没有定义 if (Width == Unit.Empty && AutoWidth) { OB.AddProperty("autoWidth", true); } if (Height == Unit.Empty && AutoHeight) { OB.AddProperty("autoHeight", true); } // 如果父控件是容器控件(不是ContentPanel),并且Layout != LayoutType.Container, // 则设置AutoWidth/AutoHeight都为false if (Parent is PanelBase) { PanelBase parent = Parent as PanelBase; if (!(parent is ContentPanel) && parent.Layout != Layout.Container) { OB.RemoveProperty("autoHeight"); OB.RemoveProperty("autoWidth"); } } if (AutoScroll) { OB.AddProperty("autoScroll", true); } #region old code //// 如果是 PageLayout 中的Panel,不能设置AutoWidth //if (Parent is PageLayout) //{ // // region // if (Region != Region_Default) OB.AddProperty(OptionName.Region, RegionTypeName.GetName(Region.Value)); //} //else //{ // // 对于Panel,如果宽度/高度没有定义,则使用自动宽度和高度 // if (Width == Unit.Empty) // { // OB.AddProperty(OptionName.AutoWidth, true); // } // if (Height == Unit.Empty) // { // OB.AddProperty(OptionName.AutoHeight, true); // } //} //// 如果父控件是容器控件,并且Layout=Fit,则设置AutoWidth/AutoHeight都为false //if (Parent is PanelBase) //{ // PanelBase parentPanel = Parent as PanelBase; // if (parentPanel.Layout == LayoutType.Fit // || parentPanel.Layout == LayoutType.Anchor // || parentPanel.Layout == LayoutType.Border) // { // OB.RemoveProperty(OptionName.AutoHeight); // OB.RemoveProperty(OptionName.AutoWidth); // } //} #endregion #endregion #region EnableIFrame if (EnableIFrame) { #region old code //string iframeJsContent = String.Empty; //string frameUrl = ResolveUrl(IFrameUrl); //JsObjectBuilder iframeBuilder = new JsObjectBuilder(); //if (IFrameDelayLoad) //{ // iframeBuilder.AddProperty(OptionName.Src, "#"); //} //else //{ // iframeBuilder.AddProperty(OptionName.Src, frameUrl); //} //iframeBuilder.AddProperty(OptionName.LoadMask, false); //iframeJsContent += String.Format("var {0}=new Ext.ux.ManagedIFrame('{0}',{1});", IFrameID, iframeBuilder.ToString()); //if (IFrameDelayLoad) //{ // iframeJsContent += String.Format("{0}_url='{1}';", IFrameID, frameUrl); //} //iframeJsContent += "\r\n"; //AddStartupScript(this, iframeJsContent); #endregion // 注意: // 如下依附于现有对象的属性名称的定义规则:x_property1 // 存储于当前对象实例中 OB.AddProperty("x_iframe", true); OB.AddProperty("x_iframe_url", IFrameUrl); OB.AddProperty("x_iframe_name", IFrameName); // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 if (!String.IsNullOrEmpty(IFrameUrl)) { //_writeIframeToHtmlDocument = true; OB.AddProperty("x_iframe_loaded", true); // 直接添加iframe属性 OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); } else { //_writeIframeToHtmlDocument = false; OB.AddProperty("x_iframe_loaded", false); } #region old code //// If current panel is Tab, then process the IFrameDelayLoad property. //Tab tab = this as Tab; //if (tab != null && tab.IFrameDelayLoad) //{ // // 如果是Tab,并且此Tab不是激活的,则不添加iframe // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); //} //else //{ // // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 // if (!String.IsNullOrEmpty(IFrameUrl)) // { // //_writeIframeToHtmlDocument = true; // OB.AddProperty("box_property_iframe_loaded", true); // // 直接添加iframe属性 // OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); // } // else // { // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); // } //} #endregion } #endregion #region RoundBorder //if (RoundBorder) OB.AddProperty(OptionName.Frame, true); #endregion #region EnableLargeHeader if (EnableLargeHeader) { OB.AddProperty("cls", "box-panel-big-header"); } #endregion #region remove fx // 关闭折叠时特效 OB.AddProperty("animCollapse", false); #endregion #region ContentEl //string finallyScript = String.Empty; if (RenderChildrenAsContent) { OB.AddProperty("contentEl", ContentID); // 在页面元素渲染完成后,才显示容器控件的内容 string renderScript = String.Format("Ext.get('{0}').show();", ContentID); OB.Listeners.AddProperty("render", "function(component){" + renderScript + "}", true); //string beforerenderScript = String.Format("Ext.get('{0}').setStyle('display','');", ChildrenContentID); //OB.Listeners.AddProperty("beforerender", "function(component){" + beforerenderScript + "}", true); // 这一段的逻辑(2008-9-1): // 如果是页面第一次加载 + 此Panel在Tab中 + 此Tab不是当前激活Tab + 此Tab的TabStrip启用了延迟加载 // 那么在页面加载完毕后,把此Panel给隐藏掉,等此Panel渲染到页面中时再显示出来 Tab tab = ControlUtil.FindParentControl(this, typeof(Tab)) as Tab; if (tab != null) { TabStrip tabStrip = tab.Parent as TabStrip; if (tabStrip.EnableDeferredRender && tabStrip.Tabs[tabStrip.ActiveTabIndex] != tab) { // 页面第一次加载时,在显示(控件的render事件)之前要先隐藏 AddStartupAbsoluteScript(String.Format("Ext.get('{0}').setStyle('display','none');", ContentID)); } } } #endregion }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); OB.AddProperty("border", false); OB.AddProperty("header", false); Form parentForm = Parent as Form; if (parentForm == null) { return; } int formrowItemsSpace = Convert.ToInt32(parentForm.FormRowItemsSpace.Value); if (Items.Count > 0) { #region oldcode /* * 增加中间的分割面板,会对显示隐藏表单字段造成影响 * int currentItemCount = 0; * JsArrayBuilder ab = new JsArrayBuilder(); * foreach (ControlBase item in Items) * { * if (item.Visible) * { * if (currentItemCount > 0) * { * OptionBuilder separatorOB = new OptionBuilder(); * separatorOB.AddProperty("type", "panelbase"); * separatorOB.AddProperty("width", 8); * ab.AddProperty(String.Format("{0}", separatorOB), true); * } * ab.AddProperty(String.Format("{0}", item.XID), true); * currentItemCount++; * } * } * OB.AddProperty("items", ab.ToString(), true); */ #endregion // 为子项添加布局属性 int columnCount = Items.Count; string defaultColumnWidthStr = (1.0 / columnCount).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); List <string> columnWidths = GetTrimedColumnWidths(); // 用户自定义ColumnWidths是否和Items的个数匹配 bool isColumnWidthsMatch = false; if (columnWidths.Count == columnCount) { isColumnWidthsMatch = true; } Dictionary <string, JsObjectBuilder> buttonOptions = new Dictionary <string, JsObjectBuilder>(); for (int i = 0; i < columnCount; i++) { var comp = Items[i] as Component; // 如果FormRow的子项是 Button,则用一个面板将其包裹起来,否则按钮的宽度会很长 bool isbutton = false; JsObjectBuilder buttonPanelOB = new JsObjectBuilder(); if (comp is Button) { isbutton = true; buttonPanelOB.AddProperty("xtype", "panel"); buttonPanelOB.AddProperty("header", false); buttonPanelOB.AddProperty("border", false); buttonPanelOB.AddProperty("items", String.Format("[{0}]", comp.XID), true); } #region Component if (comp != null) { // 不是最后一列的话,加上空白间隔 if (columnCount > 1 && i != columnCount - 1) { if (isbutton) { //buttonOB.AddProperty("marginRight", formrowItemsSpace); buttonPanelOB.AddProperty("style", String.Format("margin-right:{0}px;", formrowItemsSpace)); } else { //// 如果尚未设置 MarginRight //if (comp.MarginRight == Unit.Empty) //{ // comp.MarginRight = Unit.Pixel(formrowItemsSpace); //} //if (String.IsNullOrEmpty(comp.Margin)) //{ // comp.Margin = String.Format("0 {0} 0 0", formrowItemsSpace); //} comp.CssStyle += String.Format("margin-right:{0}px;", formrowItemsSpace); } } } #endregion #region BoxComponent var boxcomp = comp as BoxComponent; if (boxcomp != null) { if (isColumnWidthsMatch) { string columnWidth = StringUtil.ConvertPercentageToDecimalString(columnWidths[i]); if (Convert.ToDouble(columnWidth) <= 1.0) { if (isbutton) { buttonPanelOB.AddProperty("columnWidth", columnWidth, true); } else { boxcomp.ColumnWidth = columnWidth; } } else { Unit unitColumnWidth = Unit.Parse(columnWidth); if (isbutton) { buttonPanelOB.AddProperty("width", unitColumnWidth.Value); } else { boxcomp.Width = unitColumnWidth; } } } else { if (isbutton) { buttonPanelOB.AddProperty("columnWidth", defaultColumnWidthStr, true); } else { boxcomp.ColumnWidth = defaultColumnWidthStr; } } } #endregion if (isbutton) { buttonOptions.Add(comp.XID, buttonPanelOB); } } JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in Items) { if (item.Visible) { string itemXID = item.XID; if (buttonOptions.ContainsKey(itemXID)) { itemXID = buttonOptions[itemXID].ToString(); } ab.AddProperty(itemXID, true); } } OB.AddProperty("items", ab.ToString(), true); } // 自定义样式 OB.AddProperty("cls", "f-formrow"); string jsContent = String.Format("var {0}=Ext.create('Ext.panel.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); ////// 目的:子控件的JS代码在父控件的前面 ////AddStartupScript(this, String.Empty); //AddStartupScript(String.Empty); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("tab"); //if (EnableTabCloseMenu) //{ // ResourceManager.Instance.AddJavaScriptComponent("menu"); //} #region Tabs if (Tabs.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Tab tab in Tabs) { if (tab.Visible) { ab.AddProperty(String.Format("{0}", tab.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } #endregion #region options // 删除Layout配置参数 OB.RemoveProperty("layout"); //OB.AddProperty(OptionName.TabMargin, TabMargin.Value); OB.AddProperty("tabPosition", TabPositionHelper.GetName(TabPosition)); //if (!EnableTitleBackgroundColor) //{ // OB.AddProperty("plain", true); //} // 全部渲染,否则没有访问的Tab的内容渲染的位置不正确。 OB.AddProperty("deferredRender", false); //OB.AddProperty("bufferResize", true); //// 在切换Tab时重新布局Tab的内容 //OB.AddProperty("layoutOnTabChange", true); //OB.AddProperty("enableTabScroll", true); if (EnableTabCloseMenu) { OB.AddProperty("plugins", "Ext.create('Ext.ux.TabCloseMenu')", true); } ////Note: By default, a tab's close tool destroys the child tab Component and all its descendants. //// This makes the child tab Component, and all its descendants unusable. //// To enable re-use of a tab, configure the TabPanel with autoDestroy: false. //OB.AddProperty("autoDestroy", false); #endregion #region ActiveTabIndex/IFrameDelayLoad OB.AddProperty("activeTab", ActiveTabIndex); //for (int i = 0; i < Tabs.Count; i++) //{ // Tab tab = Tabs[i]; // if (tab.EnableIFrame && i != ActiveTabIndex) // { // // 拥有IFrame的Tab如果不是激活Tab,则不设置Url,只有在激活时才设置Url // tab.IFrameDelayLoad = true; // } // else // { // tab.IFrameDelayLoad = false; // } //} #endregion #region Listeners #region old code // 如果存在Tabs集合 //if (Tabs.Count > 0) //{ // JsArrayBuilder ab = new JsArrayBuilder(); // foreach (Tab tab in Tabs) // { // ab.AddProperty(String.Format("{0}", tab.ClientID), true); // } // OB.AddProperty(OptionName.Items, ab.ToString(), true); //} // listeners //JsObjectBuilder listenersBuilder = new JsObjectBuilder(); //listenersBuilder.AddProperty(OptionName.Tabchange, String.Format("function(tabPanel, activeTab){{Ext.get('{0}').dom.value=tabPanel.items.indexOf(activeTab);}}", ActiveTabHiddenField.ClientID), true); //OBuilder.AddProperty("listeners", listenersBuilder.ToString(), true); #endregion // 如果要激活的Tab含有IFrame,则需要加载IFrame // 改变Tab需要回发的脚本 // Make sure X_AutoPostBackTabs property exist in F_STATE during page's first load. //string tabchangeScript2 = String.Format("if(tabPanel.f_autoPostBackTabsContains(tab.id)){{{0}}}", GetPostBackEventReference()); string tabchangeScript = "F.wnd.updateIFrameNode(tab);"; string postbackScript = String.Empty; if (AutoPostBack) { tabchangeScript += "if(!tab.f_dynamic_added_tab){" + GetPostBackEventReference("TabIndexChanged") + "}"; } // 如果是动态添加的Tab,不做任何处理(在js/box/extender.js中) //string tabchangeScript = "F.wnd.updateIFrameNode(tab);if(!tab.f_dynamic_added_tab){" + postbackScript + "}"; //OB.Listeners.AddProperty("tabchange", JsHelper.GetFunction(tabchangeScript, "tabPanel", "tab"), true); AddListener("tabchange", tabchangeScript, "tabPanel", "tab"); #endregion #region old code //// 添加隐藏字段 //string needPostBackTabIDsScript = GetNeedPostBackTabIDsScript(); //hiddenFieldsScript += needPostBackTabIDsScript; //if (AjaxPropertyChanged("NeedPostBackTabIdsScript", needPostBackTabIDsScript)) //{ // AddAjaxPropertyChangedScript(needPostBackTabIDsScript); //} //hiddenFieldsScript += GetSetHiddenFieldValueScript(ActiveTabHiddenFieldID, ActiveTabIndex.ToString().ToLower()); #endregion #region old code //// An bug in IE. //string renderScript = "if(Ext.isIE){(function(){this.getActiveTab().removeClass('x-hide-display');}).defer(20,this);}"; //OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript), true); #endregion string jsContent = String.Format("var {0}=Ext.create('Ext.tab.Panel',{1});", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("toolbar"); #region Items // 重新设置Items if (Controls.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (Control item in Controls) { if (item is ControlBase && item.Visible) { #region old code //// 如果是分隔符 //if (item is ToolbarSeparator) //{ // ab.AddProperty("'-'", true); //} //else if (item is ToolbarText) //{ // ab.AddProperty(String.Format("'{0}'", (item as ToolbarText).Text), true); //} //if (item is ToolbarFill) //{ // ab.AddProperty("'->'", true); //} //else //{ //ab.AddProperty(String.Format("{0}", (item as ControlBase).ClientJavascriptID), true); //} #endregion ab.AddProperty(String.Format("{0}", (item as ControlBase).XID), true); } } if (ab.Count > 0) { OB.AddProperty("items", ab.ToString(), true); } } #endregion //#region IsPageMenu //// 如果是页面的菜单,使用特殊的样式 //if (IsPageMenu) //{ // OB.AddProperty(OptionName.Cls, "box-toolbar-pagemenu"); // // 这个样式在CSS中设置会被覆盖 // string style = CssStyle + "border:0px;"; // OB.AddProperty(OptionName.Style, style); //} //#endregion string jsContent = String.Format("var {0}=new Ext.Toolbar({1});", XID, OB.ToString()); AddStartupScript(jsContent); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); //ResourceManager.Instance.AddJavaScriptComponent("form"); #region Options #endregion #region ResolveRows //// 包含行的列脚本 //string rowScriptStr = String.Empty; //// 行的集合 //string rowItemScriptStr = String.Empty; //// 如果存在Rows集合 //if (Rows.Count > 0) //{ // // rowScriptStr // // rowItemScriptStr: [X.__Panel1_UpdatePanelConnector1_Panel7_Form5_row0,X.__Panel1_UpdatePanelConnector1_Panel7_Form5_row2] // ResolveRows(ref rowScriptStr, ref rowItemScriptStr); // // 添加Items // OB.RemoveProperty("items"); // OB.AddProperty("items", rowItemScriptStr, true); //} ////rowScriptStr += "\r\n"; #endregion #region Rows if (Rows.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (FormRow row in Rows) { if (row.Visible) { ab.AddProperty(String.Format("{0}", row.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } #endregion AddListener("dirtychange", "F.util.setPageStateChanged(dirty);", "form", "dirty"); string formPanelScript = String.Format("var {0}=Ext.create('Ext.form.Panel',{1});", XID, OB.ToString()); //string jsContent = rowScriptStr + formPanelScript; AddStartupScript(formPanelScript); }
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 jsContent = String.Format("var {0}=new Ext.Panel({1});", XID, OB.ToString()); AddStartupScript(jsContent); }