Exemplo n.º 1
0
        protected virtual void CallTemplate(ScriptPosition position, string template, string name, params object[] args)
        {
            if (((this.IDMode == Ext.Net.IDMode.Explicit || this.IDMode == Ext.Net.IDMode.Static) && !this.IsIdRequired) || this.IDMode == Ext.Net.IDMode.Ignore)
            {
                throw new Exception("You have to set widget's ID to call its methods");
            }

            StringBuilder sb = new StringBuilder();

            if (args != null && args.Length > 0)
            {
                foreach (object arg in args)
                {
                    if (arg is string)
                    {
                        sb.AppendFormat("{0},", TokenUtils.ParseAndNormalize(arg.ToString(), this.SafeResourceManager));
                    }
                    else
                    {
                        sb.AppendFormat("{0},", JSON.Serialize(arg, JSON.ScriptConvertersInternal));
                    }
                }
            }

            string script = template.FormatWith(this.CallID, name, sb.ToString().LeftOfRightmostOf(','));

            switch (position)
            {
            case ScriptPosition.BeforeInit:
                this.ResourceManager.RegisterBeforeClientInitScript(script);
                break;

            case ScriptPosition.AfterInit:
                this.ResourceManager.RegisterAfterClientInitScript(script);
                break;

            default:
                this.AddScript(script);
                break;
            }
        }
Exemplo n.º 2
0
        protected virtual string FormatArgs(object[] args)
        {
            StringBuilder sb = new StringBuilder();

            if (args != null && args.Length > 0)
            {
                foreach (object arg in args)
                {
                    if (arg is string)
                    {
                        sb.AppendFormat("{0},", TokenUtils.ParseAndNormalize(arg.ToString(), this.ResourceManager));
                    }
                    else
                    {
                        sb.AppendFormat("{0},", JSON.Serialize(arg));
                    }
                }
            }

            return(sb.ToString().LeftOfRightmostOf(','));
        }
Exemplo n.º 3
0
        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)) ? "<raw>".ConcatWith(script) : script);
        }
Exemplo n.º 4
0
        public virtual string ToScript()
        {
            if (this.Fn.IsNotEmpty())
            {
                return(this.WrapByDelay(this.NamePrefix + this.Fn));
            }

            string handler = TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(this.Handler, this.Owner));

            if (this.Args != null && this.Args.Length > 0)
            {
                if (this.FormatHandler)
                {
                    return(this.WrapByDelay(this.NamePrefix + "function(".ConcatWith(this.Args.Join(","), "){", handler.FormatWith(this.Args), "}")));
                }

                return(this.WrapByDelay(this.NamePrefix + "function(".ConcatWith(this.Args.Join(","), "){", handler, "}")));
            }

            return(this.WrapByDelay(this.NamePrefix + "function(){".ConcatWith(handler).ConcatWith("}")));
        }
Exemplo n.º 5
0
        public static string ParseTokens(string script, bool addRawMarker, Control seed)
        {
            TokenSettings settings = TokenUtils.Settings;

            if (script == null)
            {
                return(null);
            }

            if (script.ToString().StartsWith("<!token>"))
            {
                return(script.ToString().Substring(8));
            }

            if (settings.Disable || (settings.DisableDuringDirectEvent && X.IsAjaxRequest))
            {
                return(script);
            }

            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((addRawMarker && (isRaw || TokenUtils.IsFunction(script))) ? TokenUtils.Settings.RawMarker.ConcatWith(script) : script);
        }
Exemplo n.º 6
0
        public virtual string ValueToString()
        {
            //this.EnsureDataBind();
            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((this.Encode ? "Ext.encode(" : "").ConcatWith(
                           mode == ParameterMode.Raw ? script : JSON.Serialize(script), this.Encode ? ")" : ""));
            }
        }
Exemplo n.º 7
0
        protected virtual void CallTemplate(ScriptPosition position, string template, string name, params object[] args)
        {
            StringBuilder sb = new StringBuilder();

            if (args != null && args.Length > 0)
            {
                foreach (object arg in args)
                {
                    if (arg is string)
                    {
                        sb.AppendFormat("{0},", TokenUtils.ParseAndNormalize(arg.ToString(), this.SafeResourceManager));
                    }
                    else
                    {
                        sb.AppendFormat("{0},", JSON.Serialize(arg, JSON.AltConvertersInternal));
                    }
                }
            }

            string script = template.FormatWith(this.CallID, name, sb.ToString().LeftOfRightmostOf(','));

            switch (position)
            {
            case ScriptPosition.BeforeInit:
                this.ResourceManager.RegisterBeforeClientInitScript(script);
                break;

            case ScriptPosition.AfterInit:
                this.ResourceManager.RegisterAfterClientInitScript(script);
                break;

            default:
                this.AddScript(script);
                break;
            }
        }
Exemplo n.º 8
0
        public virtual void AddScript(string script)
        {
            if (this.IsProxy || this.AlreadyRendered)
            {
                if (HttpContext.Current == null)
                {
                    ResourceManager.AddInstanceScript(script);
                    return;
                }

                ResourceManager rm = ResourceManager.GetInstance(HttpContext.Current);

                if (HttpContext.Current.CurrentHandler is Page && rm != null)
                {
                    rm.AddScript(script);
                }
                else
                {
                    ResourceManager.AddInstanceScript(script);
                }

                return;
            }

            if (script.IsNotEmpty() && !this.IsParentDeferredRender && this.Visible)
            {
                if (this.AlreadyRendered && this.HasResourceManager)
                {
                    this.ResourceManager.RegisterOnReadyScript(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this)));
                }
                else
                {
                    this.ProxyScripts.Add(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this)));
                }
            }
        }
Exemplo n.º 9
0
        public virtual string ToConfigString()
        {
            if (this.Format != RendererFormat.None)
            {
                if (this.FormatArgs != null && this.FormatArgs.Length > 0)
                {
                    return(new JFunction("return Ext.util.Format.".ConcatWith(
                                             this.Format.ToString().ToLowerCamelCase(),
                                             "(value,",
                                             this.FormatArgs.Join(),
                                             ");"), "value").ToScript());
                }

                if (this.Handler.IsEmpty())
                {
                    return("Ext.util.Format.".ConcatWith(this.Format.ToString().ToLowerCamelCase()));
                }
            }

            if (this.Handler.IsNotEmpty())
            {
                string temp = TokenUtils.ParseTokens(this.Handler, this.Owner);

                if (TokenUtils.IsRawToken(temp))
                {
                    return(TokenUtils.ReplaceRawToken(temp));
                }

                return(new JFunction(
                           temp,
                           this.Args)
                       .ToScript());
            }

            return(TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(this.Fn)));
        }
Exemplo n.º 10
0
 public static string ParseAndNormalize(string script)
 {
     return(TokenUtils.ParseAndNormalize(script, null));
 }
Exemplo n.º 11
0
        public static string ReplaceIDTokens(string script, Control seed)
        {
            script = TokenUtils.ReplaceDirectMethods(script, seed);

            Control control = null;

            string[] parts = null;

            foreach (Match match in ID_Pattern_RE.Matches(script))
            {
                parts = match.Value.Between("{", "}").Split('.');

                control = ControlUtils.FindControl(seed, parts[0]);

                if (control != null)
                {
                    if (parts.Length == 2)
                    {
                        PropertyInfo prop = control.GetType().GetProperty(parts[1]);

                        if (prop != null)
                        {
                            object value = prop.GetValue(control, null);

                            if (value == null)
                            {
                                value = ReflectionUtils.GetDefaultValue(prop);
                            }

                            if (value is string)
                            {
                                string val = TokenUtils.ParseTokens(value.ToString(), control);

                                if (TokenUtils.IsRawToken(val))
                                {
                                    val = JSON.Serialize(TokenUtils.ReplaceRawToken(val)).Chop();
                                }
                                else
                                {
                                    val = JSON.Serialize(val);
                                }

                                script = script.Replace(match.Value, val);
                            }
                            else
                            {
                                script = script.Replace(match.Value, JSON.Serialize(value));
                            }
                        }
                    }
                    else
                    {
                        if (control is Observable || control is UserControl)
                        {
                            script = script.Replace(match.Value, control.ClientID);
                        }
                        else
                        {
                            script = script.Replace(match.Value, "Ext.get(\"" + control.ClientID + "\")");
                        }
                    }
                }
                else
                {
                    script = script.Replace(match.Value, "Ext.get(\"" + parts[0] + "\")");
                }
            }

            return(script);
        }
Exemplo n.º 12
0
        public static void Redirect(string url, string msg, string msgCls)
        {
            if (url.IsEmpty())
            {
                throw new ArgumentNullException("url", "The redirection url is empty");
            }

            if (msg.IsNotEmpty())
            {
                X.Mask.Show(new MaskConfig
                {
                    Msg    = msg,
                    MsgCls = msgCls
                });
            }

            Ext.Net.ResourceManager.AddInstanceScript("window.location=\"".ConcatWith(TokenUtils.IsRawToken(url) ? url : ExtNetTransformer.ResolveUrl(url), "\";"));
        }
Exemplo n.º 13
0
 public virtual void AddManagedListener(string item, string eventName, string fn, string scope, HandlerConfig options)
 {
     fn = TokenUtils.ParseAndNormalize(fn, this).Trim('"');
     this.Call("addManagedListener", new JRawValue(item), eventName, new JRawValue(fn), new JRawValue(scope), new JRawValue(options.Serialize()));
 }
Exemplo n.º 14
0
 public override string ToScript()
 {
     return(this.currentConfig != null?this.InstanceOf.ConcatWith(".show(", TokenUtils.ParseTokens(this.currentConfig.ToScript(), this.Page), ");") : "");
 }
Exemplo n.º 15
0
        public void GenerateProxy(StringBuilder sb, string controlID)
        {
            sb.Append(this.Attribute.Alias.IsEmpty() ? this.Name : this.Attribute.Alias);
            sb.Append(":function(");

            foreach (ParameterInfo parameterInfo in this.Params)
            {
                sb.Append(parameterInfo.Name);
                sb.Append(",");
            }
            sb.Append("config");
            sb.Append("){");
            sb.Append("Ext.net.DirectMethod.request(\"");
            sb.Append(this.Name);
            sb.Append("\",Ext.applyIf(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 (controlID.IsNotEmpty())
            {
                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 (this.Attribute.Msg.IsNotEmpty())
                {
                    sb.Append(",msg:").Append(JSON.Serialize(this.Attribute.Msg));
                }

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

                if (this.Attribute.CustomTarget.IsNotEmpty())
                {
                    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 && this.Attribute.CustomTarget.IsNotEmpty())
                {
                    ResourceManager sm = null;

                    if (HttpContext.Current != null)
                    {
                        sm = ResourceManager.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 == DirectEventType.Load)
            {
                sb.Append(needComma ? "," : "");
                sb.Append("type:\"load\"");
                needComma = true;
            }

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

            if (this.Attribute.RethrowException)
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("rethrowException:{0}", this.Attribute.RethrowException.ToString().ToLowerInvariant());
                needComma = true;
            }


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

            if (this.Attribute.DisableCaching.HasValue)
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("disableCaching:{0}", this.Attribute.DisableCaching.Value.ToString().ToLowerInvariant());
                needComma = true;
            }

            if (this.Attribute.DisableCachingParam != "_dc")
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("disableCachingParam:{0}", this.Attribute.DisableCachingParam);
                needComma = true;
            }

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

            if (this.Attribute.CompleteFn.IsNotEmpty())
            {
                sb.Append(needComma ? "," : "");
                sb.AppendFormat("complete:{0}", this.Attribute.CompleteFn);
                needComma = true;
            }

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

            sb.Append("}));}");
        }
Exemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="script"></param>
 /// <param name="seed"></param>
 /// <returns></returns>
 public static string ParseTokens(string script, Control seed)
 {
     return(TokenUtils.ParseTokens(script, true, seed));
 }
Exemplo n.º 17
0
 public virtual void Unregister(string target)
 {
     target = "Ext.net.getEl({0})".FormatWith(TokenUtils.ParseAndNormalize(target));
     this.Call("unregister", new JRawValue(target));
 }
Exemplo n.º 18
0
        public virtual string Build(RenderMode mode, string element, int?index, bool selfRendering, bool forceResources, string method, bool forceLazy, bool clearContainer)
        {
            this.ForceResources = forceResources;

            if (this.script == null)
            {
                AbstractComponent cmp = this.Control as AbstractComponent;

                bool isLazy = this.Control.IsLazy;

                if (mode == RenderMode.Auto)
                {
                    mode = isLazy ? RenderMode.AddTo : RenderMode.RenderTo;
                }

                switch (mode)
                {
                case RenderMode.RenderTo:
                    if (cmp != null)
                    {
                        if (string.IsNullOrEmpty(element))
                        {
                            element = TokenUtils.RawWrap("Ext.net.ResourceMgr.getRenderTarget()");
                        }

                        if (this.Control.IsLazy)
                        {
                            throw new Exception("Lazy control cannot be rendered with RenderTo mode.");
                        }

                        cmp.RenderTo = element;
                    }
                    break;

                case RenderMode.AddTo:
                case RenderMode.Replace:
                case RenderMode.InsertTo:
                    if (cmp == null)
                    {
                        throw new Exception("AddTo mode can be applied to only a AbstractComponent.");
                    }

                    if (string.IsNullOrEmpty(element))
                    {
                        if (isLazy)
                        {
                            element = this.Control.ParentComponent.ClientID;
                        }
                        else
                        {
                            throw new Exception("You must specify an Element for the AddTo mode.");
                        }
                    }

                    if (mode == RenderMode.InsertTo && index == null)
                    {
                        throw new Exception("You have to provide the index for the InsertTo mode.");
                    }

                    cmp.PreventRenderTo = true;
                    break;
                }

                Page pageHolder = null;
                this.Control.IsDynamicLazy     = isLazy || (mode == RenderMode.AddTo || mode == RenderMode.InsertTo || mode == RenderMode.Replace);
                this.Control.TopDynamicControl = true;
                //this.Control.ForceIdRendering = true;
                this.Control.ForceLazy = forceLazy || this.Control.IsDynamicLazy;
                this.ResourceManager   = Ext.Net.ResourceManager.GetInstance();

                if (selfRendering && this.Control.Page == null)
                {
                    pageHolder = new SelfRenderingPage();

                    ResourceManager newMgr = new ResourceManager(true);
                    newMgr.RenderScripts = ResourceLocationType.None;
                    newMgr.RenderStyles  = ResourceLocationType.None;
                    newMgr.IDMode        = IDMode.Explicit;
                    newMgr.IsDynamic     = true;
                    pageHolder.Controls.Add(newMgr);

                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = newMgr;
                    }

                    pageHolder.Controls.Add(this.Control);
                }
                else if (selfRendering && this.Control.Page is ISelfRenderingPage)
                {
                    pageHolder = this.Control.Page;
                    ResourceManager newMgr = Ext.Net.Utilities.ControlUtils.FindControl <ResourceManager>(pageHolder);
                    if (this.ResourceManager == null)
                    {
                        this.ResourceManager = newMgr;
                    }
                    if (newMgr != null)
                    {
                        newMgr.IsDynamic = true;
                    }
                }

                StringBuilder sb = new StringBuilder();

                if (this.Control.ClientID.IsNotEmpty() && !this.Control.IsGeneratedID)
                {
                    sb.AppendFormat("Ext.net.ResourceMgr.destroyCmp(\"{0}\");", this.Control.ClientID);
                }

                if (clearContainer)
                {
                    if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                    {
                        string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                        sb.AppendFormat("{0}.removeAll();", elementGet);
                    }
                    else if (mode != RenderMode.Replace)
                    {
                        sb.AppendFormat("Ext.net.getEl(\"{0}\").update();", element);
                    }
                }

                List <BaseControl> childControls = this.FindControls(this.Control, selfRendering, sb, null, null);
                childControls.Insert(0, this.Control);

                if (selfRendering && pageHolder != null)
                {
                    pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = new object();
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (c.AutoDataBind)
                        {
                            c.DataBind();
                        }
                    }
                }

                if (selfRendering)
                {
                    this.RegisterHtml(sb, pageHolder);

                    if (pageHolder != null)
                    {
                        pageHolder.Items["Ext.Net.DeferInitScriptGeneration"] = null;
                    }

                    List <BaseControl> newChildControls = this.FindControls(this.Control, false, sb, null, null);
                    newChildControls.Insert(0, this.Control);

                    foreach (BaseControl c in newChildControls)
                    {
                        if (!childControls.Contains(c) && (c.Visible || Object.ReferenceEquals(c, this.Control)))
                        {
                            if (c.AutoDataBind)
                            {
                                c.DataBind();
                            }
                        }
                    }

                    childControls = newChildControls;
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        c.OnClientInit(true);
                        c.RegisterBeforeAfterScript();
                    }
                }

                string methodTemplate = string.Concat(".", method ?? "add", "(");

                if (mode == RenderMode.InsertTo)
                {
                    methodTemplate = string.Concat(".", method ?? "insert", "(", index.Value, ",");
                }

                foreach (BaseControl c in childControls)
                {
                    if (c.Visible || Object.ReferenceEquals(c, this.Control))
                    {
                        if (Object.ReferenceEquals(c, this.Control) && (this.Control.IsLazy || this.Control.ForceLazy))
                        {
                            this.ScriptClientInitBag.Add(c.ClientInitID + "_BeforeScript", c.BeforeScript);

                            string initScript = c.BuildInitScript();
                            string topScript  = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.ItemTag), new Dictionary <string, string> {
                                { "ref", "top_dynamic_control" },
                                { "index", ResourceManager.ScriptOrderNumber.ToString() }
                            }, initScript);
                            this.ScriptClientInitBag.Add(c.ClientInitID, topScript);

                            this.ScriptClientInitBag.Add(c.ClientInitID + "_AfterScript", c.AfterScript);
                        }
                        else
                        {
                            string tokenValue = ((c is LazyObservable && c.IsIdRequired) ? "window.{0}=".FormatWith(c.ClientID) : "") + c.BuildInitScript();
                            string script     = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.ItemTag), new Dictionary <string, string> {
                                { "ref", c.IsLazy ? c.ClientInitID : "init_script" },
                                { "index", ResourceManager.ScriptOrderNumber.ToString() }
                            }, tokenValue);

                            this.ScriptClientInitBag.Add(c.ClientInitID, script);
                        }

                        c.AlreadyRendered = true;

                        foreach (KeyValuePair <long, string> proxyScript in c.ProxyScripts)
                        {
                            if (proxyScript.Value.IsNotEmpty())
                            {
                                this.ScriptOnReadyBag.Add(proxyScript.Key, proxyScript.Value);
                            }
                        }
                    }
                }

                if (this.ScriptClientInitBag.Count > 0)
                {
                    foreach (KeyValuePair <string, string> item in this.ScriptClientInitBag)
                    {
                        sb.Append(this.ScriptClientInitBag[item.Key]);
                    }
                }

                sb.Append(Transformer.NET.Net.CreateToken(typeof(Transformer.NET.AnchorTag), new Dictionary <string, string> {
                    { "id", "init_script" }
                }));

                string topAnchor = Transformer.NET.Net.CreateToken(typeof(Transformer.NET.AnchorTag), new Dictionary <string, string> {
                    { "id", "top_dynamic_control" }
                });

                if (mode == RenderMode.AddTo || mode == RenderMode.InsertTo)
                {
                    string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Append(elementGet.ConcatWith(methodTemplate, topAnchor, ");"));
                }
                else if (mode == RenderMode.Replace)
                {
                    sb.Append("Ext.net._renderTo(arguments[0],".ConcatWith(topAnchor, ");"));
                }

                foreach (KeyValuePair <long, string> script in this.ScriptOnReadyBag)
                {
                    sb.Append(script.Value);
                }

                if (mode == RenderMode.Replace)
                {
                    string elementGet = element.Contains(".") ? element : "Ext.getCmp({0})".FormatWith(JSON.Serialize(element));
                    sb.Insert(0, elementGet + ".replace(function(){");
                    sb.Append("});");
                }

                this.script = this.RegisterResources(sb.ToString());
            }

            this.Control.ForceLazy = false;

            return(Transformer.NET.Html.HtmlTransformer.Transform(this.script));
        }
Exemplo n.º 19
0
 public static string ParseAndNormalize(string script, Control seed)
 {
     return(TokenUtils.NormalizeRawToken(TokenUtils.ParseTokens(script, seed)));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes the drag drop object's constraints to restrict movement to a certain element.
 /// </summary>
 /// <param name="constrainTo">The element to constrain to.</param>
 public void ConstrainTo(string constrainTo)
 {
     this.Call("constrainTo", new JRawValue(string.Concat("Ext.net.getEl(", TokenUtils.ParseAndNormalize(constrainTo), ")")));
 }
Exemplo n.º 21
0
        public static string ReplaceDirectMethods(string script, Control seed)
        {
            if (TokenUtils.IsDirectMethodsToken(script))
            {
                string ns = ResourceManager.GlobalNormalizedDirectMethodNamespace;
#if MVC
                if (Ext.Net.MVC.MvcResourceManager.IsMVC || (seed is BaseControl && ((BaseControl)seed).IsMVC))
                {
                    if (HttpContext.Current != null && HttpContext.Current.Request.RequestContext.RouteData.DataTokens["area"] != null)
                    {
                        return(script.Replace(TokenUtils.Settings.DirectMethodsPattern, ns.ConcatWith(".", HttpContext.Current.Request.RequestContext.RouteData.DataTokens["area"].ToString())));
                    }

                    return(script.Replace(TokenUtils.Settings.DirectMethodsPattern, ns));
                }
#endif

                UserControl parent = seed as UserControl;

                if (parent == null)
                {
                    parent = ReflectionUtils.GetTypeOfParent(seed, typeof(System.Web.UI.UserControl)) as UserControl;
                }

                ResourceManager sm = null;

                if (parent != null && !(parent is MasterPage && seed.Parent is System.Web.UI.WebControls.ContentPlaceHolder))
                {
                    string id = ResourceManager.GetControlIdentification(parent, null);

                    if (id.IsNotEmpty())
                    {
                        id = ".".ConcatWith(id);
                    }

                    sm = ResourceManager.GetInstance(HttpContext.Current);

                    if (sm != null)
                    {
                        ns = sm.NormalizedDirectMethodNamespace;
                    }

                    return(script.Replace(TokenUtils.Settings.DirectMethodsPattern, ns.ConcatWith(id)));
                }
                else
                {
                    Page parentPage = seed as Page;

                    if (parentPage == null)
                    {
                        parentPage = ReflectionUtils.GetTypeOfParent(seed, typeof(System.Web.UI.Page)) as System.Web.UI.Page;
                    }


                    sm = ResourceManager.GetInstance();

                    if (sm != null)
                    {
                        ns = sm.NormalizedDirectMethodNamespace;
                    }

                    return(script.Replace(TokenUtils.Settings.DirectMethodsPattern, ns));
                }
            }

            return(script);
        }
Exemplo n.º 22
0
 /// <summary>
 /// Sets the element to the location of the mousedown or click event, maintaining the cursor location relative to the location on the element that was clicked. Override this if you want to place the element in a location other than where the cursor is.
 /// </summary>
 /// <param name="el">the element to move</param>
 /// <param name="iPageX">the X coordinate of the mousedown or drag event</param>
 /// <param name="iPageY">the Y coordinate of the mousedown or drag event</param>
 public void AlignElWithMouse(string el, int iPageX, int iPageY)
 {
     this.Call("alignElWithMouse", new JRawValue(string.Concat("Ext.net.getEl(", TokenUtils.ParseAndNormalize(el), ".dom")), iPageX, iPageY);
 }
Exemplo n.º 23
0
 public virtual void AddScript(string script)
 {
     if (script.IsNotEmpty() && !this.IsParentDeferredRender && this.Visible)
     {
         if (this.AlreadyRendered && this.HasResourceManager)
         {
             this.ResourceManager.RegisterOnReadyScript(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this)));
         }
         else
         {
             this.ProxyScripts.Add(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this)));
         }
     }
 }
Exemplo n.º 24
0
 public virtual void AddListener(string eventName, string fn, string scope)
 {
     fn = TokenUtils.ParseAndNormalize(fn, this).Trim('"');
     this.Call("on", eventName.ToLowerInvariant(), new JRawValue(fn), new JRawValue(scope));
 }
Exemplo n.º 25
0
 protected void ScriptHelper(string name, AbstractComponent target, object data)
 {
     this.ScriptHelper(name, TokenUtils.RawWrap(target.ClientID + ".getContentTarget()"), data);
 }
Exemplo n.º 26
0
 public virtual void AddManagedListener(string item, string eventName, string fn)
 {
     fn = TokenUtils.ParseAndNormalize(fn, this).Trim('"');
     this.Call("addManagedListener", new JRawValue(item), eventName, new JRawValue(fn));
 }
Exemplo n.º 27
0
 public static string ParseTokens(string script)
 {
     return(TokenUtils.ParseTokens(script, TokenUtils.Page));
 }
Exemplo n.º 28
0
        private void WriteValue(string name, object value)
        {
            if (value is string)
            {
                if (value.ToString().StartsWith("<!token>"))
                {
                    value = value.ToString().Substring(8);
                }
                else
                {
                    value = TokenUtils.ParseTokens(value.ToString(), this.owner);
                }

                string temp = value.ToString();

                if (temp.StartsWith("<string>"))
                {
                    int count = 8;

                    if (temp.StartsWith("<string><raw>"))
                    {
                        count = 13;
                    }

                    this.writer.WritePropertyName(name);
                    this.writer.WriteValue(temp.Substring(count));
                    return;
                }

                if (temp.StartsWith("<raw>"))
                {
                    this.WriteRawValue(name, temp.Substring(5));
                    return;
                }
            }

            this.writer.WritePropertyName(name);

            if (value is Unit)
            {
                Unit unit = (Unit)value;

                if (unit.Type == UnitType.Pixel)
                {
                    this.writer.WriteValue(Convert.ToInt32(((Unit)value).Value));
                }
                else if (unit.Type == UnitType.Percentage)
                {
                    this.writer.WriteValue(unit.Value.ToString() + "%");
                }
            }
            else if (value is Enum)
            {
                this.writer.WriteValue(value.ToString());
            }
            else if (value is IScriptable)
            {
                this.writer.WriteValue(((IScriptable)value).ToScript());
            }
            else
            {
                this.writer.WriteValue(value);
            }
        }
Exemplo n.º 29
0
 public virtual void AddListener(string eventName, string fn, string scope, HandlerConfig options)
 {
     fn = TokenUtils.ParseAndNormalize(fn, this).Trim('"');
     this.Call("on", eventName, new JRawValue(fn), new JRawValue(scope), new JRawValue(options.ToJsonString()));
 }