Results 1 to 6 of 6

Thread: Dynamic Menu creation...

  1. #1
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default Dynamic Menu creation...

    Hello,

    Not sure if there is an extension out there that helps with this but what I want to do is draw a menu based on the Modules to which the current user has access. I already have the Module information returned to me and stored in an Application.js object. So my choices are to draw the menu client side based on that variable, or perform the task on the server and return a pre-configured menu object and assign to the main menu.

    Any thoughts about which way to go here? Anybody already doing this?

    Thanks!

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,618
    Vote Rating
    52
      0  

    Default

    What do you mean?

    Everything is dynamic.

    Create the Menu with a "new" statement! WHere's the problem?

  3. #3
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default

    Not sure you even read what I wrote with that response. My question was theory related in terms of generating the menu code client side or server side and was asking if others are doing this and which approach they are using and why.

    I am certainly aware that the "new" statement creates a menu object. Thanks.

  4. #4

  5. #5
    ExtJS Premium Member
    Join Date
    Feb 2010
    Location
    Neptune Beach, Florida
    Posts
    51
    Vote Rating
    1
      0  

    Default This is what worked for me

    I loaded the store with fields
    Code:
    fields: [
            {name:'text',type:'string'},
            {name:'path',type:'string'},
            {name:'icon',type:'string'},
            {name:'items'}
        ],
    And then just iterated the store items thus;
    Code:
                var menuStore = Ext.create('MyStore');
    
                var goToPath = function(){
                    window.location = this.path;
                };
    
    
                var menu = Ext.create('Ext.menu.Menu',{shadow:'frame',id:'footerMenu'});
                Ext.each(menuStore.data.items,function(i){
                    var sub = null;
                    if(i.data && i.data.items) {
                        var sub = Ext.create('Ext.menu.Menu',{
                            icon : i.data.icon,
                            text : i.data.text
                        });
                        Ext.each(i.data.items,function(j){
                            var jitem = Ext.create('Ext.menu.Item',{
                                icon : j.icon,
                                text : j.text
                            });
                            if(j.path) {
                                jitem.on('click',goToPath,j);
                            }
                            sub.add(jitem);
                        });
                    }
                    var item = Ext.create('Ext.menu.Item',{
                        icon : i.data.icon,
                        text : i.data.text,
                        menu : sub
                    });
                    if(i.path) {
                        item.on('click',goToPath,i.data);
                    }
                    menu.add(item);
                });

  6. #6
    Ext JS Premium Member
    Join Date
    Feb 2008
    Posts
    12
    Vote Rating
    0
      0  

    Default

    if(user has right) {

    main_toolbar.add('-',{
    text: '<i class="fa fa-list-alt"></i> Menuitem',
    handler: function() {
    // your handler
    }
    });

    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •