Exemplo n.º 1
0
        public HandlerConfig GetListenerConfig()
        {
            HandlerConfig cfg = new HandlerConfig();

            cfg.Scope           = this.Scope == "this" ? null : this.Scope;
            cfg.Buffer          = this.Buffer;
            cfg.Delay           = this.Delay;
            cfg.Single          = this.Single;
            cfg.Delegate        = this.Delegate == "" ? null : this.Delegate;
            cfg.Normalized      = this.Normalized;
            cfg.PreventDefault  = this.PreventDefault;
            cfg.StopEvent       = this.StopEvent;
            cfg.StopPropagation = this.StopPropagation;

            return(cfg);
        }
Exemplo n.º 2
0
        protected override void OnBeforeClientInit(Observable sender)
        {
            if (this.StoreID.IsNotEmpty() && this.Store.Primary != null)
            {
                throw new Exception(string.Format("Please do not set both the StoreID property on {0} and <Store> inner property at the same time.", this.ID));
            }

            if (this.AutoPostBack)
            {
                EventHandler handler = (EventHandler)Events[EventSelectionChanged];

                if (handler != null)
                {
                    this.On("change", new JFunction(this.PostBackFunction));
                }
            }

            if (this.StoreID.IsNotEmpty() || this.Store.Primary != null)
            {
                Store store = this.Store.Primary ?? ControlUtils.FindControl <Store>(this, this.StoreID, true);

                if (store == null && !this.IsDynamic)
                {
                    throw new InvalidOperationException("The Control '{0}' could not find the StoreID of '{1}'.".FormatWith(this.ID, this.StoreID));
                }

                if (this.SelectedItems.Count > 0)
                {
                    HandlerConfig options = new HandlerConfig();
                    options.Single = true;

                    string template = "{0}.store.on(\"{1}\",{2},{3},{4});";
                    string values   = this.SelectedItems.ValuesToJsonArray();
                    string indexes  = this.SelectedItems.IndexesToJsonArray(true);


                    string suppressEvent = this.FireSelectOnLoad ? "false" : "true";
                    values  = values != "[]" ? ".setValue(".ConcatWith(values, ", true, ", suppressEvent, ");") : "";
                    indexes = indexes != "[]" ? ".setValueByIndex(".ConcatWith(indexes, ", true, ", suppressEvent, ");") : "";

                    this.AddScript(template,
                                   this.ClientID,
                                   "load",
                                   new JFunction(this.ClientID.ConcatWith(values, indexes, this.ClientID, ".clearInvalid();")).ToScript(),
                                   "this",
                                   options.ToJsonString()
                                   );
                }
            }
            else
            {
                if (this.SelectedItems.Count > 0)
                {
                    string values        = this.SelectedItems.ValuesToJsonArray();
                    string indexes       = this.SelectedItems.IndexesToJsonArray(true);
                    string suppressEvent = this.FireSelectOnLoad ? "false" : "true";

                    if (values != "[]")
                    {
                        this.Call("setValue", new JRawValue(values), true, suppressEvent);
                    }

                    if (indexes != "[]")
                    {
                        this.Call("setValue", new JRawValue(indexes), true, suppressEvent);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public virtual void Mon(Element el, string eventName, string fn, string scope, HandlerConfig options)
 {
     this.Call("mon", new JRawValue(el.Descriptor), eventName, fn, new JRawValue(scope), new JRawValue(options.Serialize()));
 }
Exemplo n.º 4
0
 public virtual void On(string eventName, string fn, string scope, HandlerConfig options)
 {
     this.AddListener(eventName, fn, scope, options);
 }
Exemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="fn"></param>
 /// <param name="options"></param>
 public virtual void Subscribe(string name, JFunction fn, HandlerConfig options)
 {
     this.Call("subscribe", name, new JRawValue(fn.ToScript()), new JRawValue(options.Serialize()));
 }
Exemplo n.º 6
0
 public virtual void Mon(Observable el, string eventName, string fn, string scope, HandlerConfig options)
 {
     this.Call("mon", new JRawValue(el.ClientID), eventName, fn, new JRawValue(scope), new JRawValue(options.Serialize()));
 }
Exemplo n.º 7
0
 public virtual void On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.AddListener(eventName, "<raw>" + fn.ToScript(), scope, options);
 }
Exemplo n.º 8
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.º 9
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value != null && value is ComponentDirectEvent)
            {
                ComponentDirectEvent directEvent = (ComponentDirectEvent)value;
                if (!directEvent.IsDefault)
                {
                    Control owner = null;
                    if (this.Owner is StateManagedItem)
                    {
                        owner = ((StateManagedItem)this.Owner).Owner;
                    }
                    else if (this.Owner is Control)
                    {
                        owner = (Control)this.Owner;
                    }

                    directEvent.Owner             = owner;
                    directEvent.ExtraParams.Owner = owner;

                    foreach (Parameter param in directEvent.ExtraParams)
                    {
                        param.Owner = owner;
                    }

                    string configObject = new ClientConfig().SerializeInternal(directEvent, directEvent.Owner);

                    StringBuilder cfgObj = new StringBuilder(configObject.Length + 64);

                    cfgObj.Append(configObject);
                    cfgObj.Remove(cfgObj.Length - 1, 1);
                    cfgObj.AppendFormat("{0}control:this", configObject.Length > 2 ? "," : "");

                    if (this.PropertyName != "Click")
                    {
                        cfgObj.AppendFormat(",action:'{0}'", this.PropertyName);
                    }

                    cfgObj.Append("}");

                    directEvent.SetArgumentList(this.Owner.GetType().GetProperty(this.PropertyName));

                    JFunction     jFunction = new JFunction("var params=arguments;Ext.net.DirectEvent.confirmRequest(".ConcatWith(cfgObj.ToString(), ");"), directEvent.ArgumentList.ToArray());
                    HandlerConfig cfg       = directEvent.GetListenerConfig();
                    string        scope     = directEvent.Scope.IsEmpty() || directEvent.Scope == "this" ? "" : directEvent.Scope;

                    StringBuilder sb = new StringBuilder();
                    sb.Append("{");

                    sb.Append("fn:").Append(jFunction.ToScript()).Append(",");

                    if (scope.Length > 0)
                    {
                        sb.Append("scope:").Append(scope).Append(",");
                    }

                    string cfgStr = cfg.ToJsonString();
                    if (cfgStr != "{}")
                    {
                        sb.Append(cfgStr.Chop());
                    }

                    if (sb[sb.Length - 1] == ',')
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    sb.Append("}");

                    writer.WriteRawValue(sb.ToString());
                    return;
                }
            }
            writer.WriteRawValue("{}");
        }
Exemplo n.º 10
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()));
 }
Exemplo n.º 11
0
 public virtual Element On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     return this.AddListener(eventName, fn, scope, options);
 }
Exemplo n.º 12
0
 public virtual Element AddListener(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.Call("on", eventName, fn, new JRawValue(scope), new JRawValue(options.Serialize()));
     return this;
 }
Exemplo n.º 13
0
 public virtual Element AddListener(string eventName, string fn, string scope, HandlerConfig options)
 {
     this.Call("on", eventName, new JRawValue(TokenUtils.ParseAndNormalize(fn).Trim('"')), new JRawValue(scope), new JRawValue(options.Serialize()));
     return this;
 }
Exemplo n.º 14
0
 public virtual Element Hover(JFunction overFn, JFunction outFn, string scope, HandlerConfig options)
 {
     this.Call("hover", overFn, outFn, new JRawValue(scope), new JRawValue(options.Serialize()));
     return this;
 }
Exemplo n.º 15
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()));
 }
Exemplo n.º 16
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value != null && value is ComponentDirectEvent)
            {
                ComponentDirectEvent directEvent = (ComponentDirectEvent)value;

                if (!directEvent.IsDefault)
                {
                    Control owner = null;
                    MessageBusDirectEvent busEvent = directEvent as MessageBusDirectEvent;

                    if (this.Owner is BaseItem)
                    {
                        owner = ((BaseItem)this.Owner).Owner;
                    }
                    else if (this.Owner is Control)
                    {
                        owner = (Control)this.Owner;
                    }

                    directEvent.Owner             = owner;
                    directEvent.ExtraParams.Owner = owner;

                    foreach (Parameter param in directEvent.ExtraParams)
                    {
                        param.Owner = owner;
                    }

                    string configObject = new ClientConfig().SerializeInternal(directEvent, directEvent.Owner);

                    StringBuilder cfgObj = new StringBuilder(configObject.Length + 64);

                    cfgObj.Append(configObject);
                    cfgObj.Remove(cfgObj.Length - 1, 1);
                    cfgObj.AppendFormat("{0}control:this", configObject.Length > 2 ? "," : "");

                    if (busEvent != null)
                    {
                        cfgObj.Append(",eventType:'bus'");
                    }

                    if (this.PropertyName != "Click")
                    {
                        cfgObj.AppendFormat(",action:'{0}:'+name", busEvent != null ? busEvent.Name : this.PropertyName);
                    }

                    cfgObj.Append("}");

                    if (this.PropertyName.IsNotEmpty())
                    {
                        directEvent.SetArgumentList(this.Owner.GetType().GetProperty(this.PropertyName));
                    }

                    JFunction     jFunction = new JFunction("Ext.net.directRequest(".ConcatWith(cfgObj.ToString(), ");"), directEvent.ArgumentList.ToArray());
                    HandlerConfig cfg       = directEvent.GetListenerConfig();
                    string        scope     = directEvent.Scope.IsEmpty() || directEvent.Scope == "this" ? "" : directEvent.Scope;

                    StringBuilder sb = new StringBuilder();

                    sb.Append("{");
                    sb.Append("fn:").Append(jFunction.ToScript()).Append(",");

                    if (scope.Length > 0)
                    {
                        sb.Append("scope:").Append(scope).Append(",");
                    }

                    if (busEvent != null)
                    {
                        if (busEvent.Bus.IsNotEmpty())
                        {
                            sb.Append("bus:'").Append(busEvent.Bus).Append("',");
                        }
                        if (busEvent.Name.IsNotEmpty())
                        {
                            sb.Append("name:'").Append(busEvent.Name).Append("',");
                        }
                    }

                    string cfgStr = cfg.Serialize();

                    if (cfgStr != "{}")
                    {
                        sb.Append(cfgStr.Chop());
                    }

                    if (sb[sb.Length - 1] == ',')
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    sb.Append("}");

                    writer.WriteRawValue(sb.ToString());

                    return;
                }
            }

            writer.WriteRawValue("{}");
        }
Exemplo n.º 17
0
 public virtual void On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.AddListener(eventName, TokenUtils.Settings.RawMarker + fn.ToScript(), scope, options);
 }
Exemplo n.º 18
0
 public virtual void On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.Call("on", eventName, JRawValue.From(fn.ToScript()), JRawValue.From(scope), JRawValue.From(options.Serialize()));
 }
Exemplo n.º 19
0
 public virtual void On(string eventName, string fn, string scope, HandlerConfig options)
 {
     this.AddListener(eventName, fn, scope, options);
 }
Exemplo n.º 20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="fn"></param>
 /// <param name="options"></param>
 public virtual void Subscribe(string name, JFunction fn, HandlerConfig options)
 {
     this.Call("subscribe", name, new JRawValue(fn.ToScript()), new JRawValue(options.Serialize()));
 }
Exemplo n.º 21
0
 public virtual void Mon(Element el, string eventName, string fn, string scope, HandlerConfig options)
 {
     this.Call("mon", new JRawValue(el.Descriptor), eventName, fn, new JRawValue(scope), new JRawValue(options.Serialize()));
 }
Exemplo n.º 22
0
 public virtual void On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.Call("on", eventName, JRawValue.From(fn.ToScript()), JRawValue.From(scope), JRawValue.From(options.Serialize()));
 }
Exemplo n.º 23
0
 /// <summary>
 ///
 /// </summary>
 public virtual TBuilder AddManagedListener(string item, string eventName, string fn, string scope, HandlerConfig options)
 {
     this.ToComponent().AddManagedListener(item, eventName, fn, scope, options);
     return(this as TBuilder);
 }
Exemplo n.º 24
0
 /// <summary>
 ///
 /// </summary>
 public virtual TBuilder On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.ToComponent().On(eventName, fn, scope, options);
     return(this as TBuilder);
 }
Exemplo n.º 25
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.º 26
0
 /// <summary>
 ///
 /// </summary>
 public virtual TBuilder Mon(Observable el, string eventName, string fn, string scope, HandlerConfig options)
 {
     this.ToComponent().Mon(el, eventName, fn, scope, options);
     return(this as TBuilder);
 }
Exemplo n.º 27
0
 public virtual void On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.AddListener(eventName, "<raw>" + fn.ToScript(), scope, options);
 }
Exemplo n.º 28
0
 public virtual void NodeOn(string nodeId, string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.CallNode("on", nodeId, eventName, new JRawValue(TokenUtils.ParseAndNormalize(fn.ToScript(), this)), new JRawValue(scope), new JRawValue(options.ToJsonString()));
 }
Exemplo n.º 29
0
 public virtual void Mon(Observable el, string eventName, string fn, string scope, HandlerConfig options)
 {
     this.Call("mon", new JRawValue(el.ClientID), eventName, fn, new JRawValue(scope), new JRawValue(options.Serialize()));
 }
Exemplo n.º 30
0
 public virtual void On(string eventName, JFunction fn, string scope, HandlerConfig options)
 {
     this.AddListener(eventName, TokenUtils.Settings.RawMarker + fn.ToScript(), scope, options);
 }