Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
 
Go Back   Zimbra - Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra - Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 11-09-2007, 08:52 AM
Senior Member
 
Posts: 51
Default Problem with JS objects loading order

Hello,

I am working on calendar app in a zimlet to add specifics actions.
I added some buttons to actionMenu and viewActionMenu => That works well.

Now, I would like to enable / disble these buttons, depending on some conditions.

I got this working, by adding listeners to views and viewManager :
Code:
MyZimlet.prototype.init = function() {
(...)
this._gcmCalViewCtrl._viewMgr.addViewActionListener(new AjxListener(this._gcmCalViewCtrl, this._activerBoutonsViewActionMenu));
this._gcmCalViewCtrl._listView[this._gcmCalViewCtrl._currentView].addActionListener(new AjxListener(this._gcmCalViewCtrl, this._activerBoutonsActionMenu));
}

MyZimlet.prototype._activerBoutonsViewActionMenu = function(ev) {
    // "this" designe le controlleur de l'agenda ZmCalViewController

    if (MyZimlet.idRdvCoupe != '') {
        this._myZimlet._gcmViewActionMenu.enable(MyZimlet._OP_COLLER_RDV_PATIENT,true);
    } else {
        this._myZimlet._gcmViewActionMenu.enable(MyZimlet._OP_COLLER_RDV_PATIENT,false);
    }
};

MyZimlet.prototype._activerBoutonsActionMenu = function(ev) {
(...)
}
Here are the problems :

1) addListener on viewManager works well when I open directly Calendar (with "app=calendar" parameter in Zimbra URL). But when Zimbra first open on default Mail app, viewManager isn't yet initialized => I've got an error, because I can't add listener on a null viewManager in my zimlet init() function.

2) addListener on default calendar view works well when I open directly Calendar at Zimbra startup. But for same reason, it doesn't work for other calendar views, or when Zimbra start on another app.

How can I solve this problem, please ?
I think I could put these instructions directly in Zimbra JS files, but I would like to make "clean" work, and keep all specific code in my Zimlet. Is it possible ?


3) I have another similar problem : I redefined some Zimbra standard functions, in order to modify Calendar hours scale like this :
Code:
ZmCalColView._HOUR_HEIGHT = 84;
ZmCalColView._HALF_HOUR_HEIGHT = ZmCalColView._HOUR_HEIGHT/2;
ZmCalColView._15_MINUTE_HEIGHT = ZmCalColView._HOUR_HEIGHT/4;
ZmCalColView._DAY_HEIGHT = ZmCalColView._HOUR_HEIGHT*24;

ZmCalColView.prototype._getBoundsForDate =
function(d, duration, col) {
(...)
}
ZmCalColView.prototype._getBoundsForCalendar =
function(d, duration, folderId) {
(...)
}
This works well, except when I lauch Zimbra on Calendar app. Column where hours are displayed don't take care of my changes on default calendar view. Other views are OK.
I think there is a problem in the order in which things are executed. How may I solve this, without modifying Zimbra sources ?


Thanks for any help !
Reply With Quote
  #2 (permalink)  
Old 11-09-2007, 11:16 AM
Zimlet Guru & Moderator
 
Posts: 431
Default

Quote:
Originally Posted by marinew View Post
Hello,

I am working on calendar app in a zimlet to add specifics actions.
I added some buttons to actionMenu and viewActionMenu => That works well.

Now, I would like to enable / disble these buttons, depending on some conditions.

I got this working, by adding listeners to views and viewManager :
Code:
MyZimlet.prototype.init = function() {
(...)
this._gcmCalViewCtrl._viewMgr.addViewActionListener(new AjxListener(this._gcmCalViewCtrl, this._activerBoutonsViewActionMenu));
this._gcmCalViewCtrl._listView[this._gcmCalViewCtrl._currentView].addActionListener(new AjxListener(this._gcmCalViewCtrl, this._activerBoutonsActionMenu));
}

MyZimlet.prototype._activerBoutonsViewActionMenu = function(ev) {
    // "this" designe le controlleur de l'agenda ZmCalViewController

    if (MyZimlet.idRdvCoupe != '') {
        this._myZimlet._gcmViewActionMenu.enable(MyZimlet._OP_COLLER_RDV_PATIENT,true);
    } else {
        this._myZimlet._gcmViewActionMenu.enable(MyZimlet._OP_COLLER_RDV_PATIENT,false);
    }
};

MyZimlet.prototype._activerBoutonsActionMenu = function(ev) {
(...)
}
Here are the problems :




How can I solve this problem, please ?
I think I could put these instructions directly in Zimbra JS files, but I would like to make "clean" work, and keep all specific code in my Zimlet. Is it possible ?





Thanks for any help !
Good stuff. No one has played around with this yet, but you look like a hearty fellow, so this is just my brainstorm. Not garunteed to work.

Quote:
1) addListener on viewManager works well when I open directly Calendar (with "app=calendar" parameter in Zimbra URL). But when Zimbra first open on default Mail app, viewManager isn't yet initialized => I've got an error, because I can't add listener on a null viewManager in my zimlet init() function.
You either need to wait until it's initialized automatically by Zimbra, or you need to force Zimbra to do that for you.

Strategy number one: Use the Zimlet onShowView method to wait until the particular view you want is being pulled up, and then add the listener:

Strategy number two: Use AjxDispatcher.run("GetWhateverControllerYouAreInte restedIn") to grab the controller and then initilize it by hand.

I like strategy one more, because it doesn't force a calendar load unless the user needs it.

Quote:
2) addListener on default calendar view works well when I open directly Calendar at Zimbra startup. But for same reason, it doesn't work for other calendar views, or when Zimbra start on another app.
Again, I would argue for stragy one here. onShowView gets called when the view changes to the calendar. I have run into situations where the compose view doesn't trip the method, but it should work.

Quote:
3) I have another similar problem : I redefined some Zimbra standard functions, in order to modify Calendar hours scale like this :
Code:
ZmCalColView._HOUR_HEIGHT = 84;
ZmCalColView._HALF_HOUR_HEIGHT = ZmCalColView._HOUR_HEIGHT/2;
ZmCalColView._15_MINUTE_HEIGHT = ZmCalColView._HOUR_HEIGHT/4;
ZmCalColView._DAY_HEIGHT = ZmCalColView._HOUR_HEIGHT*24;

ZmCalColView.prototype._getBoundsForDate =
function(d, duration, col) {
(...)
}
ZmCalColView.prototype._getBoundsForCalendar =
function(d, duration, folderId) {
(...)
}
This works well, except when I lauch Zimbra on Calendar app. Column where hours are displayed don't take care of my changes on default calendar view. Other views are OK.
I think there is a problem in the order in which things are executed. How may I solve this, without modifying Zimbra sources ?
I don't think it's possible for you to force loadyour zimlet before the application starts, which means that the best bet might be for you to force load the component (again. I think you can do this with AjxDispatcher.run) make your changes, and then re-initilize the component.Just a guess really.
Reply With Quote
  #3 (permalink)  
Old 11-12-2007, 02:14 AM
Senior Member
 
Posts: 51
Default

Thanks a lot for your help, JoshuaPrismon !

I didn't know about existence of "onShowView" function. That's a good thing.

I used it for the first problem, and this works, now.
One precision : I had to try to addListener on calendar viewManager both in "onShowView" event, and on Zimlet "init" function. Because :
- sometimes, Zimlet is already initialized when "onShowView" event is raised => OK.
- But sometimes, "onShowView" seems to be thrown before Zimlet is initialized => my zimlet "onShowView" function isn't executed, but init function can here be used.

For second problem : Unfortunately, "onShowView" event is raised when we change view between Mail app, Calendar ap... But it isn't raised if I am on calendar app, when I switch between calendar day/week/... views

So, for second and third problem, I will have to test your strategy number two, using "AjxDispatcher.run".

I don't know anything about this function.
Could you please tell me more about it, or point me on some documentation or forum posts talking about it ?

Thanks again for your help.
Reply With Quote
  #4 (permalink)  
Old 11-12-2007, 10:00 AM
Zimlet Guru & Moderator
 
Posts: 431
Default

Quote:
Originally Posted by marinew View Post
Thanks a lot for your help, JoshuaPrismon !

I didn't know about existence of "onShowView" function. That's a good thing.

I used it for the first problem, and this works, now.
One precision : I had to try to addListener on calendar viewManager both in "onShowView" event, and on Zimlet "init" function. Because :
- sometimes, Zimlet is already initialized when "onShowView" event is raised => OK.
- But sometimes, "onShowView" seems to be thrown before Zimlet is initialized => my zimlet "onShowView" function isn't executed, but init function can here be used.

For second problem : Unfortunately, "onShowView" event is raised when we change view between Mail app, Calendar ap... But it isn't raised if I am on calendar app, when I switch between calendar day/week/... views

So, for second and third problem, I will have to test your strategy number two, using "AjxDispatcher.run".

I don't know anything about this function.
Could you please tell me more about it, or point me on some documentation or forum posts talking about it ?

Thanks again for your help.
To be honest (and frankly this is my fault since I have been working on this), there isn't a lot of documentation on this. Here are some quick notes:
  • When the Zimbra code was retooled for 5.0, the biggest new thing was the modular code base.
  • Parts of the applicaiton are now loaded on the fly.
  • To force a particular module to be loaded, you use AjxDispatcher.run against a package name that normally corresponds to the path of the javascript files.
  • The exception here is the Zimlet code, which is all munched together and served out of a single Zimlet .zgz file.
  • Appending &dev=1 eliminates the modular loading, and also the minimization so you have real code to look at in firebug.
  • But it also can change behavior.
Reply With Quote
  #5 (permalink)  
Old 11-12-2007, 11:58 AM
Senior Member
 
Posts: 51
Default

Does this means that AjaxDispatcher exists only from 5.0 version ?
(I am using 4.5.8)
If it already exists in 4.5.8, are there some code samples calling AjaxDispatcher.run ? (I didn't find some, with grep command)

Quote:
But it also can change behavior.
Do you mean, that when you test your zimlet with "&dev=1" parameter, you may have different results than with no parameter ?

Thanks
Reply With Quote
  #6 (permalink)  
Old 11-12-2007, 12:35 PM
Zimlet Guru & Moderator
 
Posts: 431
Default

Quote:
Originally Posted by marinew View Post
Does this means that AjaxDispatcher exists only from 5.0 version ?
(I am using 4.5.8)
If it already exists in 4.5.8, are there some code samples calling AjaxDispatcher.run ? (I didn't find some, with grep command)



Do you mean, that when you test your zimlet with "&dev=1" parameter, you may have different results than with no parameter ?

Thanks
Yep. This is all 5.0 centric behavior.
Reply With Quote
Reply


Thread Tools
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

Zimbrablog.com




 

Search Engine Optimization by vBSEO 3.1.0