1. #1
    Touch Premium Member
    Join Date
    Oct 2011
    Posts
    37
    Answers
    1
    Vote Rating
    1
    rfox is on a distinguished road

      0  

    Default Answered: Call Controller Method from outside Ext namespace

    Answered: Call Controller Method from outside Ext namespace


    Hello, Got an MVC app with a google maps panel(https://github.com/VinylFox/ExtJS.ux.GMapPanel) the map has a few info windows that load files from my web server.

    These files have some data and a button/link. When the link is clicked I would like to somehow call a function within an ext controller to activate some ext based behavior.

    I've done this in a basic manner by doing:
    Code:
    Ext.get('button').on('click', function() { controller.method();});
    within the controller, to do this i need to workout when the info window is loaded and then call the above code.

    I was wondering if there is any other way to do this that might be a bit easier?

  2. Oo, that would work however it breaks a lot of the encapsulation that ext has. Im now looking to see if i can call application.fireEvent from outside as this makes more sense.

    If this doesn't work ill use your method and come back to it later thanks

    I opted for a more controlled approach that doesn't expose my controllers(theres probably an easier way to do this but meh it works):

    Above the app declaration in app.js
    Code:
    var App;
    function App(){
        var app;
        this.fireEvent = function(evt,opts){
            app.fireEvent(evt, opts);
        }
        this.setApp = function(a){
            app = a;
        }
    }
    Inside the apps launch or init:
    Code:
    App = new App();
            App.setApp(this);
    Then from the console you can do:
    Code:
    App.fireEvent()

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    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


    In the GMapPanel.js that is bundled with Ext JS 4 (that Shea created), when you add a marker, you can set the listeners config on the marker and it will be listened on.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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. #3
    Touch Premium Member
    Join Date
    Oct 2011
    Posts
    37
    Answers
    1
    Vote Rating
    1
    rfox is on a distinguished road

      0  

    Default


    This is not the issue, Sorry if i wasn't clear.

    I can get the marker's info window appearing, I need to call ext controller from inside the info windows html, this is loaded from a separate file and displayed.

    To re clarify from a different angle:

    How would I access a controller method from the console? eg. Ext.getController('BLAH').method()

    If this isnt possible how could i go about doing this?

  5. #4
    Sencha User
    Join Date
    Feb 2008
    Posts
    29
    Vote Rating
    0
    solodesignz is on a distinguished road

      0  

    Default


    What about:

    AppName.controller.ControllerName.prototype.methodToCall()

  6. #5
    Sencha User
    Join Date
    Feb 2008
    Posts
    29
    Vote Rating
    0
    solodesignz is on a distinguished road

      0  

    Default


    Well, that lets you call a function from inside the controller. But, it seems like its not the "full" controller.
    For example, I'm trying to reload a grid's store from a custom function inside the controller:

    Code:
    gridRefresh: function () {
            store = this.getUsersStore();
            store.reload();
    }
    Calling via: AppName.controller.Users.prototype.gridRefresh()

    Well, this calls the function correctly, but the controllers built in methods like: getUsersStore() are undefined.

    Anyone have any input?

  7. #6
    Touch Premium Member
    Join Date
    Oct 2011
    Posts
    37
    Answers
    1
    Vote Rating
    1
    rfox is on a distinguished road

      0  

    Default


    Problem there is your not getting an active instance of the class .

  8. #7
    Sencha User
    Join Date
    Feb 2008
    Posts
    29
    Vote Rating
    0
    solodesignz is on a distinguished road

      0  

    Default


    Yeah =/ I think i'm on to something, will let you know here in a few

  9. #8
    Sencha User
    Join Date
    Feb 2008
    Posts
    29
    Vote Rating
    0
    solodesignz is on a distinguished road

      0  

    Default


    Damn, thought this might work: http://www.sencha.com/forum/showthread.php?133931

    With listeners, but seems like its the same results... as the other one

  10. #9
    Sencha User
    Join Date
    Feb 2008
    Posts
    29
    Vote Rating
    0
    solodesignz is on a distinguished road

      0  

    Default


    Figured it out for my instance, using a global var:

    Code:
    var userController = null;
    Ext.define('RC.controller.Users', {
    	init: function () {
    		userController = this.getController('Users');
    	},
     	gridRefresh: function () {
            	store = this.getUsersStore();
            	store.load();
        	}
    });

    userController.gridRefresh();

  11. #10
    Touch Premium Member
    Join Date
    Oct 2011
    Posts
    37
    Answers
    1
    Vote Rating
    1
    rfox is on a distinguished road

      0  

    Default


    Oo, that would work however it breaks a lot of the encapsulation that ext has. Im now looking to see if i can call application.fireEvent from outside as this makes more sense.

    If this doesn't work ill use your method and come back to it later thanks

    I opted for a more controlled approach that doesn't expose my controllers(theres probably an easier way to do this but meh it works):

    Above the app declaration in app.js
    Code:
    var App;
    function App(){
        var app;
        this.fireEvent = function(evt,opts){
            app.fireEvent(evt, opts);
        }
        this.setApp = function(a){
            app = a;
        }
    }
    Inside the apps launch or init:
    Code:
    App = new App();
            App.setApp(this);
    Then from the console you can do:
    Code:
    App.fireEvent()