Hey everyone,

I just wanted to share with whomever might find this useful that I have been able to add a toolbar button under the Address Book tab of the ajax client.

I created a separate method in my Zimlet called _addButtonToContactsToolbar. I simply call this._addButtonToContactsToolbar() inside my init() method after I setup a few other things specific to my Zimlet.

The unique problem with adding a button to the toolbar below the Address Book tab is that once you get the controller, "_toolbar" is actually an array whereas with the salesforce Zimlet, it's an object that you can simply invoke _initializeToolBar() on. The reason _toolbar is an array is because the Address Book tab contains multiple views and each view has it's own toolbar (even though the butons remain the same, they could theoretically be different sets of buttons). You'll notice you can change the view right in the toolbar; the two views are "List" and "Card". I wanted my button to be visible in both views so the code below actually adds a button to each view's toolbar.

Also, be forewarned, I explicitly reference the view names that Zimbra uses, in future upgrades, if Zimbra were to change these strings, this code would break and would need to be updated to reflect the new strings that represent the views.

Ok, so now to the code:

Code:
Com_MyCompany_MyZimlet.prototype._addButtonToContactsToolbar = function ()
{
	if (!appCtxt.get(ZmSetting.CONTACTS_ENABLED))
	{
		return;
	}
	
	var views = {
		list : 'CNS',
		card : 'CNC'
	};
	
	var button = 'MYZIMLET';
	var controller = AjxDispatcher.run('GetContactListController');
	
	var op = {
		id: button,
		text: 'New Button',
		tooltip: 'This button hangs out in the Address Book toolbar!',
		image: 'MYZIMLET-panelIcon'
	};
	
	for (var view in views)
	{
		if (typeof(controller._toolbar[views[view]]) == 'undefined')
		{
			controller._initializeToolBar(views[view]);
		}
		
		var toolbar = controller._toolbar[views[view]];
		
		if (!toolbar.getButton(button))
		{
			var opDesc = ZmOperation.defineOperation(null, op);
			toolbar.addOp(opDesc.id, controller._getToolBarOps().length);
			toolbar.addSelectionListener(button, new AjxListener(this, this._contactsToolbarHandler));
		}
	}
};
So, when a user clicks on your button in the contacts toolbar, the method inside your Zimlet _contactsToolbarHandler() will get called and you can do whatever you want with that.

In case it wasn't obvious, I've generalized this code as I have some extra things going on in my personal code. If you have worked with any Zimlets in the past it should be fairly obvious what you need to change to make it work for your own purposes. If you do have any questions though, feel free to ask.

I hope this helps someone!

(FYI, this was done on Zimbra 5.0.5)