Just finished my first Zimlet for a project and I wanted to share some experiences and some Gotcha's I discovered. While Zimbra is a nice product, the Zimlet creation process is, how shall I say, not very pleasant. I've been a professional developer for many years and have worked with all kinds of API's and on all kinds of projects. If Zimbra wants to see people developing Zimlets that are more than just toys, a couple things are critical:
1. Provide some documentation. Whatever is out there is not even close to sufficient. And half of it is contradictory.
2. Provide a way to test Zimlets in Zimbra that does not require hair pulling. Appending dev=1 is not sufficient (see below) and doing a "zmmailboxdctl restart" and all manner of odd deploying and undeploying a zimlet to try to get the cache to clear just makes you want to poke your eyes out.
3. Don't make changes that breaks existing Zimlets between releases. There is no better way to piss off open source developers than to change you API so it ruins their hard work. Especially if they are undocumented changes.
So, enough with the Rant. Let me share what I did to finally get some buttons added to the Compose Toolbar. I hope this saves somebody some time.
The short answer. This works in the current network version:
Code:
Com_My_Zimlet.prototype.init = function () {
this._composerCtrl = AjxDispatcher.run("GetComposeController");
if(!this._composerCtrl._toolbar) {
// initialize the compose controller's toolbar
this._composerCtrl._initializeToolBar();
}
this._toolbar = this._composerCtrl._toolbar;
// Add button to toolbar
ZmMsg.myLabel = "Does not work anyway";
ZmMsg.myTooltip = "Would be nice to have";
var op = {textKey: "myLabel", tooltipKey: "myTooltip", image: "MyZimletIcon"};
var opDesc = ZmOperation.defineOperation(null, op);
ZmOperation.addOperation(this._toolbar, opDesc.id, this._toolbar._buttons, 4);
this._toolbar.addSelectionListener(opDesc.id, new AjxListener(this, this._myClickListener));
} I know a lot of people followed the salesforce Zimlet example to do this. They use
Code:
this._composerCtrl = this._appCtxt.getApp(ZmZimbraMail.MAIL_APP).getComposeController();
to get the controller. THIS DOES NOT WORK for many reasons. One of the releases broke this. First, it is no longer "ZmZimbraMail.MAIL_APP". It is now "ZmApp.MAIL". Documentation would have been nice. Also this._appCtxt no longer exists for ZmZimletBase. You have to use appCtxt instead. I'm sure there is a reason this change was made, but I don't know it.
So you can change the line to
Code:
this._composerCtrl = appCtxt.getApp(ZmApp.MAIL).getComposeController();
Now you are getting close. This works perfectly in the current Open Source edition. It also works in the current Network Edition if you append ?dev=1 to the url before logging in. But, alas, once you remove the ?dev=1 you get some error about the composeController not existing.
So, finally, you get (thx to com_yahoo_yfinance)
Code:
this._composerCtrl = AjxDispatcher.run("GetComposeController") This works in the Network, but I don't think in the Open Source. I'll have to double check.
So, now I've shared my experience.
Maybe someone can help me to get tool tips and button labels working. Right now my button only shows an image.
This DOES NOT work:
Code:
ZmMsg.myLabel = "Does not work anyway";
ZmMsg.myTooltip = "Would be nice to have";
var op = {textKey: "myLabel", tooltipKey: "myTooltip", image: "MyZimletIcon"};
var opDesc = ZmOperation.defineOperation(null, op);
ZmOperation.addOperation(this._toolbar, opDesc.id, this._toolbar._buttons, 4);