Here are other examples : the code below shows how to add a button to the compose mail view, the create contact view and the create appt view.
You have to implement the initializeToolbar function. This function is called by the framework anytime it shows a toolbar (I think). In this function, you test for what view you're in to create a button for the right toolbar. I prefer to define a function to create buttons, there's one for each but I only included createMailButton, otheres are very alike.
Some views have the same ID suffixed by a number, that's why I have this toolbar.getButton() test in each if condition to check that the button haven't been created before (otherwise you'll find yourself with multiple identical buttons).
Hope this helps.
Code:
SugarBee.prototype.initializeToolbar = function(app, toolbar, controller, viewID){
if (!toolbar.getButton(SugarBee.addMailButtonID) && viewID.indexOf(ZmId.VIEW_COMPOSE) >= 0){
this._createMailButton(toolbar,controller);
}
else if (!toolbar.getButton(SugarBee.addContactButtonID) && viewID == ZmId.VIEW_CONTACT){
this._createContactButton(toolbar,controller);
}
else if (!toolbar.getButton(SugarBee.addApptButtonID) && viewID.indexOf(ZmId.VIEW_APPOINTMENT) >= 0){
this._createApptButton(toolbar,controller);
_toolbar = toolbar;
}
};
SugarBee.prototype._createMailButton = function (toolbar,controller){
var args = {
text : "Envoi+copie sugar",
tooltip : "Envoi l'e-mail et crée une copie dans SugarCRM",
image : "plus",
index : 1,
enabled : true
};
var bouton = toolbar.createOp(SugarBee.addMailButtonID,args);
toolbar.addOp(SugarBee.addMailButtonID,1);
bouton.addSelectionListener(new AjxListener(this._displayMessage,controller));
SugarBee.addMailbuttonCreated = true;
};