Results 1 to 4 of 4

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

  1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
      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
    628
    Vote Rating
    40
      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
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #4
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
      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!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •