1. #1
    Sencha User
    Join Date
    Feb 2009
    Location
    India
    Posts
    72
    Vote Rating
    1
    arvindwill is on a distinguished road

      0  

    Default Answered: MVC Panel Click event

    Answered: MVC Panel Click event


    Is it possible to attach the click event handler for a panel body using Ext.app.Controller.control() . Tried by firing the event in the panel

    Code:
    listeners: {
                        click : {
                            fn: function(e, t) {
                                 this.fireEvent('click', t);
                            },
                            element: 'el',
                            scope: this
                        }
                    }
    but even then cant able to catch the handler function corresponding to it in the control() method.

    Code:
            this.control(
                {
                    '[cls~=entity_draw]':{
                        click:this.drawPanel,
                        scope:this
                    }
                });
    to the panel bodyCls and the cls added entity_draw.

  2. Try this:

    1. View code
    Code:
    Ext.define('App.view.Panel', {
        extend: 'Ext.panel.Panel',
        alias: 'widget.apppanel',
        bodyCls: 'entity_draw',
        ...
        listeners: {
            click: {
                element: 'el',
                fn: function(){
                    var panel = Ext.getCmp(this.id);
                    panel.fireEvent('click'); // fire 'click' event from panel
                }
            }
        }
    });
    2. Controller
    Code:
    ...
    init: function(){
        this.control({
            'apppanel': { // 'panel[bodyCls=entity_draw]'
                click: function(){
                    console.log('panel is clicked');
                }
            }
        });
    }

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,549
    Vote Rating
    873
    Answers
    3567
    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


    The component doesn't have a click event but the element does.
    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
    Sencha User
    Join Date
    Feb 2009
    Location
    India
    Posts
    72
    Vote Rating
    1
    arvindwill is on a distinguished road

      0  

    Default


    simoens but the class is provided in bodyCls only and when inspected the html the class was correctly present in the div even then below code is not working.
    Code:
    '[class~=entity_draw]':{
                    	click:this.drawBoardEntity,
                    	scope:this
                    }
    code by which panel is created
    Code:
     var panel = Ext.create('Ext.panel.Panel', {
    	            width: 200,
    	            height: 100,
    	            floating: true,
    	            draggable: true,
    	            renderTo:Ext.get('sworkspace'),
    	            html: displayString,
    	            bodyCls:'entity_draw'
    	        });

  5. #4
    Sencha User
    Join Date
    Feb 2009
    Location
    India
    Posts
    72
    Vote Rating
    1
    arvindwill is on a distinguished road

      0  

    Default


    what is the exact equivalent code for mvc style panel click listener.

  6. #5
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    115
    Answers
    346
    vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold

      1  

    Default


    Try this:

    1. View code
    Code:
    Ext.define('App.view.Panel', {
        extend: 'Ext.panel.Panel',
        alias: 'widget.apppanel',
        bodyCls: 'entity_draw',
        ...
        listeners: {
            click: {
                element: 'el',
                fn: function(){
                    var panel = Ext.getCmp(this.id);
                    panel.fireEvent('click'); // fire 'click' event from panel
                }
            }
        }
    });
    2. Controller
    Code:
    ...
    init: function(){
        this.control({
            'apppanel': { // 'panel[bodyCls=entity_draw]'
                click: function(){
                    console.log('panel is clicked');
                }
            }
        });
    }

Thread Participants: 2

Tags for this Thread