PDA

View Full Version : How to utilize more folders in an MVC structure



achernar
21 Feb 2013, 3:09 AM
I have the following structure:

-app
--controller
---...js
--model
---...js
--store
---...js
--view
---...js
--global
---Constants.js
---Variables.js
---Functions.js

How to load in my application scripts under the custom folder global. Note that each
script under global folder is defined similar to this:

Ext.define('MTAP.global.Variables', {
singleton: true,

workingDate : undefined
});

While using global variable MTAP.global.Variables.workingDate
I am getting the error
TypeError: MTAP.global is undefined

sword-it
21 Feb 2013, 6:07 AM
Hi Achernar,

You should specify the path of the namespace with Ext.Loader.setPath('Ext', 'app/global').

For more info read API docs-http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Loader-method-setPath

achernar
21 Feb 2013, 6:49 AM
Somehow the singleton is not registered into the application. Check below the full configuration. setPath is specifying the extra folder. Code in red is giving the error.

app.js

Ext.Loader.setPath('MTAP.global', 'app/global');

Ext.application({
name: 'MTAP',
appFolder: 'app',
controllers: ['CtrlMain', 'CtrlUser'],
autoCreateViewport: true,
launch: function() {
Ext.get('loading').remove();
}
});

app/global/Constants.js

Ext.define('MTAP.global.Constants', {
singleton: true,

APP_VERSION: '0.2a',
BASE_URL: 'http://sharepoint.com/sites/MTAP',
APP_URL: '/Analytics'
});

app/view/panel/AppStatusbar.js

Ext.define('MTAP.view.panel.AppStatusbar', {
extend: 'Ext.ux.statusbar.StatusBar',
alias: 'widget.appstatusbar',

defaultText: 'Default status text',
defaultIconCls: 'default-icon',
text: 'Ready',
iconCls: 'ready-icon',

items: [
'->',
{
xtype: 'tbitem',
html: '<div class="version-icon">v' + MTAP.global.Constants.APP_VERSION + '</div>'
}
]
});

scottmartin
21 Feb 2013, 8:59 AM
You should be able to use:



Ext.application({
name : 'MyApp',

requires : [
'MTAP.global.Constants'
],
..
});


and in your controller:



getAppVerison : function () {
return MTAP.global.Constants.APP_VERSION;
}


Scott.

achernar
22 Feb 2013, 12:15 AM
Thanks,

I realize that the following is doing the work



requires : [
'MTAP.global.Constants',
'MTAP.global.Variables',
'MTAP.global.Functions' ]

rather using the .* which look like it does not load everything under folder app/global


requires : [
'MTAP.global.*'
]