PDA

View Full Version : MVC && Ext.app.Application.init()



Ex_Soft
7 Feb 2012, 7:12 AM
I need to override Ext.app.Application.init().


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.

mitchellsimoens
7 Feb 2012, 8:23 AM
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.

Ex_Soft
7 Feb 2012, 11:35 AM
Ext.app.Application never calls an init event
So I misunderstood this (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.app.Application-method-init)

mitchellsimoens
7 Feb 2012, 11:43 AM
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

Ex_Soft
7 Feb 2012, 11:50 AM
So, if I want to do something before Ext.app.Application.launch what and where should I override?

mitchellsimoens
7 Feb 2012, 11:54 AM
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.

ondra.cz
12 Jun 2012, 4:28 AM
Constructor is not called either.



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';
},

...

michael.piecko
17 Mar 2013, 3:04 AM
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):



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:



Ext.application({
name: 'MyApp',

requires: [
'MyApp.lib.Application'
...
]

...
}


That's it.

Michael