Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.widget.TreeNode");
12
dojo.require("dojo.html.*");
13
dojo.require("dojo.event.*");
14
dojo.require("dojo.io.*");
15
dojo.widget.defineWidget("dojo.widget.TreeNode", dojo.widget.HtmlWidget, function () {
16
	this.actionsDisabled = [];
17
}, {widgetType:"TreeNode", loadStates:{UNCHECKED:"UNCHECKED", LOADING:"LOADING", LOADED:"LOADED"}, actions:{MOVE:"MOVE", REMOVE:"REMOVE", EDIT:"EDIT", ADDCHILD:"ADDCHILD"}, isContainer:true, lockLevel:0, templateString:("<div class=\"dojoTreeNode\"> " + "<span treeNode=\"${this.widgetId}\" class=\"dojoTreeNodeLabel\" dojoAttachPoint=\"labelNode\"> " + "\t\t<span dojoAttachPoint=\"titleNode\" dojoAttachEvent=\"onClick: onTitleClick\" class=\"dojoTreeNodeLabelTitle\">${this.title}</span> " + "</span> " + "<span class=\"dojoTreeNodeAfterLabel\" dojoAttachPoint=\"afterLabelNode\">${this.afterLabel}</span> " + "<div dojoAttachPoint=\"containerNode\" style=\"display:none\"></div> " + "</div>").replace(/(>|<)\s+/g, "$1"), childIconSrc:"", childIconFolderSrc:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/closed.gif"), childIconDocumentSrc:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/document.gif"), childIcon:null, isTreeNode:true, objectId:"", afterLabel:"", afterLabelNode:null, expandIcon:null, title:"", object:"", isFolder:false, labelNode:null, titleNode:null, imgs:null, expandLevel:"", tree:null, depth:0, isExpanded:false, state:null, domNodeInitialized:false, isFirstChild:function () {
18
	return this.getParentIndex() == 0 ? true : false;
19
}, isLastChild:function () {
20
	return this.getParentIndex() == this.parent.children.length - 1 ? true : false;
21
}, lock:function () {
22
	return this.tree.lock.apply(this, arguments);
23
}, unlock:function () {
24
	return this.tree.unlock.apply(this, arguments);
25
}, isLocked:function () {
26
	return this.tree.isLocked.apply(this, arguments);
27
}, cleanLock:function () {
28
	return this.tree.cleanLock.apply(this, arguments);
29
}, actionIsDisabled:function (action) {
30
	var _this = this;
31
	var disabled = false;
32
	if (this.tree.strictFolders && action == this.actions.ADDCHILD && !this.isFolder) {
33
		disabled = true;
34
	}
35
	if (dojo.lang.inArray(_this.actionsDisabled, action)) {
36
		disabled = true;
37
	}
38
	if (this.isLocked()) {
39
		disabled = true;
40
	}
41
	return disabled;
42
}, getInfo:function () {
43
	var info = {widgetId:this.widgetId, objectId:this.objectId, index:this.getParentIndex(), isFolder:this.isFolder};
44
	return info;
45
}, initialize:function (args, frag) {
46
	this.state = this.loadStates.UNCHECKED;
47
	for (var i = 0; i < this.actionsDisabled.length; i++) {
48
		this.actionsDisabled[i] = this.actionsDisabled[i].toUpperCase();
49
	}
50
	this.expandLevel = parseInt(this.expandLevel);
51
}, adjustDepth:function (depthDiff) {
52
	for (var i = 0; i < this.children.length; i++) {
53
		this.children[i].adjustDepth(depthDiff);
54
	}
55
	this.depth += depthDiff;
56
	if (depthDiff > 0) {
57
		for (var i = 0; i < depthDiff; i++) {
58
			var img = this.tree.makeBlankImg();
59
			this.imgs.unshift(img);
60
			dojo.html.insertBefore(this.imgs[0], this.domNode.firstChild);
61
		}
62
	}
63
	if (depthDiff < 0) {
64
		for (var i = 0; i < -depthDiff; i++) {
65
			this.imgs.shift();
66
			dojo.html.removeNode(this.domNode.firstChild);
67
		}
68
	}
69
}, markLoading:function () {
70
	this._markLoadingSavedIcon = this.expandIcon.src;
71
	this.expandIcon.src = this.tree.expandIconSrcLoading;
72
}, unMarkLoading:function () {
73
	if (!this._markLoadingSavedIcon) {
74
		return;
75
	}
76
	var im = new Image();
77
	im.src = this.tree.expandIconSrcLoading;
78
	if (this.expandIcon.src == im.src) {
79
		this.expandIcon.src = this._markLoadingSavedIcon;
80
	}
81
	this._markLoadingSavedIcon = null;
82
}, setFolder:function () {
83
	dojo.event.connect(this.expandIcon, "onclick", this, "onTreeClick");
84
	this.expandIcon.src = this.isExpanded ? this.tree.expandIconSrcMinus : this.tree.expandIconSrcPlus;
85
	this.isFolder = true;
86
}, createDOMNode:function (tree, depth) {
87
	this.tree = tree;
88
	this.depth = depth;
89
	this.imgs = [];
90
	for (var i = 0; i < this.depth + 1; i++) {
91
		var img = this.tree.makeBlankImg();
92
		this.domNode.insertBefore(img, this.labelNode);
93
		this.imgs.push(img);
94
	}
95
	this.expandIcon = this.imgs[this.imgs.length - 1];
96
	this.childIcon = this.tree.makeBlankImg();
97
	this.imgs.push(this.childIcon);
98
	dojo.html.insertBefore(this.childIcon, this.titleNode);
99
	if (this.children.length || this.isFolder) {
100
		this.setFolder();
101
	} else {
102
		this.state = this.loadStates.LOADED;
103
	}
104
	dojo.event.connect(this.childIcon, "onclick", this, "onIconClick");
105
	for (var i = 0; i < this.children.length; i++) {
106
		this.children[i].parent = this;
107
		var node = this.children[i].createDOMNode(this.tree, this.depth + 1);
108
		this.containerNode.appendChild(node);
109
	}
110
	if (this.children.length) {
111
		this.state = this.loadStates.LOADED;
112
	}
113
	this.updateIcons();
114
	this.domNodeInitialized = true;
115
	dojo.event.topic.publish(this.tree.eventNames.createDOMNode, {source:this});
116
	return this.domNode;
117
}, onTreeClick:function (e) {
118
	dojo.event.topic.publish(this.tree.eventNames.treeClick, {source:this, event:e});
119
}, onIconClick:function (e) {
120
	dojo.event.topic.publish(this.tree.eventNames.iconClick, {source:this, event:e});
121
}, onTitleClick:function (e) {
122
	dojo.event.topic.publish(this.tree.eventNames.titleClick, {source:this, event:e});
123
}, markSelected:function () {
124
	dojo.html.addClass(this.titleNode, "dojoTreeNodeLabelSelected");
125
}, unMarkSelected:function () {
126
	dojo.html.removeClass(this.titleNode, "dojoTreeNodeLabelSelected");
127
}, updateExpandIcon:function () {
128
	if (this.isFolder) {
129
		this.expandIcon.src = this.isExpanded ? this.tree.expandIconSrcMinus : this.tree.expandIconSrcPlus;
130
	} else {
131
		this.expandIcon.src = this.tree.blankIconSrc;
132
	}
133
}, updateExpandGrid:function () {
134
	if (this.tree.showGrid) {
135
		if (this.depth) {
136
			this.setGridImage(-2, this.isLastChild() ? this.tree.gridIconSrcL : this.tree.gridIconSrcT);
137
		} else {
138
			if (this.isFirstChild()) {
139
				this.setGridImage(-2, this.isLastChild() ? this.tree.gridIconSrcX : this.tree.gridIconSrcY);
140
			} else {
141
				this.setGridImage(-2, this.isLastChild() ? this.tree.gridIconSrcL : this.tree.gridIconSrcT);
142
			}
143
		}
144
	} else {
145
		this.setGridImage(-2, this.tree.blankIconSrc);
146
	}
147
}, updateChildGrid:function () {
148
	if ((this.depth || this.tree.showRootGrid) && this.tree.showGrid) {
149
		this.setGridImage(-1, (this.children.length && this.isExpanded) ? this.tree.gridIconSrcP : this.tree.gridIconSrcC);
150
	} else {
151
		if (this.tree.showGrid && !this.tree.showRootGrid) {
152
			this.setGridImage(-1, (this.children.length && this.isExpanded) ? this.tree.gridIconSrcZ : this.tree.blankIconSrc);
153
		} else {
154
			this.setGridImage(-1, this.tree.blankIconSrc);
155
		}
156
	}
157
}, updateParentGrid:function () {
158
	var parent = this.parent;
159
	for (var i = 0; i < this.depth; i++) {
160
		var idx = this.imgs.length - (3 + i);
161
		var img = (this.tree.showGrid && !parent.isLastChild()) ? this.tree.gridIconSrcV : this.tree.blankIconSrc;
162
		this.setGridImage(idx, img);
163
		parent = parent.parent;
164
	}
165
}, updateExpandGridColumn:function () {
166
	if (!this.tree.showGrid) {
167
		return;
168
	}
169
	var _this = this;
170
	var icon = this.isLastChild() ? this.tree.blankIconSrc : this.tree.gridIconSrcV;
171
	dojo.lang.forEach(_this.getDescendants(), function (node) {
172
		node.setGridImage(_this.depth, icon);
173
	});
174
	this.updateExpandGrid();
175
}, updateIcons:function () {
176
	this.imgs[0].style.display = this.tree.showRootGrid ? "inline" : "none";
177
	this.buildChildIcon();
178
	this.updateExpandGrid();
179
	this.updateChildGrid();
180
	this.updateParentGrid();
181
	dojo.profile.stop("updateIcons");
182
}, buildChildIcon:function () {
183
	if (this.childIconSrc) {
184
		this.childIcon.src = this.childIconSrc;
185
	}
186
	this.childIcon.style.display = this.childIconSrc ? "inline" : "none";
187
}, setGridImage:function (idx, src) {
188
	if (idx < 0) {
189
		idx = this.imgs.length + idx;
190
	}
191
	this.imgs[idx].style.backgroundImage = "url(" + src + ")";
192
}, updateIconTree:function () {
193
	this.tree.updateIconTree.call(this);
194
}, expand:function () {
195
	if (this.isExpanded) {
196
		return;
197
	}
198
	if (this.children.length) {
199
		this.showChildren();
200
	}
201
	this.isExpanded = true;
202
	this.updateExpandIcon();
203
	dojo.event.topic.publish(this.tree.eventNames.expand, {source:this});
204
}, collapse:function () {
205
	if (!this.isExpanded) {
206
		return;
207
	}
208
	this.hideChildren();
209
	this.isExpanded = false;
210
	this.updateExpandIcon();
211
	dojo.event.topic.publish(this.tree.eventNames.collapse, {source:this});
212
}, hideChildren:function () {
213
	this.tree.toggleObj.hide(this.containerNode, this.toggleDuration, this.explodeSrc, dojo.lang.hitch(this, "onHide"));
214
	if (dojo.exists(dojo, "dnd.dragManager.dragObjects") && dojo.dnd.dragManager.dragObjects.length) {
215
		dojo.dnd.dragManager.cacheTargetLocations();
216
	}
217
}, showChildren:function () {
218
	this.tree.toggleObj.show(this.containerNode, this.toggleDuration, this.explodeSrc, dojo.lang.hitch(this, "onShow"));
219
	if (dojo.exists(dojo, "dnd.dragManager.dragObjects") && dojo.dnd.dragManager.dragObjects.length) {
220
		dojo.dnd.dragManager.cacheTargetLocations();
221
	}
222
}, addChild:function () {
223
	return this.tree.addChild.apply(this, arguments);
224
}, doAddChild:function () {
225
	return this.tree.doAddChild.apply(this, arguments);
226
}, edit:function (props) {
227
	dojo.lang.mixin(this, props);
228
	if (props.title) {
229
		this.titleNode.innerHTML = this.title;
230
	}
231
	if (props.afterLabel) {
232
		this.afterLabelNode.innerHTML = this.afterLabel;
233
	}
234
	if (props.childIconSrc) {
235
		this.buildChildIcon();
236
	}
237
}, removeNode:function () {
238
	return this.tree.removeNode.apply(this, arguments);
239
}, doRemoveNode:function () {
240
	return this.tree.doRemoveNode.apply(this, arguments);
241
}, toString:function () {
242
	return "[" + this.widgetType + " Tree:" + this.tree + " ID:" + this.widgetId + " Title:" + this.title + "]";
243
}});
244