1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    76
    Answers
    1
    Vote Rating
    1
    Monti123 is on a distinguished road

      0  

    Default Answered: Question regarding namespace in app.js

    Answered: Question regarding namespace in app.js


    Hi all,

    I'm new to Extjs, just migrating from Touch.

    I've created my app today, but can't seem to use the namespace AppName.app.func()

    Code:
    Ext.require('Ext.container.Viewport');
    Ext.require('Ext.form.Panel');
    
    Ext.application({
        name: 'Admin',
    
        appFolder: 'app',
    
        launch: function () {
            
            //Check if user is signed in
                Ext.Ajax.request({
                    ...              
                    success : function(response, opts) {
                        Here, after I performed the check I want to call:
                        Admin.app.enterAdmin();
                    },
                });
        },
        
        enterAdmin: function () {
            Ext.create('Ext.container.Viewport', {
            ...
    Although calling AppName.app.func() works on ST2, this doesn't work on Extjs for some reason, and if I'm not missing something it should work the same way.

    BTW, if there's a better way to implement this, don't hesitate.

    Thanks!

  2. I've wondered about that before, too. From what I've sen ExtJS doesn't get namespace.app created automatically. I saw mitchell recommend doing the following in either the application's init or launch method:

    either
    Code:
    init: function () {
        Admin.app = this;
        // ....
    }
    Code:
    launch: function () {
        Admin.app = this;
        // ....
    }
    That way from any controller or from the app itself you can use Namespace.app.method().
    Init is called before launch, so if you're going to use Namespace.app.method() in launch it'd be best to set up Namespace.app in the init method.

    EDIT: I believe in earlier versions of ExtJS 4 init didn't get fired at all. I know it was fixed, but I don't know when that was. I'm using 4.1.1a and it's for sure fixed there.

  3. #2
    Sencha User
    Join Date
    Jul 2007
    Posts
    15
    Vote Rating
    0
    jkisner is on a distinguished road

      0  

    Default


    Monti123,

    You need to set a scope for the Ext.AJAX.request() object. See if the following code works for you.

    Code:
    launch: function () {
            
            //Check if user is signed in
                Ext.Ajax.request({
                    ...              
                    success : function(response, opts) {
                        Here, after I performed the check I want to call:
                        this.enterAdmin();
                    },
                    scope: this
                });
        },

  4. #3
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,364
    Answers
    432
    Vote Rating
    200
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    I've wondered about that before, too. From what I've sen ExtJS doesn't get namespace.app created automatically. I saw mitchell recommend doing the following in either the application's init or launch method:

    either
    Code:
    init: function () {
        Admin.app = this;
        // ....
    }
    Code:
    launch: function () {
        Admin.app = this;
        // ....
    }
    That way from any controller or from the app itself you can use Namespace.app.method().
    Init is called before launch, so if you're going to use Namespace.app.method() in launch it'd be best to set up Namespace.app in the init method.

    EDIT: I believe in earlier versions of ExtJS 4 init didn't get fired at all. I know it was fixed, but I don't know when that was. I'm using 4.1.1a and it's for sure fixed there.

  5. #4
    Sencha User
    Join Date
    Mar 2012
    Posts
    76
    Answers
    1
    Vote Rating
    1
    Monti123 is on a distinguished road

      0  

    Default


    Didn't know that it's a known thing that this doesn't happen automatically.

    Great solution slemmon, thanks.

  6. #5
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,364
    Answers
    432
    Vote Rating
    200
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    After I saw mitchell do it I've used it ever since.

    I'll be excited for ExtJS 7 or Touch 5 or Sencha TotallyRad v.1 or whatever comes along that makes ExtJS and Touch the same thing.

Thread Participants: 2

Tags for this Thread