Results 1 to 5 of 5

Thread: DwtTree.addSelectionListener fires twice for clicks - WHY?

Hybrid View

  1. #1
    Join Date
    Mar 2011
    Posts
    39
    Rep Power
    4

    Question DwtTree.addSelectionListener fires twice for clicks - WHY?

    While amending the tree view, I found out that the selections fire twice for 2nd, 3rd... ciick on any item in the tree list. The first click, however, just fires once.

    Code:
    var i=1;
        this._treeclick = function() {
            console.log('Treeclick ' + i++);
            console.log(arguments);
        }
        linkTree.addSelectionListener(
            new AjxListener(this, this._treeclick, {})
        );
    The function _treeclick will be executed once for the first click, and then twice for each click from there on. All of the events are "mouseup" and I can not distinguish between them -- they are the same.

    Is this a bug? This was tested against 7.2.1 Network edition and against ZimbraDesktop 7.2.1.

    Also, I would only like to handle clicks, but if the DwtTreeItem has set selectable=false, then I can not catch the click events (even by using other listeners (addTreeListener, addListener).

    Regards,
    Miha.
    --
    Zimbra 7.1.2 GA NETWORK

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

    Default

    Can you show evidence that you're not calling this code two times, just to get rid of the obvious errors ?

  3. #3
    Join Date
    Mar 2011
    Posts
    39
    Rep Power
    4

    Default

    Sure. Below is a repro. Copy/paste to console part of Inspector (say in Chrome, Firefox (Firebug)):

    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
    });
    
    linkTree.addSelectionListener(
        new AjxListener(this, function() {console.log('addSelectionListener works! - click');console.log(arguments);}, [])
    );
    --
    Zimbra 7.1.2 GA NETWORK

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

    Default

    Ok, I have replied in the other thread but I think this one is more appropriate.

    Hi skyflyer,

    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.

    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.

    I think I'll leave this to Zimbra developers.

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

    Default

    ychaouche,

    thanks for taking the time to look into this issue.

    I seem to be missing this information (ITEM_SELECTED, ITEM_DESELECTED) in the event info I get back. According to DwtTree.prototype._notifyListeners implementation it should part of the detail property of the event; but in both events, the value of detail field is 0.

    Regards,
    Miha.
    --
    Zimbra 7.1.2 GA NETWORK

Similar Threads

  1. dwtTree
    By rr_khaseeb1 in forum Developers
    Replies: 2
    Last Post: 08-04-2008, 03:56 AM
  2. right-clicks and desired features.
    By rotorboy in forum Users
    Replies: 1
    Last Post: 06-11-2008, 11:59 AM
  3. DwtListView, DvListView and DwtTree
    By Heladito in forum Developers
    Replies: 0
    Last Post: 11-21-2005, 03:04 AM

Tags for this Thread

Posting Permissions

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