Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Details | Compare with Previous | 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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.Tree");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.event.*");
16
dojo.require("dojo.io.*");
17
dojo.require("dojo.widget.HtmlWidget");
18
dojo.require("dojo.widget.TreeNode");
19
dojo.require("dojo.html.common");
20
dojo.require("dojo.html.selection");
21
dojo.widget.defineWidget("dojo.widget.Tree", dojo.widget.HtmlWidget, function () {
22
	this.eventNames = {};
23
	this.tree = this;
24
	this.DNDAcceptTypes = [];
25
	this.actionsDisabled = [];
26
}, {widgetType:"Tree", eventNamesDefault:{createDOMNode:"createDOMNode", treeCreate:"treeCreate", treeDestroy:"treeDestroy", treeClick:"treeClick", iconClick:"iconClick", titleClick:"titleClick", moveFrom:"moveFrom", moveTo:"moveTo", addChild:"addChild", removeNode:"removeNode", expand:"expand", collapse:"collapse"}, isContainer:true, DNDMode:"off", lockLevel:0, strictFolders:true, DNDModes:{BETWEEN:1, ONTO:2}, DNDAcceptTypes:"", templateCssString:"\n.dojoTree {\n\tfont: caption;\n\tfont-size: 11px;\n\tfont-weight: normal;\n\toverflow: auto;\n}\n\n\n.dojoTreeNodeLabelTitle {\n\tpadding-left: 2px;\n\tcolor: WindowText;\n}\n\n.dojoTreeNodeLabel {\n\tcursor:hand;\n\tcursor:pointer;\n}\n\n.dojoTreeNodeLabelTitle:hover {\n\ttext-decoration: underline;\n}\n\n.dojoTreeNodeLabelSelected {\n\tbackground-color: Highlight;\n\tcolor: HighlightText;\n}\n\n.dojoTree div {\n\twhite-space: nowrap;\n}\n\n.dojoTree img, .dojoTreeNodeLabel img {\n\tvertical-align: middle;\n}\n\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/Tree.css"), templateString:"<div class=\"dojoTree\"></div>", isExpanded:true, isTree:true, objectId:"", controller:"", selector:"", menu:"", expandLevel:"", blankIconSrc:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_blank.gif"), gridIconSrcT:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_t.gif"), gridIconSrcL:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_l.gif"), gridIconSrcV:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_v.gif"), gridIconSrcP:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_p.gif"), gridIconSrcC:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_c.gif"), gridIconSrcX:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_x.gif"), gridIconSrcY:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_y.gif"), gridIconSrcZ:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_grid_z.gif"), expandIconSrcPlus:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_expand_plus.gif"), expandIconSrcMinus:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_expand_minus.gif"), expandIconSrcLoading:dojo.uri.moduleUri("dojo.widget", "templates/images/Tree/treenode_loading.gif"), iconWidth:18, iconHeight:18, showGrid:true, showRootGrid:true, actionIsDisabled:function (action) {
27
	var _this = this;
28
	return dojo.lang.inArray(_this.actionsDisabled, action);
29
}, actions:{ADDCHILD:"ADDCHILD"}, getInfo:function () {
30
	var info = {widgetId:this.widgetId, objectId:this.objectId};
31
	return info;
32
}, initializeController:function () {
33
	if (this.controller != "off") {
34
		if (this.controller) {
35
			this.controller = dojo.widget.byId(this.controller);
36
		} else {
37
			dojo.require("dojo.widget.TreeBasicController");
38
			this.controller = dojo.widget.createWidget("TreeBasicController", {DNDController:(this.DNDMode ? "create" : ""), dieWithTree:true});
39
		}
40
		this.controller.listenTree(this);
41
	} else {
42
		this.controller = null;
43
	}
44
}, initializeSelector:function () {
45
	if (this.selector != "off") {
46
		if (this.selector) {
47
			this.selector = dojo.widget.byId(this.selector);
48
		} else {
49
			dojo.require("dojo.widget.TreeSelector");
50
			this.selector = dojo.widget.createWidget("TreeSelector", {dieWithTree:true});
51
		}
52
		this.selector.listenTree(this);
53
	} else {
54
		this.selector = null;
55
	}
56
}, initialize:function (args, frag) {
57
	var _this = this;
58
	for (name in this.eventNamesDefault) {
59
		if (dojo.lang.isUndefined(this.eventNames[name])) {
60
			this.eventNames[name] = this.widgetId + "/" + this.eventNamesDefault[name];
61
		}
62
	}
63
	for (var i = 0; i < this.actionsDisabled.length; i++) {
64
		this.actionsDisabled[i] = this.actionsDisabled[i].toUpperCase();
65
	}
66
	if (this.DNDMode == "off") {
67
		this.DNDMode = 0;
68
	} else {
69
		if (this.DNDMode == "between") {
70
			this.DNDMode = this.DNDModes.ONTO | this.DNDModes.BETWEEN;
71
		} else {
72
			if (this.DNDMode == "onto") {
73
				this.DNDMode = this.DNDModes.ONTO;
74
			}
75
		}
76
	}
77
	this.expandLevel = parseInt(this.expandLevel);
78
	this.initializeSelector();
79
	this.initializeController();
80
	if (this.menu) {
81
		this.menu = dojo.widget.byId(this.menu);
82
		this.menu.listenTree(this);
83
	}
84
	this.containerNode = this.domNode;
85
}, postCreate:function () {
86
	this.createDOMNode();
87
}, createDOMNode:function () {
88
	dojo.html.disableSelection(this.domNode);
89
	for (var i = 0; i < this.children.length; i++) {
90
		this.children[i].parent = this;
91
		var node = this.children[i].createDOMNode(this, 0);
92
		this.domNode.appendChild(node);
93
	}
94
	if (!this.showRootGrid) {
95
		for (var i = 0; i < this.children.length; i++) {
96
			this.children[i].expand();
97
		}
98
	}
99
	dojo.event.topic.publish(this.eventNames.treeCreate, {source:this});
100
}, destroy:function () {
101
	dojo.event.topic.publish(this.tree.eventNames.treeDestroy, {source:this});
102
	return dojo.widget.HtmlWidget.prototype.destroy.apply(this, arguments);
103
}, addChild:function (child, index) {
104
	var message = {child:child, index:index, parent:this, domNodeInitialized:child.domNodeInitialized};
105
	this.doAddChild.apply(this, arguments);
106
	dojo.event.topic.publish(this.tree.eventNames.addChild, message);
107
}, doAddChild:function (child, index) {
108
	if (dojo.lang.isUndefined(index)) {
109
		index = this.children.length;
110
	}
111
	if (!child.isTreeNode) {
112
		dojo.raise("You can only add TreeNode widgets to a " + this.widgetType + " widget!");
113
		return;
114
	}
115
	if (this.isTreeNode) {
116
		if (!this.isFolder) {
117
			this.setFolder();
118
		}
119
	}
120
	var _this = this;
121
	dojo.lang.forEach(child.getDescendants(), function (elem) {
122
		elem.tree = _this.tree;
123
	});
124
	child.parent = this;
125
	if (this.isTreeNode) {
126
		this.state = this.loadStates.LOADED;
127
	}
128
	if (index < this.children.length) {
129
		dojo.html.insertBefore(child.domNode, this.children[index].domNode);
130
	} else {
131
		this.containerNode.appendChild(child.domNode);
132
		if (this.isExpanded && this.isTreeNode) {
133
			this.showChildren();
134
		}
135
	}
136
	this.children.splice(index, 0, child);
137
	if (child.domNodeInitialized) {
138
		var d = this.isTreeNode ? this.depth : -1;
139
		child.adjustDepth(d - child.depth + 1);
140
		child.updateIconTree();
141
	} else {
142
		child.depth = this.isTreeNode ? this.depth + 1 : 0;
143
		child.createDOMNode(child.tree, child.depth);
144
	}
145
	var prevSibling = child.getPreviousSibling();
146
	if (child.isLastChild() && prevSibling) {
147
		prevSibling.updateExpandGridColumn();
148
	}
149
}, makeBlankImg:function () {
150
	var img = document.createElement("img");
151
	img.style.width = this.iconWidth + "px";
152
	img.style.height = this.iconHeight + "px";
153
	img.src = this.blankIconSrc;
154
	img.style.verticalAlign = "middle";
155
	return img;
156
}, updateIconTree:function () {
157
	if (!this.isTree) {
158
		this.updateIcons();
159
	}
160
	for (var i = 0; i < this.children.length; i++) {
161
		this.children[i].updateIconTree();
162
	}
163
}, toString:function () {
164
	return "[" + this.widgetType + " ID:" + this.widgetId + "]";
165
}, move:function (child, newParent, index) {
166
	var oldParent = child.parent;
167
	var oldTree = child.tree;
168
	this.doMove.apply(this, arguments);
169
	var newParent = child.parent;
170
	var newTree = child.tree;
171
	var message = {oldParent:oldParent, oldTree:oldTree, newParent:newParent, newTree:newTree, child:child};
172
	dojo.event.topic.publish(oldTree.eventNames.moveFrom, message);
173
	dojo.event.topic.publish(newTree.eventNames.moveTo, message);
174
}, doMove:function (child, newParent, index) {
175
	child.parent.doRemoveNode(child);
176
	newParent.doAddChild(child, index);
177
}, removeNode:function (child) {
178
	if (!child.parent) {
179
		return;
180
	}
181
	var oldTree = child.tree;
182
	var oldParent = child.parent;
183
	var removedChild = this.doRemoveNode.apply(this, arguments);
184
	dojo.event.topic.publish(this.tree.eventNames.removeNode, {child:removedChild, tree:oldTree, parent:oldParent});
185
	return removedChild;
186
}, doRemoveNode:function (child) {
187
	if (!child.parent) {
188
		return;
189
	}
190
	var parent = child.parent;
191
	var children = parent.children;
192
	var index = child.getParentIndex();
193
	if (index < 0) {
194
		dojo.raise("Couldn't find node " + child + " for removal");
195
	}
196
	children.splice(index, 1);
197
	dojo.html.removeNode(child.domNode);
198
	if (parent.children.length == 0 && !parent.isTree) {
199
		parent.containerNode.style.display = "none";
200
	}
201
	if (index == children.length && index > 0) {
202
		children[index - 1].updateExpandGridColumn();
203
	}
204
	if (parent instanceof dojo.widget.Tree && index == 0 && children.length > 0) {
205
		children[0].updateExpandGrid();
206
	}
207
	child.parent = child.tree = null;
208
	return child;
209
}, markLoading:function () {
210
}, unMarkLoading:function () {
211
}, lock:function () {
212
	!this.lockLevel && this.markLoading();
213
	this.lockLevel++;
214
}, unlock:function () {
215
	if (!this.lockLevel) {
216
		dojo.raise("unlock: not locked");
217
	}
218
	this.lockLevel--;
219
	!this.lockLevel && this.unMarkLoading();
220
}, isLocked:function () {
221
	var node = this;
222
	while (true) {
223
		if (node.lockLevel) {
224
			return true;
225
		}
226
		if (node instanceof dojo.widget.Tree) {
227
			break;
228
		}
229
		node = node.parent;
230
	}
231
	return false;
232
}, flushLock:function () {
233
	this.lockLevel = 0;
234
	this.unMarkLoading();
235
}});
236