Results 1 to 6 of 6

Thread: Problem with JS objects loading order

  1. #1
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    8

    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 !

  2. #2
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    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.

    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.

    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.

    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.

  3. #3
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    8

    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.

  4. #4
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    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.

  5. #5
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    8

    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)

    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

  6. #6
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    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.

Similar Threads

  1. Zimbra fails after working for 2 weeks
    By Linsys in forum Administrators
    Replies: 10
    Last Post: 10-07-2008, 12:42 AM
  2. Is it started or not
    By kwelipatton in forum Installation
    Replies: 10
    Last Post: 03-28-2006, 10:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •