author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /frontend/beta/js/YUI-extensions/tree/TreePanel.js | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'frontend/beta/js/YUI-extensions/tree/TreePanel.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/YUI-extensions/tree/TreePanel.js | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/tree/TreePanel.js b/frontend/beta/js/YUI-extensions/tree/TreePanel.js new file mode 100644 index 0000000..202c0d0 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/tree/TreePanel.js | |||
@@ -0,0 +1,213 @@ | |||
1 | YAHOO.namespace('ext.tree'); | ||
2 | |||
3 | YAHOO.ext.tree.TreePanel = function(el, config){ | ||
4 | YAHOO.ext.tree.TreePanel.superclass.constructor.call(this); | ||
5 | this.el = getEl(el); | ||
6 | this.id = this.el.id; | ||
7 | YAHOO.ext.util.Config.apply(this, config || {}, { | ||
8 | rootVisible : true, | ||
9 | lines : true, | ||
10 | enableDD : false, | ||
11 | hlDrop : true/*, | ||
12 | hlColor: null, | ||
13 | ddGroup : 'TreeDD' | ||
14 | hlBaseColor : 'FFFFFF'*/ | ||
15 | |||
16 | }); | ||
17 | YAHOO.ext.util.Config.apply(this.events, { | ||
18 | 'beforeload' : true, | ||
19 | 'load' : true, | ||
20 | 'textchange' : true, | ||
21 | 'beforeexpand' : true, | ||
22 | 'beforecollapse' : true, | ||
23 | 'expand' : true, | ||
24 | 'collapse' : true, | ||
25 | 'disabledchange' : true, | ||
26 | 'beforeclick':true, | ||
27 | 'click':true, | ||
28 | 'dblclick':true, | ||
29 | 'contentmenu':true, | ||
30 | 'beforechildrenrendered':true, | ||
31 | /** | ||
32 | * @event startdrag | ||
33 | * Fires when a node starts being dragged | ||
34 | * @param {YAHOO.ext.tree.TreePanel} this | ||
35 | * @param {YAHOO.ext.tree.TreeNode} node | ||
36 | * @param {event} e The raw browser event | ||
37 | */ | ||
38 | 'startdrag' : true, | ||
39 | /** | ||
40 | * @event enddrag | ||
41 | * Fires when a drag operation is complete | ||
42 | * @param {YAHOO.ext.tree.TreePanel} this | ||
43 | * @param {YAHOO.ext.tree.TreeNode} node | ||
44 | * @param {event} e The raw browser event | ||
45 | */ | ||
46 | 'enddrag' : true, | ||
47 | /** | ||
48 | * @event dragdrop | ||
49 | * Fires when a dragged node is dropped on a valid DD target | ||
50 | * @param {YAHOO.ext.tree.TreePanel} this | ||
51 | * @param {YAHOO.ext.tree.TreeNode} node | ||
52 | * @param {DD} dd The dd it was dropped on | ||
53 | * @param {event} e The raw browser event | ||
54 | */ | ||
55 | 'dragdrop' : true, | ||
56 | /** | ||
57 | * @event beforenodedrop | ||
58 | * Fires when a DD object is dropped on a node in this tree for preprocessing. This event can cancel. | ||
59 | * @param {Object} dropEvent | ||
60 | */ | ||
61 | 'beforenodedrop' : true, | ||
62 | /** | ||
63 | * @event nodedrop | ||
64 | * Fires after a DD object is dropped on a node in this tree | ||
65 | * @param {Object} dropEvent | ||
66 | */ | ||
67 | 'nodedrop' : true, | ||
68 | /** | ||
69 | * @event nodedragover | ||
70 | * Fires when a tree node is being target | ||
71 | * @param {Object} dragOverEvent | ||
72 | */ | ||
73 | 'nodedragover' : true | ||
74 | }); | ||
75 | if(this.singleExpand){ | ||
76 | this.on('beforeexpand', this.restrictExpand, this, true); | ||
77 | } | ||
78 | // problem with safari and animation | ||
79 | // I am investigating | ||
80 | if(YAHOO.ext.util.Browser.isSafari){ | ||
81 | this.animate = false; | ||
82 | } | ||
83 | }; | ||
84 | YAHOO.extendX(YAHOO.ext.tree.TreePanel, YAHOO.ext.data.Tree, { | ||
85 | restrictExpand : function(node){ | ||
86 | var p = node.parentNode; | ||
87 | if(p){ | ||
88 | if(p.expandedChild && p.expandedChild.parentNode == p){ | ||
89 | p.expandedChild.collapse(); | ||
90 | } | ||
91 | p.expandedChild = node; | ||
92 | } | ||
93 | }, | ||
94 | |||
95 | setRootNode : function(node){ | ||
96 | YAHOO.ext.tree.TreePanel.superclass.setRootNode.call(this, node); | ||
97 | if(!this.rootVisible){ | ||
98 | node.ui = new YAHOO.ext.tree.RootTreeNodeUI(node); | ||
99 | } | ||
100 | return node; | ||
101 | }, | ||
102 | |||
103 | getEl : function(){ | ||
104 | return this.el; | ||
105 | }, | ||
106 | |||
107 | getLoader : function(){ | ||
108 | return this.loader; | ||
109 | }, | ||
110 | |||
111 | expandAll : function(){ | ||
112 | this.root.expand(true); | ||
113 | }, | ||
114 | |||
115 | collapseAll : function(){ | ||
116 | this.root.collapse(true); | ||
117 | }, | ||
118 | |||
119 | getSelectionModel : function(){ | ||
120 | if(!this.selModel){ | ||
121 | this.selModel = new YAHOO.ext.tree.DefaultSelectionModel(); | ||
122 | } | ||
123 | return this.selModel; | ||
124 | }, | ||
125 | |||
126 | expandPath : function(path, attr, callback){ | ||
127 | attr = attr || 'id'; | ||
128 | var keys = path.split(this.pathSeparator); | ||
129 | var curNode = this.root; | ||
130 | if(curNode.attributes[attr] != keys[1]){ // invalid root | ||
131 | if(callback){ | ||
132 | callback(false, null); | ||
133 | } | ||
134 | return; | ||
135 | } | ||
136 | var index = 1; | ||
137 | var f = function(){ | ||
138 | if(++index == keys.length){ | ||
139 | if(callback){ | ||
140 | callback(true, curNode); | ||
141 | } | ||
142 | return; | ||
143 | } | ||
144 | var c = curNode.findChild(attr, keys[index]); | ||
145 | if(!c){ | ||
146 | if(callback){ | ||
147 | callback(false, curNode); | ||
148 | } | ||
149 | return; | ||
150 | } | ||
151 | curNode = c; | ||
152 | c.expand(false, false, f); | ||
153 | } | ||
154 | curNode.expand(false, false, f); | ||
155 | }, | ||
156 | |||
157 | selectPath : function(path, attr, callback){ | ||
158 | attr = attr || 'id'; | ||
159 | var keys = path.split(this.pathSeparator); | ||
160 | var v = keys.pop(); | ||
161 | if(keys.length > 0){ | ||
162 | var f = function(success, node){ | ||
163 | if(success && node){ | ||
164 | var n = node.findChild(attr, v); | ||
165 | if(n){ | ||
166 | n.select(); | ||
167 | if(callback){ | ||
168 | callback(true, n); | ||
169 | } | ||
170 | } | ||
171 | }else{ | ||
172 | if(callback){ | ||
173 | callback(false, n); | ||
174 | } | ||
175 | } | ||
176 | }; | ||
177 | this.expandPath(keys.join(this.pathSeparator), attr, f); | ||
178 | }else{ | ||
179 | this.root.select(); | ||
180 | if(callback){ | ||
181 | callback(true, this.root); | ||
182 | } | ||
183 | } | ||
184 | }, | ||
185 | |||
186 | render : function(){ | ||
187 | this.container = this.el.createChild({tag:'ul', | ||
188 | cls:'ytree-root-ct ' + | ||
189 | (this.lines ? 'ytree-lines' : 'ytree-no-lines')}); | ||
190 | |||
191 | if(this.containerScroll){ | ||
192 | YAHOO.ext.dd.ScrollManager.register(this.el); | ||
193 | } | ||
194 | |||
195 | if((this.enableDD || this.enableDrop) && !this.dropZone){ | ||
196 | this.dropZone = new YAHOO.ext.tree.TreeDropZone(this, this.dropConfig || { | ||
197 | ddGroup: this.ddGroup || 'TreeDD' | ||
198 | }); | ||
199 | } | ||
200 | if((this.enableDD || this.enableDrag) && !this.dragZone){ | ||
201 | this.dragZone = new YAHOO.ext.tree.TreeDragZone(this, this.dragConfig || { | ||
202 | ddGroup: this.ddGroup || 'TreeDD', | ||
203 | scroll: this.ddScroll | ||
204 | }); | ||
205 | } | ||
206 | this.getSelectionModel().init(this); | ||
207 | this.root.render(); | ||
208 | if(!this.rootVisible){ | ||
209 | this.root.renderChildren(); | ||
210 | } | ||
211 | return this; | ||
212 | } | ||
213 | }); | ||