Results 1 to 5 of 5

Thread: MVC Panel Click event

  1. #1
    Sencha User
    Join Date
    Feb 2009
    Location
    India
    Posts
    73
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,411
    Answers
    3898
    Vote Rating
    1290
      0  

    Default

    The component doesn't have a click event but the element does.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
    73
    Vote Rating
    1
      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
    73
    Vote Rating
    1
      0  

    Default

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

  6. #5
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347
    Vote Rating
    114
      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');
                }
            }
        });
    }

Tags for this Thread

Posting Permissions

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