Results 1 to 8 of 8

Thread: MVC && Ext.app.Application.init()

  1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    249
    Answers
    2

    Default Answered: MVC && Ext.app.Application.init()

    I need to override Ext.app.Application.init().
    Code:
    Ext.Loader.setConfig({
        enabled: true,
        disableCaching: false
    });
    
    Ext.application({
        name: "M3",
        appFolder: "app",
        autoCreateViewport: true,
        enableQuickTips: true,
        models: ["Country"],
        stores: ["Countries"],
    
        init: function(app) {
            if(window.console && console.log)
                console.log("Ext.app.Application.init(%o)", arguments);
        },
    
        onLaunch: function(app) {
            if(window.console && console.log)
                console.log("Ext.app.Application.onLaunch(%o)", arguments);
        },
        
        launch: function() {
            if(window.console && console.log)
                console.log("Ext.app.Application.launch(%o)", arguments);
        }
    });
    Only Ext.app.Application.launch is called.

  2. onBeforeLaunch is call just after the controller's are init() but after autoCreateViewport creates the viewport and after the Ext.require has loaded all the classes. If you need something earlier, constructor is your only option.

  3. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    Ext.app.Application never calls an init event. The reason a Controller's init method is executed is the Application loops through the controllers and executes it.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  4. #3
    Sencha User
    Join Date
    Mar 2010
    Posts
    249
    Answers
    2

    Default

    Quote Originally Posted by mitchellsimoens View Post
    Ext.app.Application never calls an init event
    So I misunderstood this

  5. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    It's inherited and shouldn't be there as it's never fired. Search Ext.app.Application code for 'init' and all you will find is for where it fires it on the controller and for the QuickTips
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  6. #5
    Sencha User
    Join Date
    Mar 2010
    Posts
    249
    Answers
    2

    Default

    So, if I want to do something before Ext.app.Application.launch what and where should I override?

  7. #6
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    onBeforeLaunch is call just after the controller's are init() but after autoCreateViewport creates the viewport and after the Ext.require has loaded all the classes. If you need something earlier, constructor is your only option.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  8. #7
    Sencha User
    Join Date
    Jul 2008
    Location
    Czech republic
    Posts
    69

    Default

    Constructor is not called either.

    Code:
    Ext.application({
        name : 'App',
    
        appFolder : '/js/app',
    
        paths : {
            'Ext.ux' : '/js/app/ux',
            'Module' : '/js/app/module'
        },
        
        requires : [
            'Ext.window.MessageBox'
        ],
    
        controllers : [
            'Desktop',
            'Login'
        ],
    
        autoCreateViewport : true,
    
        constructor : function() {
    console.log('never happen');
            this.callParent(arguments);
    
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'side';
        },
    
    ...

  9. #8

    Default

    Well, this is old, but in case someone looks for an example how to use a custom application object, here is my way.

    What i needed was some logic before the redirectTo() method (always check some data before the call). I didn't want to use before filters in each and every controller (for every route), so i looked for another place for that. And here it is, as simple as this.

    Create your own Application class by 'overriding' the base Application class. Override methods with your own logic (and callParent() if necessary):

    Code:
    Ext.define('MyApp.lib.Application', {
        override: 'Ext.app.Application',
    
        redirectTo: function(place) {
            console.log('Do somethig ...');
    
            this.callParent(arguments);
        }
    });
    Require it in your app.js:

    Code:
    Ext.application({
        name: 'MyApp',
    
        requires: [
            'MyApp.lib.Application'
            ...
        ]
    
        ...
    }
    That's it.

    Michael

Posting Permissions

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