Results 1 to 2 of 2

Thread: [SOLVED] Need help with extended component events/listeners

  1. #1

    Question [SOLVED] Need help with extended component events/listeners

    Hi,
    Sorry if this is a duplicate post - I posted it a few minutes ago, but can't see it in the forum, so I'm not sure whether I did something wrong, or whether it's gone into a moderator queue.

    I'm extendeding the menu class as follows, which is part of a process which passes the record from a GridPanel to the grid's context Menu, which will then (hopefully) pass it into the action that the menu triggers. I've got the code passing the record from the GridPanel to the menu, but the menu will only seem to run the default behaviour for the listener. The problem is that I want each instance of the menu to be able to run custom code when the grid is right-clicked, and I can't get the specific instance to run.

    Code:
    MyApp.AccountGridContextMenu = Ext.extend(Ext.menu.Menu, {
        parentGrid: null,        
        contextRecord: null,
           
        initComponent:function() {
            var config = {
               parentGrid: null         // Holds the reference to the grid which the menu works with
            }; // eo config object
     
       
             // Pass the menu to the parent grid
             if (this.parentGrid != null) {
                this.parentGrid.contextMenu = this;
             }
             
             // Add events and listeners
             //this.addEvents('contextRecordSet');
             
             
            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));
     
           MyApp.AccountGridContextMenu.superclass.initComponent.apply(this, arguments);
        }, // eo function initComponent
        
    
        setContextRecord: function(contextRecord) {
            this.contextRecord = contextRecord;
            //this.test(contextRecord);
            alert("DEFAULT BEHAVIOUR: Menu has got context record: " + contextRecord.id);
            // this.fireEvent('contextRecordSet', contextRecord); // ***** I DON'T THINK THIS IS NECESSARY?
        }
    });
    Ext.reg('accountGridContextMenu', MyApp.AccountGridContextMenu);
    The menu is instantiated as follows:

    Code:
    var menuAccountGridContext = new MyApp.AccountGridContextMenu({ 
        items: [
                    {id: 'pluginActivate', text: 'Activate'},
                    {id: 'pluginUninstall', text: 'Uninstall'},
                    {id: 'pluginUpgrade', text: 'Upgrade'},
                    {id: 'pluginDectivate', text: 'Deactivate'}
        ],
        parentGrid: gridPlugins,           // THIS ASSIGNS THE MENU TO A SPECIFIC GRID. THE GRID IS EXTENDED TO SUPPORT THIS, AND THAT FUNCTIONALITY IS WORKING OK
        
           listeners: {
            contextRecordSet: function(contextRecord){
                alert("CUSTOM BEHAVIOUR: " + contextRecord.plugin_status);
            }
        }
    });

    The 'setContextRecord' function is called when the grid is right-clicked, on the 'rowcontextmenu' event.

    The connection between the grid and menu is working fine: the menus is assigned to the grid on creation; the default listener function runs fine, and does display the record ID.

    But I just can't get the specific instance of the menu to run it's own local routine.

    Any advice/tips/hints/alternative solutions/slaps round the head would be GREATLY appreciated, as I spent most of last night trying to get this working!

    Thanks in advance,
    Andy
    Last edited by Andrew Peacock; 16 Jun 2010 at 4:57 AM. Reason: Realised my mistake

  2. #2

    Default Doh, I'm an *****

    Somehow, I'd copied and pasted the section

    Code:
    var menuAccountGridContext = new PromotionBot.AccountGridContextMenu({ 
        items: {%$accountGridContextMenuItems%},
        ...
    });
    So I had two definitions of the same object, and obviously one of them (without the custom behaviour) redefined the one with the custom behaviour.

    Sorry!

    Andy

Similar Threads

  1. SOLVED: Need help with events/listeners in extended component (context menu in grid)
    By Andrew Peacock in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 16 Jun 2010, 2:11 PM
  2. Viewport and Component to Component Listeners
    By jmoran888 in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 6 Aug 2009, 10:50 AM
  3. Ajax Event In Extended Component
    By boylesw in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 24 Feb 2009, 7:24 AM

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
  •