Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
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:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.TreeBasicController");
13
dojo.provide("dojo.widget.TreeBasicController");
12
dojo.require("dojo.event.*");
14
dojo.require("dojo.event.*");
13
dojo.require("dojo.json");
15
dojo.require("dojo.json");
14
dojo.require("dojo.io.*");
16
dojo.require("dojo.io.*");
15
dojo.widget.defineWidget("dojo.widget.TreeBasicController", dojo.widget.HtmlWidget, {widgetType:"TreeBasicController", DNDController:"", dieWithTree:false, initialize:function (args, frag) {
17
dojo.widget.defineWidget("dojo.widget.TreeBasicController", dojo.widget.HtmlWidget, {widgetType:"TreeBasicController", DNDController:"", dieWithTree:false, initialize:function (args, frag) {
16
	if (this.DNDController == "create") {
18
	if (this.DNDController == "create") {
17
		dojo.require("dojo.dnd.TreeDragAndDrop");
19
		dojo.require("dojo.dnd.TreeDragAndDrop");
18
		this.DNDController = new dojo.dnd.TreeDNDController(this);
20
		this.DNDController = new dojo.dnd.TreeDNDController(this);
19
	}
21
	}
20
}, listenTree:function (tree) {
22
}, listenTree:function (tree) {
21
	dojo.event.topic.subscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
23
	dojo.event.topic.subscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
22
	dojo.event.topic.subscribe(tree.eventNames.treeClick, this, "onTreeClick");
24
	dojo.event.topic.subscribe(tree.eventNames.treeClick, this, "onTreeClick");
23
	dojo.event.topic.subscribe(tree.eventNames.treeCreate, this, "onTreeCreate");
25
	dojo.event.topic.subscribe(tree.eventNames.treeCreate, this, "onTreeCreate");
24
	dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
26
	dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
25
	if (this.DNDController) {
27
	if (this.DNDController) {
26
		this.DNDController.listenTree(tree);
28
		this.DNDController.listenTree(tree);
27
	}
29
	}
28
}, unlistenTree:function (tree) {
30
}, unlistenTree:function (tree) {
29
	dojo.event.topic.unsubscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
31
	dojo.event.topic.unsubscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
30
	dojo.event.topic.unsubscribe(tree.eventNames.treeClick, this, "onTreeClick");
32
	dojo.event.topic.unsubscribe(tree.eventNames.treeClick, this, "onTreeClick");
31
	dojo.event.topic.unsubscribe(tree.eventNames.treeCreate, this, "onTreeCreate");
33
	dojo.event.topic.unsubscribe(tree.eventNames.treeCreate, this, "onTreeCreate");
32
	dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
34
	dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
33
}, onTreeDestroy:function (message) {
35
}, onTreeDestroy:function (message) {
34
	var tree = message.source;
36
	var tree = message.source;
35
	this.unlistenTree(tree);
37
	this.unlistenTree(tree);
36
	if (this.dieWithTree) {
38
	if (this.dieWithTree) {
37
		this.destroy();
39
		this.destroy();
38
	}
40
	}
39
}, onCreateDOMNode:function (message) {
41
}, onCreateDOMNode:function (message) {
40
	var node = message.source;
42
	var node = message.source;
41
	if (node.expandLevel > 0) {
43
	if (node.expandLevel > 0) {
42
		this.expandToLevel(node, node.expandLevel);
44
		this.expandToLevel(node, node.expandLevel);
43
	}
45
	}
44
}, onTreeCreate:function (message) {
46
}, onTreeCreate:function (message) {
45
	var tree = message.source;
47
	var tree = message.source;
46
	var _this = this;
48
	var _this = this;
47
	if (tree.expandLevel) {
49
	if (tree.expandLevel) {
48
		dojo.lang.forEach(tree.children, function (child) {
50
		dojo.lang.forEach(tree.children, function (child) {
49
			_this.expandToLevel(child, tree.expandLevel - 1);
51
			_this.expandToLevel(child, tree.expandLevel - 1);
50
		});
52
		});
51
	}
53
	}
52
}, expandToLevel:function (node, level) {
54
}, expandToLevel:function (node, level) {
53
	if (level == 0) {
55
	if (level == 0) {
54
		return;
56
		return;
55
	}
57
	}
56
	var children = node.children;
58
	var children = node.children;
57
	var _this = this;
59
	var _this = this;
58
	var handler = function (node, expandLevel) {
60
	var handler = function (node, expandLevel) {
59
		this.node = node;
61
		this.node = node;
60
		this.expandLevel = expandLevel;
62
		this.expandLevel = expandLevel;
61
		this.process = function () {
63
		this.process = function () {
62
			for (var i = 0; i < this.node.children.length; i++) {
64
			for (var i = 0; i < this.node.children.length; i++) {
63
				var child = node.children[i];
65
				var child = node.children[i];
64
				_this.expandToLevel(child, this.expandLevel);
66
				_this.expandToLevel(child, this.expandLevel);
65
			}
67
			}
66
		};
68
		};
67
	};
69
	};
68
	var h = new handler(node, level - 1);
70
	var h = new handler(node, level - 1);
69
	this.expand(node, false, h, h.process);
71
	this.expand(node, false, h, h.process);
70
}, onTreeClick:function (message) {
72
}, onTreeClick:function (message) {
71
	var node = message.source;
73
	var node = message.source;
72
	if (node.isLocked()) {
74
	if (node.isLocked()) {
73
		return false;
75
		return false;
74
	}
76
	}
75
	if (node.isExpanded) {
77
	if (node.isExpanded) {
76
		this.collapse(node);
78
		this.collapse(node);
77
	} else {
79
	} else {
78
		this.expand(node);
80
		this.expand(node);
79
	}
81
	}
80
}, expand:function (node, sync, callObj, callFunc) {
82
}, expand:function (node, sync, callObj, callFunc) {
81
	node.expand();
83
	node.expand();
82
	if (callFunc) {
84
	if (callFunc) {
83
		callFunc.apply(callObj, [node]);
85
		callFunc.apply(callObj, [node]);
84
	}
86
	}
85
}, collapse:function (node) {
87
}, collapse:function (node) {
86
	node.collapse();
88
	node.collapse();
87
}, canMove:function (child, newParent) {
89
}, canMove:function (child, newParent) {
88
	if (child.actionIsDisabled(child.actions.MOVE)) {
90
	if (child.actionIsDisabled(child.actions.MOVE)) {
89
		return false;
91
		return false;
90
	}
92
	}
91
	if (child.parent !== newParent && newParent.actionIsDisabled(newParent.actions.ADDCHILD)) {
93
	if (child.parent !== newParent && newParent.actionIsDisabled(newParent.actions.ADDCHILD)) {
92
		return false;
94
		return false;
93
	}
95
	}
94
	var node = newParent;
96
	var node = newParent;
95
	while (node.isTreeNode) {
97
	while (node.isTreeNode) {
96
		if (node === child) {
98
		if (node === child) {
97
			return false;
99
			return false;
98
		}
100
		}
99
		node = node.parent;
101
		node = node.parent;
100
	}
102
	}
101
	return true;
103
	return true;
102
}, move:function (child, newParent, index) {
104
}, move:function (child, newParent, index) {
103
	if (!this.canMove(child, newParent)) {
105
	if (!this.canMove(child, newParent)) {
104
		return false;
106
		return false;
105
	}
107
	}
106
	var result = this.doMove(child, newParent, index);
108
	var result = this.doMove(child, newParent, index);
107
	if (!result) {
109
	if (!result) {
108
		return result;
110
		return result;
109
	}
111
	}
110
	if (newParent.isTreeNode) {
112
	if (newParent.isTreeNode) {
111
		this.expand(newParent);
113
		this.expand(newParent);
112
	}
114
	}
113
	return result;
115
	return result;
114
}, doMove:function (child, newParent, index) {
116
}, doMove:function (child, newParent, index) {
115
	child.tree.move(child, newParent, index);
117
	child.tree.move(child, newParent, index);
116
	return true;
118
	return true;
117
}, canRemoveNode:function (child) {
119
}, canRemoveNode:function (child) {
118
	if (child.actionIsDisabled(child.actions.REMOVE)) {
120
	if (child.actionIsDisabled(child.actions.REMOVE)) {
119
		return false;
121
		return false;
120
	}
122
	}
121
	return true;
123
	return true;
122
}, removeNode:function (node, callObj, callFunc) {
124
}, removeNode:function (node, callObj, callFunc) {
123
	if (!this.canRemoveNode(node)) {
125
	if (!this.canRemoveNode(node)) {
124
		return false;
126
		return false;
125
	}
127
	}
126
	return this.doRemoveNode(node, callObj, callFunc);
128
	return this.doRemoveNode(node, callObj, callFunc);
127
}, doRemoveNode:function (node, callObj, callFunc) {
129
}, doRemoveNode:function (node, callObj, callFunc) {
128
	node.tree.removeNode(node);
130
	node.tree.removeNode(node);
129
	if (callFunc) {
131
	if (callFunc) {
130
		callFunc.apply(dojo.lang.isUndefined(callObj) ? this : callObj, [node]);
132
		callFunc.apply(dojo.lang.isUndefined(callObj) ? this : callObj, [node]);
131
	}
133
	}
132
}, canCreateChild:function (parent, index, data) {
134
}, canCreateChild:function (parent, index, data) {
133
	if (parent.actionIsDisabled(parent.actions.ADDCHILD)) {
135
	if (parent.actionIsDisabled(parent.actions.ADDCHILD)) {
134
		return false;
136
		return false;
135
	}
137
	}
136
	return true;
138
	return true;
137
}, createChild:function (parent, index, data, callObj, callFunc) {
139
}, createChild:function (parent, index, data, callObj, callFunc) {
138
	if (!this.canCreateChild(parent, index, data)) {
140
	if (!this.canCreateChild(parent, index, data)) {
139
		return false;
141
		return false;
140
	}
142
	}
141
	return this.doCreateChild.apply(this, arguments);
143
	return this.doCreateChild.apply(this, arguments);
142
}, doCreateChild:function (parent, index, data, callObj, callFunc) {
144
}, doCreateChild:function (parent, index, data, callObj, callFunc) {
143
	var widgetType = data.widgetType ? data.widgetType : "TreeNode";
145
	var widgetType = data.widgetType ? data.widgetType : "TreeNode";
144
	var newChild = dojo.widget.createWidget(widgetType, data);
146
	var newChild = dojo.widget.createWidget(widgetType, data);
145
	parent.addChild(newChild, index);
147
	parent.addChild(newChild, index);
146
	this.expand(parent);
148
	this.expand(parent);
147
	if (callFunc) {
149
	if (callFunc) {
148
		callFunc.apply(callObj, [newChild]);
150
		callFunc.apply(callObj, [newChild]);
149
	}
151
	}
150
	return newChild;
152
	return newChild;
151
}});
153
}});
152
 
154