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.