PDA

View Full Version : Extending dot notation for controllers and views



luismerino
1 Feb 2012, 2:39 PM
Hi team:

Why isn't it possible to use namespaces to have sub-folders inside controllers and views in order to structure the application?

controller/Products.js -> 'MyApp.controller.Products OK
controller/Products/Detail.js - 'MyApp.controller.Products.Detail NOT OK

rdougan
1 Feb 2012, 3:31 PM
It will work, but your class name 'packages' should be all lowercase: 'MyApp.controller.products..Detail'.

More information about naming conventions here: http://docs.sencha.com/touch/2-0/#!/guide/class_system

luismerino
1 Feb 2012, 3:42 PM
It will work, but your class name 'packages' should be all lowercase: 'MyApp.controller.products..Detail'.

More information about naming conventions here: http://docs.sencha.com/touch/2-0/#!/guide/class_system

Yeah, I mean it should work, but not within the Router class where after "redirectTo" gets called, the part where "action.getController()" exists, it returns the last dot-delimited part only.

edspencer
1 Feb 2012, 3:49 PM
Touch 2.0 beta 1 is more forgiving over what you call your controllers, allowing the dot notation you specify there. If you migrate your app to b1 it should just work, if not I'll keep an eye on this thread.

luismerino
1 Feb 2012, 3:54 PM
After taking a look, here...



applyRoutes: function(routes) {
var app = this instanceof Ext.app.Application ? this : this.getApplication(),
router = app.getRouter(),
parts = this.$className.split('.'),
url;


for (url in routes) {
router.connect(url, {
controller: parts[parts.length - 1],
action: routes[url]
});
}


return routes;
},


So the fix/improvement would be something like:



Ext.filter(parts, function(chunk){
return (!(app.getName() == chunk || 'controller' == chunk));
});
parts.join('')

< not tested.

ps: Solution could be more elegant

luismerino
1 Feb 2012, 3:56 PM
Touch 2.0 beta 1 is more forgiving over what you call your controllers, allowing the dot notation you specify there. If you migrate your app to b1 it should just work, if not I'll keep an eye on this thread.

Excellent then, I didn't see your reply while I was posting...