Exemplo n.º 1
0
        internal virtual string Build(string template, params object[] args)
        {
            if (this.sm == null)
            {
                this.sm = ScriptManager.GetInstance(HttpContext.Current);
            }

            if (this.page == null && this.sm != null)
            {
                this.page = this.sm.Page;
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] is string)
                {
                    args[i] = TokenUtils.ParseAndNormalize(args[i].ToString(), this.sm);
                }
            }

            return(string.Format(template, args));
        }
Exemplo n.º 2
0
        public void GenerateProxy(StringBuilder sb, string controlID)
        {
            sb.Append(this.Name);
            sb.Append(":function(");

            foreach (ParameterInfo parameterInfo in this.Params)
            {
                sb.Append(parameterInfo.Name);
                sb.Append(",");
            }
            sb.Append("config");
            sb.Append("){");
            sb.Append("Coolite.AjaxMethod.request(\"");
            sb.Append(this.Name);
            sb.Append("\",Ext.apply(config || {}, {");

            int  index     = 0;
            bool needComma = false;

            if (this.Params.Length > 0)
            {
                sb.Append("params:{");
                foreach (ParameterInfo parameterInfo in this.Params)
                {
                    sb.Append(parameterInfo.Name);
                    sb.Append(":");
                    sb.AppendFormat(parameterInfo.Name);
                    index++;
                    if (index < this.Params.Length)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("}");
                needComma = true;
            }

            if (this.Method.IsStatic)
            {
                sb.Append(needComma ? "," : "");
                sb.Append("specifier:\"static\"");
                needComma = true;
            }

            if (!string.IsNullOrEmpty(controlID))
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("control:\"{0}\"", controlID);
                needComma = true;
            }

            if (this.Attribute.Method == HttpMethod.GET)
            {
                sb.Append(needComma ? "," : "");
                sb.Append("method:\"GET\"");
                needComma = true;
            }

            if (this.Attribute.ShowMask)
            {
                sb.Append(needComma ? "," : "");
                sb.Append("eventMask:{showMask:true");

                if (!string.IsNullOrEmpty(this.Attribute.Msg))
                {
                    sb.Append(",msg:").Append(JSON.Serialize(this.Attribute.Msg));
                }

                if (!string.IsNullOrEmpty(this.Attribute.MsgCls))
                {
                    sb.Append(",msgCls:").Append(JSON.Serialize(this.Attribute.MsgCls));
                }

                if (!string.IsNullOrEmpty(this.Attribute.CustomTarget))
                {
                    this.Attribute.Target = MaskTarget.CustomTarget;
                }

                if (this.Attribute.Target != MaskTarget.Page)
                {
                    sb.Append(",target:").Append(JSON.Serialize(this.Attribute.Target.ToString().ToLower()));
                }

                if (this.Attribute.Target == MaskTarget.CustomTarget && !string.IsNullOrEmpty(this.Attribute.CustomTarget))
                {
                    ScriptManager sm = null;

                    if (HttpContext.Current != null)
                    {
                        sm = ScriptManager.GetInstance(HttpContext.Current);
                    }

                    string script = TokenUtils.ReplaceRawToken((sm != null) ? TokenUtils.ParseTokens(this.Attribute.CustomTarget, sm) : TokenUtils.ParseAndNormalize(this.Attribute.CustomTarget));

                    sb.Append(",customTarget:").Append(script);

                    //sb.Append(",customTarget:").Append(JSON.Serialize(this.Attribute.CustomTarget));
                }

                sb.Append("}");
                needComma = true;
            }

            if (this.Attribute.Type == AjaxEventType.Load)
            {
                sb.Append(needComma ? "," : "");
                sb.Append("type:\"load\"");
                needComma = true;
            }

            if (this.Attribute.ViewStateMode != ViewStateMode.Default)
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("viewStateMode:\"{0}\"", this.Attribute.ViewStateMode.ToString().ToLowerInvariant());
                needComma = true;
            }

            if (this.Attribute.Timeout != 30000)
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("timeout:{0}", this.Attribute.Timeout);
                needComma = true;
            }

            if (!string.IsNullOrEmpty(this.Attribute.SuccessFn))
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("success:{0}", this.Attribute.SuccessFn);
                needComma = true;
            }

            if (!string.IsNullOrEmpty(this.Attribute.FailureFn))
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("failure:{0}", this.Attribute.FailureFn);
            }

            sb.Append("}));}");
        }
Exemplo n.º 3
0
        public virtual void AddListener(string eventName, string handler, string scope, HandlerConfig options)
        {
            string template = "{0}.on(\"{1}\",{2},{3},{4});";

            this.AddScript(template, this.ClientID, eventName, TokenUtils.ParseAndNormalize(handler, this), scope, options.ToJsonString());
        }
Exemplo n.º 4
0
 public static string ParseAndNormalize(string script)
 {
     return(TokenUtils.ParseAndNormalize(script, null));
 }
Exemplo n.º 5
0
        public virtual void AddListener(string eventName, string handler, string scope)
        {
            string template = "{0}.on(\"{1}\",{2},{3});";

            this.AddScript(template, this.ClientID, eventName.ToLower(), TokenUtils.ParseAndNormalize(handler, this), scope);
        }