Esempio n. 1
0
        /// <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()));
        }
Esempio n. 2
0
        /// <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)));
            }
        }
Esempio n. 3
0
        /// <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);
        }