PDA

View Full Version : Confusion in Ext Js MVC



jksnu
21 Jun 2012, 7:22 AM
Hi,

We are trying to use ExtJs MVC for our application and we are trying to create our own directory structor for MVC that is we are not following the directory structor given in example on Document. We are able to chage the name of Directories like model, store, view and my POC runs fine. But when ever I changed the folder name of controller folder, my POC stops running. I am giving code below:

I have changed name of "controller" directory to "nitin" and according changed the name in my controller file and app.js file.

Controller file:

Ext.define('AM.nitin.Users', {
extend: 'Ext.app.Controller',

models: ['AM.model.User'],
stores: ['AM.store_123.Users'],
views: ['Panel', 'Grid'],
init: function() {
Ext.create('Ext.panel.Panel', {
layout: 'fit',
height: 300,
width: 500,

items: {
xtype: 'userlist'
},

renderTo: document.body
});

Ext.create('AM.view.Grid').show();
}
});


app.js file:

Ext.Loader.setConfig({

enabled: true
});
Ext.application({
name: 'AM',
appFolder: 'app',
controllers: [
'AM.nitin.Users'
],
launch: function() {}
});


So, please suggest me that can we change the directory name of controller folder in ExtJs MVC, so that we can create our own directory structor.

scottmartin
3 Jul 2012, 7:51 AM
You can use your own DIR structure, adhering to your class names.

Scott.

jratcliff
3 Jul 2012, 9:21 AM
I just tried this as well and I get an error when I change from using 'controller' to 'nitin'. So I'm on going to dig deeper to see why this is.

scottmartin
3 Jul 2012, 9:35 AM
Does this demonstrate what your setup? It should show 'works' in the console.

36764

Scott.

jratcliff
3 Jul 2012, 10:22 AM
Hi Scott,

I actually started with jksnu's code and tried to fill in the missing pieces. If you take what I have in the zip file you will see it works. But if you edit the app.js file and change the controllers to 'AM.nitin.Users' you get an error. The error is due to the AM.view.user.List class not getting loaded. But it loads when you use AM.controller.Users instead of AM.nitin.Users.

jratcliff
3 Jul 2012, 11:08 AM
Found the issue. In the onClassExtended method of Ext.app.Controller, it expects the controller to be named 'controller', otherwise it will not load the models, stores and views specified in the controller. So it looks like you have to use 'controller' in your namespace of your controller.




onClassExtended: function(cls, data, hooks) {
var className = Ext.getClassName(cls),
match = className.match(/^(.*)\.controller\./),
namespace,
onBeforeClassCreated,
requires,
modules,
namespaceAndModule;

if (match !== null) {
namespace = Ext.Loader.getPrefix(className) || match[1];
onBeforeClassCreated = hooks.onBeforeCreated;
requires = [];
modules = ['model', 'view', 'store'];

hooks.onBeforeCreated = function(cls, data) {
var i, ln, module,
items, j, subLn, item;

for (i = 0,ln = modules.length; i < ln; i++) {
module = modules[i];
namespaceAndModule = namespace + '.' + module + '.';

items = Ext.Array.from(data[module + 's']);

for (j = 0,subLn = items.length; j < subLn; j++) {
item = items[j];







if (item.indexOf('.') !== -1 && (Ext.ClassManager.isCreated(item) || Ext.Loader.isAClassNameWithAKnownPrefix(item))) {
requires.push(item);
} else {
requires.push(namespaceAndModule + item);
}
}
}

Ext.require(requires, Ext.Function.pass(onBeforeClassCreated, arguments, this));
};
}
},

scottmartin
3 Jul 2012, 11:48 AM
I stand corrected .. good to know .. thanks for the research .. perhaps this should be changed ;)

Scott.

mitchellsimoens
3 Jul 2012, 12:27 PM
Just popping in and as Scott suggested it should be changed. I have a change pending to get merged into 4.1.2 that will allow you to have your own controller name and still load the models, stores and views.

To sum it up, since I like cake, I would say you will be able to have your cake and eat it too B)

mitchellsimoens
3 Jul 2012, 12:28 PM
Forgot to mention... you can still name your controllers whatever you would like and put the classes in the models, stores and views properties in Ext.application's requires array and it will load it no matter what the controller's name is. You won't get the getters created but IMO they aren't that useful.

mitchellsimoens
3 Jul 2012, 1:28 PM
Researching into Ext.application it seems that controllers, models and stores configs do work but views does not. You can use requires instead of views but I have another merge pending to fix the views config and this will likely hit 4.1.2 also

jksnu
3 Jul 2012, 8:32 PM
Hi,

First, thanks to all (mitchellsimoens, scottmartin and jratcliff ) for taking my query so seriously and providing me a conclusion by doing this amout of R&D.

Mitchellsimoens - Mitchellsimoens! when should we expect ExtJs 4.1.2, so that we will be able to fulfill our requirement regarding MVC. It will be helpful for us if you can explain following in some broader sense.

controllers, models and stores configs do work but views does not. You can use requires instead of views

mitchellsimoens
4 Jul 2012, 4:05 AM
Ext.application({
name : 'Test',

controllers : [
'Main'
],

models : [
'Main'
],

requires : [
'Main'
],

stores : [
'Main
]
});

4.1.1 is due out any day and so we are working on 4.1.2 now which we do not have any public dates but like to come out within a few months.

jksnu
23 Jul 2012, 3:33 AM
Hi,

When we are expecting Extjs 4.1.2 release, so that we will be able to change the controllers name as per our requirement as mentioned in above discussion.

scottmartin
23 Jul 2012, 5:58 AM
There is not a public release data at this time.

Regards,
Scott.