source: trunk/web/addons/job_monarch/lib/extjs-30/src/widgets/tree/TreeEventModel.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 4.5 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7Ext.tree.TreeEventModel = function(tree){
8    this.tree = tree;
9    this.tree.on('render', this.initEvents, this);
10}
11
12Ext.tree.TreeEventModel.prototype = {
13    initEvents : function(){
14        var el = this.tree.getTreeEl();
15        el.on('click', this.delegateClick, this);
16        if(this.tree.trackMouseOver !== false){
17            this.tree.innerCt.on('mouseover', this.delegateOver, this);
18            this.tree.innerCt.on('mouseout', this.delegateOut, this);
19        }
20        el.on('dblclick', this.delegateDblClick, this);
21        el.on('contextmenu', this.delegateContextMenu, this);
22    },
23
24    getNode : function(e){
25        var t;
26        if(t = e.getTarget('.x-tree-node-el', 10)){
27            var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
28            if(id){
29                return this.tree.getNodeById(id);
30            }
31        }
32        return null;
33    },
34
35    getNodeTarget : function(e){
36        var t = e.getTarget('.x-tree-node-icon', 1);
37        if(!t){
38            t = e.getTarget('.x-tree-node-el', 6);
39        }
40        return t;
41    },
42
43    delegateOut : function(e, t){
44        if(!this.beforeEvent(e)){
45            return;
46        }
47        if(e.getTarget('.x-tree-ec-icon', 1)){
48            var n = this.getNode(e);
49            this.onIconOut(e, n);
50            if(n == this.lastEcOver){
51                delete this.lastEcOver;
52            }
53        }
54        if((t = this.getNodeTarget(e)) && !e.within(t, true)){
55            this.onNodeOut(e, this.getNode(e));
56        }
57    },
58
59    delegateOver : function(e, t){
60        if(!this.beforeEvent(e)){
61            return;
62        }
63        if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
64            Ext.getBody().on('mouseover', this.trackExit, this);
65            this.trackingDoc = true;
66        }
67        if(this.lastEcOver){ // prevent hung highlight
68            this.onIconOut(e, this.lastEcOver);
69            delete this.lastEcOver;
70        }
71        if(e.getTarget('.x-tree-ec-icon', 1)){
72            this.lastEcOver = this.getNode(e);
73            this.onIconOver(e, this.lastEcOver);
74        }
75        if(t = this.getNodeTarget(e)){
76            this.onNodeOver(e, this.getNode(e));
77        }
78    },
79
80    trackExit : function(e){
81        if(this.lastOverNode && !e.within(this.lastOverNode.ui.getEl())){
82            this.onNodeOut(e, this.lastOverNode);
83            delete this.lastOverNode;
84            Ext.getBody().un('mouseover', this.trackExit, this);
85            this.trackingDoc = false;
86        }
87    },
88
89    delegateClick : function(e, t){
90        if(!this.beforeEvent(e)){
91            return;
92        }
93
94        if(e.getTarget('input[type=checkbox]', 1)){
95            this.onCheckboxClick(e, this.getNode(e));
96        }
97        else if(e.getTarget('.x-tree-ec-icon', 1)){
98            this.onIconClick(e, this.getNode(e));
99        }
100        else if(this.getNodeTarget(e)){
101            this.onNodeClick(e, this.getNode(e));
102        }
103    },
104
105    delegateDblClick : function(e, t){
106        if(this.beforeEvent(e) && this.getNodeTarget(e)){
107            this.onNodeDblClick(e, this.getNode(e));
108        }
109    },
110
111    delegateContextMenu : function(e, t){
112        if(this.beforeEvent(e) && this.getNodeTarget(e)){
113            this.onNodeContextMenu(e, this.getNode(e));
114        }
115    },
116
117    onNodeClick : function(e, node){
118        node.ui.onClick(e);
119    },
120
121    onNodeOver : function(e, node){
122        this.lastOverNode = node;
123        node.ui.onOver(e);
124    },
125
126    onNodeOut : function(e, node){
127        node.ui.onOut(e);
128    },
129
130    onIconOver : function(e, node){
131        node.ui.addClass('x-tree-ec-over');
132    },
133
134    onIconOut : function(e, node){
135        node.ui.removeClass('x-tree-ec-over');
136    },
137
138    onIconClick : function(e, node){
139        node.ui.ecClick(e);
140    },
141
142    onCheckboxClick : function(e, node){
143        node.ui.onCheckChange(e);
144    },
145
146    onNodeDblClick : function(e, node){
147        node.ui.onDblClick(e);
148    },
149
150    onNodeContextMenu : function(e, node){
151        node.ui.onContextMenu(e);
152    },
153
154    beforeEvent : function(e){
155        if(this.disabled){
156            e.stopEvent();
157            return false;
158        }
159        return true;
160    },
161
162    disable: function(){
163        this.disabled = true;
164    },
165
166    enable: function(){
167        this.disabled = false;
168    }
169};
Note: See TracBrowser for help on using the repository browser.