1. #1
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    65
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default 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
    Code:
    Ext.create('Ext.container.Viewport', {
                layout: 'border',
                items: [{
                    xtype: 'header'
                },{
                    xtype: 'dashboard'
                }]
            });
    And the app/view/Header.js looks like this:
    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);
        }
    When user is not authenticated i bring up a modal login-window which is controlled by my users controller.

    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?

  2. I assign the tpl to a container and then use the update method and pass in an Object which is the user details.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,404
    Answers
    3549
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by Spenna View Post
    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?
    This is really up to you... my favorite way is to save it on the app namespace.

    Code:
    app.user = {...};
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    65
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default


    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?

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,404
    Answers
    3549
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  6. #5
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    65
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default


    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
                }
            });
        }
    );

  7. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,404
    Answers
    3549
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1