/// <summary> /// 获取显示确认对话框的客户端脚本 /// </summary> /// <param name="message">对话框消息</param> /// <param name="title">对话框标题</param> /// <param name="icon">对话框图标</param> /// <param name="okScriptstring">点击确定按钮执行的客户端脚本</param> /// <param name="cancelScript">点击取消按钮执行的客户端脚本</param> /// <param name="target">弹出对话框的目标页面</param> /// <returns>客户端脚本</returns> public static string GetShowReference(string message, string title, MessageBoxIcon icon, string okScriptstring, string cancelScript, Target target) { //string msgBoxScript = "var msgBox=Ext.MessageBox;"; //msgBoxScript += "if(parent!=window){msgBox=parent.window.Ext.MessageBox;}"; if (String.IsNullOrEmpty(title)) { title = "X.util.confirmTitle"; } else { title = JsHelper.GetJsString(title.Replace("\r\n", "\n").Replace("\n", "<br/>")); } message = message.Replace("\r\n", "\n").Replace("\n", "<br/>"); JsObjectBuilder ob = new JsObjectBuilder(); ob.AddProperty("title", title, true); ob.AddProperty("msg", JsHelper.GetJsStringWithScriptTag(message), true); ob.AddProperty("buttons", "Ext.MessageBox.OKCANCEL", true); ob.AddProperty("icon", String.Format("{0}", MessageBoxIconHelper.GetName(icon)), true); ob.AddProperty("fn", String.Format("function(btn){{if(btn=='cancel'){{{0}}}else{{{1}}}}}", cancelScript, okScriptstring), true); string targetName = "window"; if (target != Target.Self) { targetName = TargetHelper.GetScriptName(target); } return(String.Format("{0}.Ext.MessageBox.show({1});", targetName, ob.ToString())); }
/// <summary> /// 获取显示提示对话框的客户端脚本 /// </summary> /// <param name="message">对话框消息</param> /// <param name="title">对话框标题</param> /// <param name="icon">对话框图标</param> /// <param name="okScript">点击确定按钮执行的客户端脚本</param> /// <param name="target">显示对话框的目标页面</param> /// <returns>客户端脚本</returns> public static string GetShowReference(string message, string title, MessageBoxIcon icon, string okScript, Target target) { #region oldcode //Ext.MessageBox.show({ // title: 'Icon Support', // msg: 'Here is a message with an icon!', // buttons: Ext.MessageBox.OK, // animEl: 'mb9', // fn: showResult, // icon: Ext.get('icons').dom.value // }); //string msgBoxScript = "var msgBox=Ext.MessageBox;"; //msgBoxScript += "if(parent!=window){msgBox=parent.window.Ext.MessageBox;}"; //title = title.Replace("\r\n", "<br/>").Replace("\n", "<br/>"); //message = message.Replace("\r\n", "<br/>").Replace("\n", "<br/>"); //JsObjectBuilder ob = new JsObjectBuilder(); //ob.AddProperty(OptionName.Title, String.Format("'{0}'", title), true); //ob.AddProperty(OptionName.Msg, String.Format("'{0}'", message), true); //ob.AddProperty(OptionName.Buttons, "Ext.MessageBox.OK", true); //ob.AddProperty(OptionName.Icon, String.Format("'{0}'", MessageBoxIconName.GetName(icon)), true); //return String.Format("box_getMessageBox({0}).show({1});", windowInstance, ob.ToString()); #endregion if (title == null) { title = String.Empty; } message = message.Replace("\r\n", "\n").Replace("\n", "<br/>"); title = title.Replace("\r\n", "\n").Replace("\n", "<br/>"); string targetScript = "window"; if (target != Target.Self) { targetScript = TargetHelper.GetScriptName(target); } if (String.IsNullOrEmpty(title) && icon == DefaultIcon && String.IsNullOrEmpty(okScript)) { return(String.Format("{0}.X.alert({1});", targetScript, JsHelper.GetJsString(message))); } else { return(String.Format("{0}.X.alert({1},{2},{3},{4});", targetScript, JsHelper.GetJsStringWithScriptTag(message), JsHelper.GetJsString(title), MessageBoxIconHelper.GetName(icon), String.IsNullOrEmpty(okScript) ? "''" : JsHelper.GetFunction(okScript))); } }