public static string ParseTokens(string script, Control seed) { if (seed == null) { seed = TokenUtils.Page; } bool isRaw = ( TokenUtils.IsAlertToken(script) || TokenUtils.IsRawToken(script) || TokenUtils.IsSelectToken(script)); script = TokenUtils.ReplaceIDTokens(script, seed); script = TokenUtils.ReplaceSelectTokens(script); script = TokenUtils.ReplaceAlertToken(script); script = TokenUtils.ReplaceRawToken(script); script = TokenUtils.ReplaceFunctionToken(script); return((isRaw || TokenUtils.IsFunction(script)) ? string.Concat("<raw>", script) : script); }
public static string ReplaceIDTokens(string script, Control seed) { script = TokenUtils.ReplaceAjaxMethods(script, seed); script = TokenUtils.ReplaceFuncToken(script); Regex regex = new Regex(TokenUtils.ID_PATTERN); MatchCollection matches = regex.Matches(script); Control control = null; string id = ""; foreach (Match match in matches) { id = match.Value.Remove(match.Value.Length - 1).Remove(0, 2); control = ControlUtils.FindControl(seed, id); if (control != null) { if (control is Layout) { Component component = ((Layout)control).ParentComponent; script = script.Replace(match.Value, component != null ? string.Concat(component.ClientID, ".getLayout()") : control.ClientID); } else if (control is Observable || control is UserControl) { script = script.Replace(match.Value, control.ClientID); } else { script = script.Replace(match.Value, string.Concat("Ext.get(\"", control.ClientID, "\")")); } } else { script = script.Replace(match.Value, string.Concat("Ext.get(\"", match.Value.Remove(match.Value.Length - 1).Remove(0, 2), "\")")); } } return(script); }
protected override void OnBeforeClientInit(Observable sender) { base.OnBeforeClientInit(sender); if (!string.IsNullOrEmpty(this.OnClientClick)) { this.On("click", new JFunction(TokenUtils.ParseTokens(this.OnClientClick, this), "el", "e")); } string fn = this.PostBackFunction; if (this.ParentForm != null && !string.IsNullOrEmpty(fn)) { this.On("click", new JFunction(fn)); } if (this.EnableToggle || !string.IsNullOrEmpty(this.ToggleGroup)) { fn = "this.getPressedField().setValue(pressed ? \"true\" : \"false\");"; this.On("toggle", new JFunction(fn, "b", "pressed")); } }
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)); }
public string ValueToString() { ParameterMode mode = this.Mode; if (this.Params.Count > 0) { return(this.ToStringInnerParams(null)); } else { string script = TokenUtils.ParseTokens(this.Value, this.Owner); if (TokenUtils.IsRawToken(script)) { mode = ParameterMode.Raw; script = TokenUtils.ReplaceRawToken(script); } return(string.Concat(this.Encode ? "Ext.encode(" : "", mode == ParameterMode.Raw ? script : JSON.Serialize(script), this.Encode ? ")" : "")); } }
public virtual string ToConfigString() { if (this.Format != RendererFormat.None) { if (this.FormatArgs != null && this.FormatArgs.Length > 0) { return(new JFunction( string.Concat( "return Ext.util.Format.", StringUtils.ToLowerCamelCase(this.Format.ToString()), "(value,", StringUtils.Concat(this.FormatArgs), ");"), "value").ToString()); } if (string.IsNullOrEmpty(this.Handler)) { return(string.Concat("Ext.util.Format.", StringUtils.ToLowerCamelCase(this.Format.ToString()))); } } if (!string.IsNullOrEmpty(this.Handler)) { string temp = TokenUtils.ParseTokens(this.Handler, this.Owner); if (TokenUtils.IsRawToken(temp)) { return(TokenUtils.ReplaceRawToken(temp)); } return(new JFunction( temp, new string[] { "value", "metadata", "record", "rowIndex", "colIndex", "store" }) .ToString()); } return(TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(this.Fn))); }
public static void Redirect(string url, string msg, string msgCls) { ScriptManager sm = ScriptManager.GetInstance(HttpContext.Current); if (sm == null) { throw new InvalidOperationException("The ScriptManager can not be found during the Ext.Redirect."); } if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url", "The redirection url is empty"); } if (!string.IsNullOrEmpty(msg)) { Mask.Show(new Mask.Config { Msg = msg, MsgCls = msgCls }); } sm.AddScript(string.Concat("window.location=\"", (Coolite.Utilities.UrlUtils.IsUrl(url) || sm.Page == null || TokenUtils.IsRawToken(url)) ? url : sm.Page.ResolveUrl(url), "\";")); }
public virtual void AddScript(string script) { if (!string.IsNullOrEmpty(script) && !this.IsParentDeferredRender && this.Visible) { this.ProxyScripts.Add(ScriptManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this))); } }
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("}));}"); }
public static string ParseTokens(string script) { return(TokenUtils.ParseTokens(script, TokenUtils.Page)); }
public static string ParseAndNormalize(string script, Control seed) { return(TokenUtils.NormalizeRawToken(TokenUtils.ParseTokens(script, seed))); }
public static string ParseAndNormalize(string script) { return(TokenUtils.ParseAndNormalize(script, null)); }
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()); }
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); }