Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
  #1 (permalink)  
Old 06-05-2008, 07:16 AM
jonnybravo's Avatar
Junior Member
 
Join Date: Jul 2007
Location: Buffalo, NY
Posts: 7
jonnybravo is on a distinguished road
Post Dynamic Right Click Menu

I came up with a method for changing the right click menu (also know as context menu) labels on the fly. Technically you could take this code and change other properties of right click menu items but I'll leave that to your imagination!

Here's the code (should be executed from the Zimlet):

Code:
    var zimlet_manager = this.getZimletManager();
    var panel_items = zimlet_manager.getPanelZimlets();
    var action_menu = null;
    
    for (var item in panel_items)
    {
        var panel_item = panel_items[item];
        
        if (panel_item.toString().match(/com_xxx_xxx/i))
        {
            action_menu = panel_item.getPanelActionMenu();
        }
    }
    
    var item = action_menu.getItem(2);
    item.setText('New Label');
I'll just explain a few things about this code.

1. You'll notice we're looping through an array of panel items in the middle of this code. What we need to do is check each panel item to find out which one belongs to the Zimlet we're working with, which is where "panel_item.toString().match(/com_xxx_xxx/i)" comes in. You will need to replace the text com_xxx_xxx with your Zimlet name. So if you call your Zimlet Com_Company_TestZimlet, then you would change the text in this code to read "panel_item.toString().match(/com_company_testzimlet/i)". If you're not familiar with regular expressions, the "i" after the slash makes the match case insensitive.

2. Once we have our panel item, we need to identify the specific menu item we'd like to work with. The menu items are in an array, in the same order you visibly see them in the webmail interface. Furthermore, because it's an array, your first menu item would be item 0. So this sample code uses menu item 2 which is actually the third item in the list. Also, separators count as menu items, but you can't really do much with them.

Just a side-bar. There is an alternate method called getItemById() which takes a string ID. I would assume it matches the ID that you specify in your XML config file. I gave this method a quick test but no matter what string I gave it, it kept giving me menu item 0. I knew my menu item positions wouldn't ever change so I just gave up on this method and used the standard method.

3. Finally, we set the new label with "item.setText('New Label');". Now, doing all this work to hard code a label in here is silly - but you can obviously put anything in here that you want now (which the whole point of doing this). So maybe you want a right click menu option that says something to the effect of "[Display Name]'s Coupons", you would then do something like:

Code:
    var item = action_menu.getItem(2);
    var name = appCtxt.get(ZmSetting.DISPLAY_NAME);
    item.setText(name + "'s Coupons");
So that's all for now. Feel free to ask any questions. This was done Zimbra 5.0.5.
__________________
Jon
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Build Zimbra..a little problem... Abdelmonam Kouka Developers 33 05-22-2008 05:10 AM
Right click menu not disappearing osiris Administrators 1 02-08-2008 05:55 AM
need advice on configuring zimbra to work with fax server pheonix1t Administrators 0 07-11-2007 07:46 PM
Sent, Sent Items, Sent Messages scottp Administrators 4 03-30-2006 09:33 PM


freshmeat.net sourceforge.net The best Java IDE



 

Search Engine Optimization by vBSEO 3.1.0