1. #11
    Sencha Premium Member lorezyra's Avatar
    Join Date
    Dec 2007
    Location
    Japan -- 日本
    Posts
    576
    Answers
    8
    Vote Rating
    6
    lorezyra will become famous soon enough

      0  

    Default


    for application wide events, use

    PHP Code:
    this.application.on({ //handle system-application wide events and calls here!!
                
    'eventName1'this.event1Handler,
                
    'eventName2'this.event2Handler,
                
    'eventName3'this.event3Handler
            
    }); 
    this.control() is used only for the local controller. If you want the event bubbled up to the application level use this.application.on()
    Perfection as a goal is a nice idea that can point one in a specific direction. However, since "perfection" is an ever changing (evolving?) and moving target, one must admit that perfection can never be obtained...

    When in doubt, check the d4mn source code!

  2. #12
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    The problem here is that <controller>.control() uses Ext.app.EventBus to inject the <component>.fireEvent() to catch events and this mechanism does not process the bubbled events.
    I include here my way to resolve this problem. It overrides the Ext.app.EventBus.dispatch() method to catch both original events and bubbled events. This way, you can catch component events from its parents or its ancestors. One thing to remember is that this will only process original events and events that are enabled to bubble (set by enableBubble() method or bubbleEvents config).
    Code:
    Ext.define('Its.override.app.EventBus', {
        override: 'Ext.app.EventBus',
        
        dispatch: function(ev, target, args) {
            var bus = this.bus,
                selectors = bus[ev],
                selector, controllers, id, i, ln,
                events = target.events,
                event = events && events[ev],
                bubbles = event && event.bubble;
    
    
            if (selectors) {
                // Loop over all the selectors that are bound to this event
                for (selector in selectors) {
                    // Check if the target matches the selector
                    // if(target.is(selector))
                    if (this.isSelectorTarget(target, selector, bubbles)) {
                        // Loop over all the controllers that are bound to this selector
                        controllers = selectors[selector];
                        for (id in controllers) {
                            // Loop over all the events that are bound to this selector on this controller
                            events = controllers[id];
                            for (i = 0, ln = events.length; i < ln; i++) {
                                event = events[i];
                                // Fire the event!
                                if (event.fire.apply(event, Array.prototype.slice.call(args, 1)) === false) {
                                    return false;
                                };
                            }
                        }
                    }
                }
            }
        },
        isSelectorTarget: function(target, selector, bubbles) {
            do {
                if(target.is(selector)){
                    return true;
                }    
            } while (bubbles && (target = target.getBubbleParent()));
            return false;
        }
    });