/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); #region Options JsObjectBuilder fieldDefaults = new JsObjectBuilder(); if (LabelWidth.Value != ConfigPropertyValue.FORM_LABELWIDTH_DEFAULT) { fieldDefaults.AddProperty("labelWidth", LabelWidth.Value); } if (LabelSeparator != ConfigPropertyValue.FORM_LABELSEPARATOR_DEFAULT) { fieldDefaults.AddProperty("labelSeparator", LabelSeparator); } if (LabelAlign != ConfigPropertyValue.FORM_LABELALIGN_DEFAULT && LabelAlign != FineUI.LabelAlign.Undefined) { fieldDefaults.AddProperty("labelAlign", LabelAlignHelper.GetName(LabelAlign)); } if (MessageTarget != ConfigPropertyValue.FORM_MESSAGETARGET_DEFAULT) { fieldDefaults.AddProperty("msgTarget", MessageTargetHelper.GetName(MessageTarget)); } if (fieldDefaults.Count > 0) { OB.AddProperty("fieldDefaults", fieldDefaults); } #endregion }
/// <summary> /// 取得页面初始化时脚本 /// </summary> /// <param name="script"></param> /// <returns></returns> private string GetStartupScript(string script) { #region beforeBuilder StringBuilder beforeBuilder = new StringBuilder(); //beforeBuilder.Append("F.init();"); // ExtJS2.2的BUG,Ext.onReady会被调用两次(在ExtJS 2.2.1中已经修正) // Ext.onReady在extjsv3.1.0中依然有问题,在IE下有时会导致页面空白,不能继续执行,只有在点击Stop按钮或者重新刷新后才行。 // http://www.extjs.net/forum/showthread.php?t=69437 // http://www.extjs.com/forum/showthread.php?p=347524#post347524 // https://extjs.net/forum/showthread.php?t=86948 //beforeBuilder.Append("if(X.initialized){return;}X.initialized=true;"); // 空白图片,只在 IE6 和 IE7 下设置(默认为 http://www.sencha.com/s.gif ),其他浏览器下使用 data URL //beforeBuilder.AppendFormat("if(Ext.isIE6||Ext.isIE7){{Ext.BLANK_IMAGE_URL='{0}';}}", ResourceHelper.GetWebResourceUrl("FineUI.res.img.s.gif")); //beforeBuilder.Append("F.util.init();"); // form 相关配置 //beforeBuilder.Append("var fieldPro=Ext.form.Base.prototype;"); //beforeBuilder.AppendFormat("fieldPro.msgTarget='{0}';", MsgTargetHelper.GetName(PageManager.Instance.FormMessageTarget)); //beforeBuilder.AppendFormat("fieldPro.labelWidth={0};", PageManager.Instance.FormLabelWidth.Value); //beforeBuilder.AppendFormat("fieldPro.labelSeparator='{0}';", PageManager.Instance.FormLabelSeparator); //beforeBuilder.AppendFormat("F.util.init('{0}',{1},'{2}','{3}',{4},'{5}',{6},'{7}',{8});", // MessageTargetHelper.GetName(PageManager.Instance.FormMessageTarget), // PageManager.Instance.FormLabelWidth.Value, // PageManager.Instance.FormLabelSeparator, // //PageManager.Instance.EnableBigFont.ToString().ToLower(), // Page.ResolveUrl(ResourceHelper.GetEmptyImageUrl()), //String.Format("{0}/res/images/s.gif", GlobalConfig.GetExtjsBasePath())), //ResourceHelper.GetWebResourceUrlResAxd("FineUI.res.img.s.gif&v=1"), // //PageManager.Instance.EnableAspnetSubmitButtonAjax.ToString().ToLower(), // PageManager.Instance.EnableAjaxLoading.ToString().ToLower(), // AjaxLoadingTypeName.GetName(PageManager.Instance.AjaxLoadingType), // PageManager.Instance.EnableAjax.ToString().ToLower(), // ThemeHelper.GetName(PageManager.Instance.Theme), // PageManager.Instance.EnableFormChangeConfirm.ToString().ToLower() // ); //beforeBuilder.AppendFormat("F.util.init('{0}',{1},'{2}','{3}',{4},'{5}',{6},'{7}',{8});", // MessageTargetHelper.GetName(PageManager.Instance.FormMessageTarget), // PageManager.Instance.FormLabelWidth.Value, // PageManager.Instance.FormLabelSeparator, // //PageManager.Instance.EnableBigFont.ToString().ToLower(), // Page.ResolveUrl(ResourceHelper.GetEmptyImageUrl()), //String.Format("{0}/res/images/s.gif", GlobalConfig.GetExtjsBasePath())), //ResourceHelper.GetWebResourceUrlResAxd("FineUI.res.img.s.gif&v=1"), // //PageManager.Instance.EnableAspnetSubmitButtonAjax.ToString().ToLower(), // PageManager.Instance.EnableAjaxLoading.ToString().ToLower(), // AjaxLoadingTypeName.GetName(PageManager.Instance.AjaxLoadingType), // PageManager.Instance.EnableAjax.ToString().ToLower(), // ThemeHelper.GetName(PageManager.Instance.Theme), // PageManager.Instance.EnableFormChangeConfirm.ToString().ToLower() // ); JsObjectBuilder initObj = new JsObjectBuilder(); if (PageManager.Instance.FormMessageTarget != ConfigPropertyValue.FORM_MESSAGETARGET_DEFAULT) { initObj.AddProperty("msgTarget", MessageTargetHelper.GetName(PageManager.Instance.FormMessageTarget)); } if (PageManager.Instance.FormLabelWidth != ConfigPropertyValue.FORM_LABELWIDTH_DEFAULT) { initObj.AddProperty("labelWidth", PageManager.Instance.FormLabelWidth.Value); } if (PageManager.Instance.FormLabelSeparator != ConfigPropertyValue.FORM_LABELSEPARATOR_DEFAULT) { initObj.AddProperty("labelSeparator", PageManager.Instance.FormLabelSeparator); } //initObj.AddProperty("blankImageUrl", Page.ResolveUrl(ResourceHelper.GetEmptyImageUrl())); if (PageManager.Instance.EnableAjaxLoading != ConfigPropertyValue.ENABLE_AJAX_LOADING_DEFAULT) { initObj.AddProperty("enableAjaxLoading", PageManager.Instance.EnableAjaxLoading.ToString().ToLower()); } if (PageManager.Instance.AjaxLoadingType != ConfigPropertyValue.AJAX_LOADING_TYPE_DEFAULT) { initObj.AddProperty("ajaxLoadingType", AjaxLoadingTypeName.GetName(PageManager.Instance.AjaxLoadingType)); } if (PageManager.Instance.EnableAjax != ConfigPropertyValue.ENABLE_AJAX_DEFAULT) { initObj.AddProperty("enableAjax", PageManager.Instance.EnableAjax.ToString().ToLower()); } if (PageManager.Instance.Theme != Theme.Neptune) { initObj.AddProperty("theme", ThemeHelper.GetName(PageManager.Instance.Theme)); } if (PageManager.Instance.Language != ConfigPropertyValue.LANGUAGE_DEFAULT) { initObj.AddProperty("language", LanguageHelper.GetName(PageManager.Instance.Language)); } if (PageManager.Instance.EnableFormChangeConfirm) { initObj.AddProperty("formChangeConfirm", PageManager.Instance.EnableFormChangeConfirm.ToString().ToLower()); } if (PageManager.Instance.AjaxTimeout != ConfigPropertyValue.AJAX_TIMEOUT_DEFAULT) { initObj.AddProperty("ajaxTimeout", PageManager.Instance.AjaxTimeout); } initObj.AddProperty("_version", GlobalConfig.ProductVersion); beforeBuilder.AppendFormat("F.init({0});", initObj); //if (PageManager.Instance.BeforeAjaxPostBackScript != String.Empty) //{ // beforeBuilder.AppendFormat("F.util.beforeAjaxPostBackScript=function(){{{0}}};", PageManager.Instance.BeforeAjaxPostBackScript); //} //beforeBuilder.Append("F.ajax.hookPostBack();"); //if (PageManager.Instance.EnableAjax) //{ // if (PageManager.Instance.AjaxTimeout != ConfigPropertyValue.AJAX_TIMEOUT_DEFAULT) // { // beforeBuilder.AppendFormat("Ext.Ajax.timeout={0};", PageManager.Instance.AjaxTimeout * 1000); // } //} //if (PageManager.Instance.EnableBigFont) //{ // beforeBuilder.Append("Ext.getBody().addCls('bigfont');"); //} // WindowGroup //beforeBuilder.AppendFormat("{0}=new Ext.WindowGroup();{0}.zseed=6000;", WINDOW_DEFAULT_GROUP_ID); //// CookieProvider //beforeBuilder.AppendFormat("{0}=new Ext.state.CookieProvider();", COOKIE_PROVIDER_ID); //// HiddenFields //beforeBuilder.AppendFormat("{0}=[];", HIDDEN_FIELDS_ID); // 保存页面中可输入的表单字段状态是否发生变化的隐藏字段 //innderBuilder.AppendFormat("var sn=document.createElement('input');sn.type='hidden';sn.value='false';sn.id=sn.name='{0}';Ext.getBody().query('form')[0].appendChild(sn);", PAGE_STATE_CHANGED_ID); //innderBuilder.AppendFormat("Ext.DomHelper.append(document.forms[0],{{tag:'input',type:'hidden',value:'false',id:'{0}',name:'{0}'}});", PAGE_STATE_CHANGED_ID); //beforeBuilder.AppendFormat("F.util.setHiddenFieldValue('{0}','false');", PAGE_STATE_CHANGED_ID); // 5.预加载图片 //beforeBuilder.AppendFormat("{0}=[];", PRELOAD_IMAGES_ID); //beforeBuilder.AppendFormat("{0}.push('{1}');", PRELOAD_IMAGES_ID, ResourceHelper.GetWebResourceUrl(Page, "FineUI.res.img.default.form.error-tip-corners.gif")); //beforeBuilder.AppendFormat("box_preloadImages({0});", PRELOAD_IMAGES_ID); #endregion #region afterBuilder //StringBuilder afterBuilder = new StringBuilder(); //afterBuilder.Append("\r\n"); // 注册隐藏字段 //string hiddenFieldScript = "var itemNode=Ext.get(item[0]);if(itemNode==null){Ext.DomHelper.append(document.forms[0],{tag:'input',type:'hidden',value:item[1],id:item[0],name:item[0]});}else{itemNode.dom.value=item[1];}"; //afterBuilder.AppendFormat("Ext.each({0},function(item){{{1}}},box);", HIDDEN_FIELDS_ID, hiddenFieldScript); //afterBuilder.Append("box_alertDEBUG();"); //afterBuilder.Append("if(typeof(onReady)==='function'){onReady.call(window);}"); //afterBuilder.Append("F.util.triggerReady();"); //// 如果是回发并且允许回发注册onReady脚本 //if (!Page.IsPostBack || (Page.IsPostBack && PageManager.Instance.ExecuteOnReadyWhenPostBack)) //{ // afterBuilder.Append("if(typeof(onReady)==='function'){onReady.call(window);}"); //} //afterBuilder.Append("\r\n"); //#if DEBUG // afterBuilder.Append("window.f_render_end_time = new Date();"); //#endif #endregion // 需要注册script //string contentScript = String.Format("EXTASPNET_READY=function(){{{0}}};", beforeBuilder.ToString() + script + afterBuilder.ToString()); //contentScript += "Ext.onReady(EXTASPNET_READY);";//Ext.EventManager.on(window,'onload',function(){EXTASPNET_READY();});";//if(Ext.isIE){}else{Ext.onReady(EXTASPNET_READY);}"; string contentScript = String.Format("F.load(function(){{{0}}});", beforeBuilder.ToString() + script); //#if DEBUG // contentScript += "var x_end_time=new Date();"; //#endif #region RELEASE模式下去除换行符 if (!GlobalConfig.GetDebugMode()) { contentScript = contentScript.Replace("\r\n", ""); } #endregion string checkScript = "if(!F&&!Ext){if(confirm('ERROR: extjs folder is lost, download it now?')){window.location.href='http://fineui.com/bbs/forum.php?mod=viewthread&tid=3218';}}"; return(checkScript + contentScript); }