-
26 Mar 2012 1:30 AM #1
Non application-wide controllers
Non application-wide controllers
Hi all,
What's the best way to define a panel specific controller (in my case for a single, complex panel in a wizard)?
Controllers that are defined in the Ext.app.Application definition are initialized at startup and live as long as the application itself.
I'd love to use the control statement to quickly setup handlers instead of decorating a view with listeners,
but when the controller is not instantiated by the Application, there's no reference to the Application and thus not to the EventBus that implements the control statement.
I'd also love to see an example for this situation, as I have the feeling that the existing application/controller examples only apply to more simple applications where all views are visible/used at startup.
IMHO, most situations require more flexibility like instantiating and adding complex panel to a tab (and instantiating a controller for that panel).
So, instead of:
I'd prefer (but won't work as the this is probably not defined during definition):
Or automagically instantiate a controller with the proper references if a panel has a property called 'controller' (the code in the initComponent method could be moved to the AbstractComponent's corresponding method).Code:Ext.define('MyPanel', { extend: 'Ext.panel.Panel', requires: [ 'Ext.panel.Panel', .... ], layout: 'fit', control({ 'button': { click: this.onClickHandler } }), onClickHandler: function(btn) { alert('you clicked me'); }, items: [{ xtype: 'button', text: 'Click me', listeners: { click: function(btn) { this.up('panel').onClickHandler } } }] });
Of course the controller should be able to find the application and live as long as the panel lives.
Any other idea's are more than welcome.Code:Ext.define('MyPanel', { extend: 'Ext.panel.Panel', requires: [ 'Ext.panel.Panel', .... ], layout: 'fit', controller: 'MyPanelController', initComponent: function(cfg) { this.callParent(cfg); if(this.controller) { this.controller = Ext.create(this.controller, this, cfg); } }, onClickHandler: function(btn) { alert('you clicked me'); }, items: [{ xtype: 'button', text: 'Click me' }] });
Ronald van Raaphorst aka Ronaldo
I'm a freelance software developer in Java, PHP, and ExtJs.
Skyperonald_twensoc
Mailinfo@twensoc.nl
-
26 Mar 2012 7:45 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Ext JS 4 doesn't have this ability built in. You can bubble up events from children to a parent (at any level). I personally don't see an issue with having all this in a controller (or multiple).
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
26 Mar 2012 11:59 PM #3
Hi Mitchell,
Thx for your reply. The way of how you spell it out isn't that important.
But it would be great if controllers could be instantiated 'on the fly', apply to a specific panel only, and have the same lifespan as the panel it controls.
Surely there's a way to access the Ext.app.Application or the EventBus during runtime? Aren't they both singletons?Ronald van Raaphorst aka Ronaldo
I'm a freelance software developer in Java, PHP, and ExtJs.
Skyperonald_twensoc
Mailinfo@twensoc.nl
-
27 Mar 2012 4:12 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote