Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Panel zimlet to display a list of links

  1. #11
    Join Date
    Jul 2012
    Location
    Algiers
    Posts
    55
    Rep Power
    3

    Default

    Quote Originally Posted by skyflyer View Post
    Code:
        subItem1.addListener(
            DwtEvent.ONCLICK, 
            new AjxListener(function() {
                console.log('click');
                console.log(arguments);
            }, this, {})
        );
    I think you inverted the parameters of AjxListner, "this" should be the _first_ parameter and the function should be the _second_ parameter. Also, you're passing an empty object as third parameter which is wrong, the AjxListner expects an array, not an object. So I'd write your code like this:

    Code:
        subItem1.addListener(
            new AjxListener(this, function() {console.log('click');console.log(arguments);}),
            DwtEvent.ONCLICK, 
        )

  2. #12
    Join Date
    Mar 2011
    Posts
    39
    Rep Power
    4

    Default

    Hi!

    A few posts back, you wrote:
    2/ If you want to pass a function, then just pass it as first argument
    It does not really matter, as it behaves the same anyway you turn it. addListener does not work. addSelectionListener, on the other hand, fires twice. I guess I'll file a bug report about that. Here is a code you can test in your browser. For intante, in Chrome, open Inspector, then click Console and paste the code inside. Then click on the item. At first, there will be one event, afterwards, two events.

    The order of arguments to AjxListener constructor is interestignly not that important, as both variants below actually work. I agree that we should be using the documented ones. Unfortunately, I recieve two events for a single click, so its not really usable. I'd be interested to hear how it performs on your installation (I'm testing this on 7.2.1 releases (ZD & Zimbra NE)).

    Code:
    var appMgr = appCtxt.getAppViewMgr();
    var tree = appMgr.getCurrentViewComponent(ZmAppViewMgr.C_TREE);
    var controller = new ZmOverviewController(tree);
    var overview = controller.createOverview({
        id: 'links',
        parent: tree,
        showUnread: false,
        showNewButtons: false,
        noTooltips: true        
    });
    overview.setClassName('ZmOverviewSection');
    
    var linkTree = new DwtTree({
        parent: overview,
        style: DwtTree.MULTI_STYLE,
    });
    
    // hide border which seems to be the default
    linkTree.getHtmlElement().style.border = "none";
    
    var treeStartItem = new DwtTreeItem({
        parent: linkTree,
        text: 'Test parent',
        selectable: true,
        className: 'overviewHeader'
    });
    treeStartItem.showExpansionIcon(true);
    
    var subitem = new DwtTreeItem({
        parent: treeStartItem,
        text: 'Item text',
        selectable: true
    });
    subitem.addListener(
        DwtEvent.ONCLICK,
        new AjxListener(this, function() {console.log('addListener works! - click');console.log(arguments);}),
        0
    );
    
    linkTree.addSelectionListener(
        new AjxListener(this, function() {console.log('addSelectionListener works! - click');console.log(arguments);}, [])
    );
    
    linkTree.addSelectionListener(
        new AjxListener(function() {console.log('addSelectionListener works differently too! - click'); console.log(arguments);}, this, [])
    );
    --
    Zimbra 7.1.2 GA NETWORK

  3. #13
    Join Date
    Jul 2012
    Location
    Algiers
    Posts
    55
    Rep Power
    3

    Default

    Hi skyflyer,

    You can read again my earlier posts about passing sole function versus passing object methods to AjxListener if you wish if that's still a bit confusing ^^. The AjxListener source code handles its arguments differently depending on their number the their types.

    I tested your code on my configuration and I have the same behaviour : one click the first time and then two clicks all successive times. I'm not sure why this behaves like so, I suspect something is going wrong in the _itemClicked method because this method calls your ajaxlistener two times in two different locations (in the same function), look here (marked lines with ">>"):

    Code:
    DwtTree.prototype._itemClicked=function(n,o){
        var t;
        var e=this._selectedItems.getArray();
        var s=this._selectedItems.size();
        if(this._style&DwtTree.SINGLE_STYLE||(!o.shiftKey&&!o.ctrlKey)){
    	var r=this._notifyListeners(DwtEvent.PRE_SELECTION,[n],DwtTree.ITEM_SELECTED,o,this._selEv);
    	if(r===false){
    	    return
    	}
    	if(s>0){
    	    for(t=0;
    		t<s;
    		t++){
    		e[t]._setSelected(false)
    	    }
    
    	    /* HERE */
    	    >> this._notifyListeners(DwtEvent.SELECTION,this._selectedItems.getArray(),DwtTree.ITEM_DESELECTED,o,this._selEv);
    	    /* HERE */
    
    
    	    this._selectedItems.removeAll()
    	}
    
    	this._selectedItems.add(n);	
    	if(n._setSelected(true)){
    	    
    	    /* AND HERE */
    	    >> this._notifyListeners(DwtEvent.SELECTION,[n],DwtTree.ITEM_SELECTED,o,this._selEv)
    	    /* AND HERE */
    
    	}
        }
        else{
    	if(o.ctrlKey){
    	    if(this._selectedItems.contains(n)){
    		this._selectedItems.remove(n);
    		n._setSelected(false);
    		this._notifyListeners(DwtEvent.SELECTION,[n],DwtTree.ITEM_DESELECTED,o,this._selEv)
    		}
    	    else{
    		this._selectedItems.add(n);
    		if(n._setSelected(true)){
    		    this._notifyListeners(DwtEvent.SELECTION,[n],DwtTree.ITEM_SELECTED,o,this._selEv)
    		}
    	    }
    	}
    	else{
    	}
        }
    };
    So executing your script in the debugger (I didn't have the courage to debug from A to Z, is it requires more time and attention), I saw that both calls are called at first click just as well as the subsequent clicks, so there should also be two calls on the first click, I don't know why it's called just one time.

    I think I'll leave this to Zimbra developers.

  4. #14
    Join Date
    Jul 2012
    Location
    Algiers
    Posts
    55
    Rep Power
    3

    Default

    You can see in the code that the first marked line calls your listner with a DwtTree.ITEM_DESELECTED flag and the second one with a DwtTree.ITEM_SELECTED flag.

  5. #15
    Join Date
    Mar 2011
    Posts
    39
    Rep Power
    4

    Default

    ychaouche,

    let's continue discussion about tree events in the more appropriate topic.

    Thanks!
    --
    Zimbra 7.1.2 GA NETWORK

Similar Threads

  1. installed zimlet doesn't appear in panel
    By Jignesh in forum Installation Help
    Replies: 0
    Last Post: 02-27-2012, 09:50 PM
  2. Admin panel dont display deferred mail
    By section1 in forum Administrators
    Replies: 5
    Last Post: 11-03-2011, 06:32 PM
  3. Getting username in panel from zimlet
    By loocek in forum Zimlets
    Replies: 1
    Last Post: 07-27-2011, 12:06 PM
  4. Panel using an iFrame Example Zimlet
    By bku09 in forum Developers
    Replies: 1
    Last Post: 04-18-2010, 06:53 PM
  5. Changing the label of the zimlet in the zimlet panel
    By bogdan.mocanu in forum Zimlets
    Replies: 1
    Last Post: 08-12-2008, 04:07 AM

Posting Permissions

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