Results 1 to 5 of 5

Thread: How to bind event listener to action menu item created with JS?

  1. #1
    Join Date
    Apr 2013
    Posts
    33
    Rep Power
    0

    Default How to bind event listener to action menu item created with JS?

    Hello,

    I'm trying to build context menu for my zimlet panel item with javascript. Here is the code:

    Code:
    var ctxtMenu = this.getZimletContext().getPanelActionMenu();
    ctxtMenu.createMenuItem("item1", {"text":"Menu Item 1});
    Menu items appear in the menu but they appear not to be bound to menu selection event listener as ones defined in zimlet definition file (XML). In other words menuItemSelected() method is not called when generated by JS menu items are selected.

    How to bind the event listener to dynamicly added items?

  2. #2
    Join Date
    May 2013
    Location
    California
    Posts
    27
    Rep Power
    2

    Default

    While the API isn't the most fun thing to slog through, the answers are often there. The links below assume you are using 8.0.4, but you should be able to check similar areas for other versions.

    If you look at createMenuItem(Zimlet JavaScript API Reference - ZmPopupMenu), you will see that you are specifying an ID for the menu item you are adding. Scroll up one item to addSelectionListener (Zimlet JavaScript API Reference - ZmPopupMenu), and you will see that you can attach a listener to a menu item ID.

    HTH,
    Kathy A.
    Last edited by kapplebaum; 07-29-2013 at 09:08 AM. Reason: added describtion to clarify URL link

  3. #3
    Join Date
    Apr 2013
    Posts
    33
    Rep Power
    0

    Default

    Thank you for you answer!

    I saw that method in the documentation. Unfortunately I can't say it is for zimbra newbies.
    It would be nice to have more detailed description with examples.

    Here is how I use it
    Code:
    ctxtMenu.addSelectionListener('item1', new AjxListener(this, this.menuItemSelected, 'item1'));
    BTW, can an existent listener be bound with new elements? How to find it?

  4. #4
    Join Date
    May 2013
    Location
    California
    Posts
    27
    Rep Power
    2

    Default

    I'm barely out of the complete Zimbra noob stage myself, so I know your pain.

    From the API, I'd say that a new element could be bound to an existing listener, *if* the listener could be grabbed. For example, in the code you have above, I can't see how to grab the listener you made to reuse it for another element. (But that could just be my lack of knowledge.) But if you had bound the listener to a variable (ie foo = new AjaxListener(), then I would think you could reuse it to your heart's content. For the Zimlet I made, I constructed a different listener for each item, but I have more than one listener calling the same function. (I did it this way because it's likely the spec will change on me, and I'll need different functionality for the different items).

    Good luck!
    Kathy A.

  5. #5
    Join Date
    Apr 2013
    Posts
    33
    Rep Power
    0

    Default

    My understanding that instead of new AjxListener object creation for each new menu item it is possible somehow to reuse one created during zimlet initialization, not init() method but a stage when menu items defined in zimlet definition file (XML) are rendered and event listener is bound to them.
    Is there any way to do that for memory usage optimization?

Similar Threads

  1. New Compose Window Menu Item
    By g23 in forum Zimlets
    Replies: 3
    Last Post: 06-20-2013, 03:16 PM
  2. Zimbra server rules menu item vs Outlook Today
    By stfroy in forum Zimbra Connector for Outlook
    Replies: 4
    Last Post: 02-22-2010, 06:23 AM
  3. Replies: 4
    Last Post: 08-21-2008, 04:48 AM
  4. Replies: 2
    Last Post: 10-16-2007, 04:47 AM
  5. Share Calendar Menu Item doesn't show up
    By kiwicmc in forum Administrators
    Replies: 3
    Last Post: 04-17-2006, 07:15 PM

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
  •