1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    bweiler is on a distinguished road

      0  

    Default Application reference required in the view to fire an event from a view.

    I need to fire events from a view. To do this, I have set listeners on the application as described in the documentation. However, based on the documentation, the only way to fire these events from the map view is to get a reference to the application (see getBubbleTarget()) in the view code below).

    The Sencha Touch team discourages coding practices where the view has knowledge of the application, but the documentation does not explain how to avoid this when using fireEvent.


    How do I fire events from a view that will be captured by the application without the view knowing about the application?


    Controller:
    Code:
            // Setup the custom event listeners
            this.getApplication().on({
                ...
                geocode: this.loadSettings,
                popup: this.showMsgBox,
                scope: this
            });

    View:
    Code:
    Ext.define('Bill.view.Map', {
        extend: 'Ext.Map',
        xtype: 'mapview',
        mixins: ['Ext.mixin.Observable'],
        //requires: ['Ext.mixin.Observable'],
        
        config: {
            layout: 'fit',
            mapOptions: {
                disableDefaultUI: true,
                zoomControl: true,
                zoom: 10
            },
        },
        
        initialize: function() {
              this.enableBubble('location');
              this.enableBubble('geocode');
              this.enableBubble('popup');
        },
    ...
    
    
        // Fire the location event
        this.fireEvent('geocode');
    
    
    ...
    
    
        getBubbleTarget: function() {
            
            var globals = Bill.globals.mapGlobals;
    
    
            return globals.application;
        }

  2. #2
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    580
    Vote Rating
    30
    estesbubba has a spectacular aura about estesbubba has a spectacular aura about

      0  

    Default

    Get rid of mixins, enableBubble, and getBubbleTarget and in your controller do:

    Code:
    config: {
        control: {
            'mapview': {
                location: 'onLocation',
                geocode: 'onGeocode',
                ...
            }
        }
    },

  3. #3
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,402
    Vote Rating
    1103
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default

    You should fire events on the component and the application (or better the controller) can listen for events on the component to handle application logic.

    However, if you want to the application instance is now cached on the namespace so if your Application has a name of 'MyApp' then you can get the application instance via MyApp.app
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #4
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    bweiler is on a distinguished road

      0  

    Thumbs up

    Quote Originally Posted by estesbubba View Post
    Get rid of mixins, enableBubble, and getBubbleTarget and in your controller do:

    Code:
    config: {
        control: {
            'mapview': {
                location: 'onLocation',
                geocode: 'onGeocode',
                ...
            }
        }
    },
    This is exactly what I was looking for, but could not figure out. Now it makes perfect sense.

    Thanks!!!

Thread Participants: 2