Diffstat (limited to 'frontend/beta/js/YUI-extensions/tree/TreeNode.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/YUI-extensions/tree/TreeNode.js | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/tree/TreeNode.js b/frontend/beta/js/YUI-extensions/tree/TreeNode.js new file mode 100644 index 0000000..c676481 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/tree/TreeNode.js | |||
@@ -0,0 +1,300 @@ | |||
1 | /** | ||
2 | * @class YAHOO.ext.tree.TreeNode | ||
3 | * @extends YAHOO.ext.data.Node | ||
4 | * @cfg {Boolean} leaf true if this node is a leaf and does not have or cannot have children | ||
5 | * @cfg {Boolean} expanded true to start the node expanded | ||
6 | * @cfg {Boolean} draggable false to make this node undraggable if DD is on (default to true) | ||
7 | * @cfg {Boolean} isTarget false if this node cannot be drop on | ||
8 | * @cfg {Boolean} disabled true to start the node disabled | ||
9 | * @constructor | ||
10 | * @param {Object} attributes The attributes/config for the node | ||
11 | */ | ||
12 | YAHOO.ext.tree.TreeNode = function(attributes){ | ||
13 | attributes = attributes || {}; | ||
14 | if(typeof attributes == 'string'){ | ||
15 | attributes = {text: attributes}; | ||
16 | } | ||
17 | this.el = null; | ||
18 | this.childrenRendered = false; | ||
19 | this.rendered = false; | ||
20 | YAHOO.ext.tree.TreeNode.superclass.constructor.call(this, attributes); | ||
21 | this.expanded = attributes.expanded === true; | ||
22 | this.isTarget = attributes.isTarget !== false; | ||
23 | this.draggable = attributes.draggable !== false && attributes.allowDrag !== false; | ||
24 | this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false; | ||
25 | this.text = attributes.text; | ||
26 | this.disabled = attributes.disabled === true; | ||
27 | |||
28 | YAHOO.ext.util.Config.apply(this.events, { | ||
29 | 'textchange' : true, | ||
30 | 'beforeexpand' : true, | ||
31 | 'beforecollapse' : true, | ||
32 | 'expand' : true, | ||
33 | 'disabledchange' : true, | ||
34 | 'collapse' : true, | ||
35 | 'beforeclick':true, | ||
36 | 'click':true, | ||
37 | 'dblclick':true, | ||
38 | 'contentmenu':true, | ||
39 | 'beforechildrenrendered':true | ||
40 | }); | ||
41 | |||
42 | var uiClass = this.attributes.uiProvider || YAHOO.ext.tree.TreeNodeUI; | ||
43 | this.ui = new uiClass(this); | ||
44 | }; | ||
45 | YAHOO.extendX(YAHOO.ext.tree.TreeNode, YAHOO.ext.data.Node, { | ||
46 | isExpanded : function(){ | ||
47 | return this.expanded; | ||
48 | }, | ||
49 | |||
50 | getUI : function(){ | ||
51 | return this.ui; | ||
52 | }, | ||
53 | |||
54 | setFirstChild : function(node){ | ||
55 | var of = this.firstChild; | ||
56 | YAHOO.ext.tree.TreeNode.superclass.setFirstChild.call(this, node); | ||
57 | if(this.childrenRendered && of && node != of){ | ||
58 | of.renderIndent(true, true); | ||
59 | } | ||
60 | if(this.rendered){ | ||
61 | this.renderIndent(true, true); | ||
62 | } | ||
63 | }, | ||
64 | |||
65 | setLastChild : function(node){ | ||
66 | var ol = this.lastChild; | ||
67 | YAHOO.ext.tree.TreeNode.superclass.setLastChild.call(this, node); | ||
68 | if(this.childrenRendered && ol && node != ol){ | ||
69 | ol.renderIndent(true, true); | ||
70 | } | ||
71 | if(this.rendered){ | ||
72 | this.renderIndent(true, true); | ||
73 | } | ||
74 | }, | ||
75 | |||
76 | // these methods are overridden to provide lazy rendering support | ||
77 | appendChild : function(){ | ||
78 | var node = YAHOO.ext.tree.TreeNode.superclass.appendChild.apply(this, arguments); | ||
79 | if(node && this.childrenRendered){ | ||
80 | node.render(); | ||
81 | } | ||
82 | this.ui.updateExpandIcon(); | ||
83 | return node; | ||
84 | }, | ||
85 | |||
86 | removeChild : function(node){ | ||
87 | this.ownerTree.getSelectionModel().unselect(node); | ||
88 | YAHOO.ext.tree.TreeNode.superclass.removeChild.apply(this, arguments); | ||
89 | // if it's been rendered remove dom node | ||
90 | if(this.childrenRendered){ | ||
91 | node.ui.remove(); | ||
92 | } | ||
93 | if(this.childNodes.length < 1){ | ||
94 | this.collapse(false, false); | ||
95 | }else{ | ||
96 | this.ui.updateExpandIcon(); | ||
97 | } | ||
98 | return node; | ||
99 | }, | ||
100 | |||
101 | insertBefore : function(node, refNode){ | ||
102 | var newNode = YAHOO.ext.tree.TreeNode.superclass.insertBefore.apply(this, arguments); | ||
103 | if(newNode && refNode && this.childrenRendered){ | ||
104 | node.render(); | ||
105 | } | ||
106 | this.ui.updateExpandIcon(); | ||
107 | return newNode; | ||
108 | }, | ||
109 | |||
110 | setText : function(text){ | ||
111 | var oldText = this.text; | ||
112 | this.text = text; | ||
113 | this.attributes.text = text; | ||
114 | if(this.rendered){ // event without subscribing | ||
115 | this.ui.onTextChange(this, text, oldText); | ||
116 | } | ||
117 | this.fireEvent('textchange', this, text, oldText); | ||
118 | }, | ||
119 | |||
120 | select : function(){ | ||
121 | this.getOwnerTree().getSelectionModel().select(this); | ||
122 | }, | ||
123 | |||
124 | unselect : function(){ | ||
125 | this.getOwnerTree().getSelectionModel().unselect(this); | ||
126 | }, | ||
127 | |||
128 | isSelected : function(){ | ||
129 | return this.getOwnerTree().getSelectionModel().isSelected(node); | ||
130 | }, | ||
131 | |||
132 | expand : function(deep, anim, callback){ | ||
133 | if(!this.expanded){ | ||
134 | if(this.fireEvent('beforeexpand', this, deep, anim) === false){ | ||
135 | return; | ||
136 | } | ||
137 | if(!this.childrenRendered){ | ||
138 | this.renderChildren(); | ||
139 | } | ||
140 | this.expanded = true; | ||
141 | if((this.getOwnerTree().animate && anim !== false) || anim){ | ||
142 | this.ui.animExpand(function(){ | ||
143 | this.fireEvent('expand', this); | ||
144 | if(typeof callback == 'function'){ | ||
145 | callback(this); | ||
146 | } | ||
147 | if(deep === true){ | ||
148 | this.expandChildNodes(true); | ||
149 | } | ||
150 | }.createDelegate(this)); | ||
151 | return; | ||
152 | }else{ | ||
153 | this.ui.expand(); | ||
154 | this.fireEvent('expand', this); | ||
155 | if(typeof callback == 'function'){ | ||
156 | callback(this); | ||
157 | } | ||
158 | } | ||
159 | }else{ | ||
160 | if(typeof callback == 'function'){ | ||
161 | callback(this); | ||
162 | } | ||
163 | } | ||
164 | if(deep === true){ | ||
165 | this.expandChildNodes(true); | ||
166 | } | ||
167 | }, | ||
168 | |||
169 | collapse : function(deep, anim){ | ||
170 | if(this.expanded && (!this.isRoot || (this.isRoot && this.getOwnerTree().rootVisible))){ | ||
171 | if(this.fireEvent('beforecollapse', this, deep, anim) === false){ | ||
172 | return; | ||
173 | } | ||
174 | this.expanded = false; | ||
175 | if((this.getOwnerTree().animate && anim !== false) || anim){ | ||
176 | this.ui.animCollapse(function(){ | ||
177 | this.fireEvent('collapse', this); | ||
178 | if(deep === true){ | ||
179 | this.collapseChildNodes(true); | ||
180 | } | ||
181 | }.createDelegate(this)); | ||
182 | return; | ||
183 | }else{ | ||
184 | this.ui.collapse(); | ||
185 | this.fireEvent('collapse', this); | ||
186 | } | ||
187 | } | ||
188 | if(deep === true){ | ||
189 | var cs = this.childNodes; | ||
190 | for(var i = 0, len = cs.length; i < len; i++) { | ||
191 | cs[i].collapse(true) | ||
192 | } | ||
193 | } | ||
194 | }, | ||
195 | |||
196 | delayedExpand : function(delay){ | ||
197 | if(!this.expandProcId){ | ||
198 | this.expandProcId = this.expand.defer(delay, this); | ||
199 | } | ||
200 | }, | ||
201 | |||
202 | cancelExpand : function(){ | ||
203 | if(this.expandProcId){ | ||
204 | clearTimeout(this.expandProcId); | ||
205 | } | ||
206 | this.expandProcId = false; | ||
207 | }, | ||
208 | |||
209 | toggle : function(){ | ||
210 | if(this.expanded){ | ||
211 | this.collapse(); | ||
212 | }else{ | ||
213 | this.expand(); | ||
214 | } | ||
215 | }, | ||
216 | |||
217 | ensureVisible : function(){ | ||
218 | if(this.parentNode){ | ||
219 | this.parentNode.bubble(function(){ | ||
220 | this.expand(false, false); | ||
221 | }); | ||
222 | } | ||
223 | }, | ||
224 | |||
225 | expandChildNodes : function(deep){ | ||
226 | var cs = this.childNodes; | ||
227 | for(var i = 0, len = cs.length; i < len; i++) { | ||
228 | cs[i].expand(deep); | ||
229 | } | ||
230 | }, | ||
231 | |||
232 | collapseChildNodes : function(deep){ | ||
233 | var cs = this.childNodes; | ||
234 | for(var i = 0, len = cs.length; i < len; i++) { | ||
235 | cs[i].expand(deep); | ||
236 | } | ||
237 | }, | ||
238 | |||
239 | disable : function(){ | ||
240 | this.disabled = true; | ||
241 | this.unselect(); | ||
242 | if(this.rendered && this.ui.onDisableChange){ // event without subscribing | ||
243 | this.ui.onDisableChange(this, true); | ||
244 | } | ||
245 | this.fireEvent('disabledchange', this, true); | ||
246 | }, | ||
247 | |||
248 | enable : function(){ | ||
249 | this.disabled = false; | ||
250 | if(this.rendered && this.ui.onDisableChange){ // event without subscribing | ||
251 | this.ui.onDisableChange(this, false); | ||
252 | } | ||
253 | this.fireEvent('disabledchange', this, false); | ||
254 | }, | ||
255 | |||
256 | renderChildren : function(suppressEvent){ | ||
257 | if(suppressEvent !== false){ | ||
258 | this.fireEvent('beforechildrenrendered', this); | ||
259 | } | ||
260 | var cs = this.childNodes; | ||
261 | for(var i = 0, len = cs.length; i < len; i++){ | ||
262 | cs[i].render(true); | ||
263 | } | ||
264 | this.childrenRendered = true; | ||
265 | }, | ||
266 | |||
267 | sort : function(fn, scope){ | ||
268 | YAHOO.ext.tree.TreeNode.superclass.sort.apply(this, arguments); | ||
269 | if(this.childrenRendered){ | ||
270 | var cs = this.childNodes; | ||
271 | for(var i = 0, len = cs.length; i < len; i++){ | ||
272 | cs[i].render(true); | ||
273 | } | ||
274 | } | ||
275 | }, | ||
276 | |||
277 | render : function(bulkRender){ | ||
278 | this.ui.render(bulkRender); | ||
279 | if(!this.rendered){ | ||
280 | this.rendered = true; | ||
281 | if(this.expanded){ | ||
282 | this.expanded = false; | ||
283 | this.expand(false, false); | ||
284 | } | ||
285 | } | ||
286 | }, | ||
287 | |||
288 | renderIndent : function(deep, refresh){ | ||
289 | if(refresh){ | ||
290 | this.ui.childIndent = null; | ||
291 | } | ||
292 | this.ui.renderIndent(); | ||
293 | if(deep === true && this.childrenRendered){ | ||
294 | var cs = this.childNodes; | ||
295 | for(var i = 0, len = cs.length; i < len; i++){ | ||
296 | cs[i].renderIndent(true, refresh); | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | }); | ||