-
1 Nov 2011 12:53 AM #1
Answered: Viewport with template in header
Answered: Viewport with template in header
Hi.
I'm new to ExtJS 4, and are wondering whats the correct way to bind data to a 'header' using the MVC pattern.
Basically i have a Viewport defined in app.js
And the app/view/Header.js looks like this:Code:Ext.create('Ext.container.Viewport', { layout: 'border', items: [{ xtype: 'header' },{ xtype: 'dashboard' }] });
When user is not authenticated i bring up a modal login-window which is controlled by my users controller.Code:Ext.define('SF6.view.Header', { extend: 'Ext.Component', region: 'north', alias : 'widget.header', tpl: Ext.create('Ext.Template', '<div class="x-panel-header" style="border-bottom: 1px solid #CCC;background-color:#FFF">' + '<h1 style="float:left;">Application Title</h1>' + '<tpl if="authenticated">' + '<span style="float:right; font-size:11px;">Logged in as <b>{username}</b> ({role}) | {company} | <a href="#">Log out</a></span><br>' + '</tpl>' +'</div>'), initComponent: function() { this.callParent(arguments); }
2011-11-01_0938.jpg
http://screencast.com/t/qnwUjDdh
My question is what is the correct way to store current user in the 'Application' and how to apply the current users value to the header?
-
Best Answer Posted by mitchellsimoens
I assign the tpl to a container and then use the update method and pass in an Object which is the user details.
-
1 Nov 2011 6:31 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3106
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.
-
1 Nov 2011 6:39 AM #3
Cool, this is what i've ended up doing. How about the view in header? Whats the 'ext4' way of updating a part of the view when user is logged in?
-
1 Nov 2011 6:47 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3106
I assign the tpl to a container and then use the update method and pass in an Object which is the user details.
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.
-
30 Nov 2011 5:40 AM #5
I've got another question regarding this - once logged in, template is rendered ok - but how do i capture click on the 'log out' link? (Its part of the original template)
I would prefer to have definition of it in my 'Users' controller am unsure of how to achive it. Something like this:Code:Ext.define('SF6.controller.Users', { extend: 'Ext.app.Controller', init: function() { this.control({ 'header a': { click: this.logout } }) }, ...... logout: function () { Ext.Ajax.request({ url: '/users/logout', success: function (response) { var view = Ext.widget('userlogin'); // brings up login window } }); } );
-
30 Nov 2011 6:28 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3106
ComponentQuery cannot listen for DOM elements.
You have to do something like this after a component has rendered:
Code:cmp.mon(cmp.el, { scope : this, delegate : 'a', click : function() {...} });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