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.TreeContextMenu");
12
dojo.require("dojo.event.*");
13
dojo.require("dojo.io.*");
14
dojo.require("dojo.widget.Menu2");
15
dojo.widget.defineWidget("dojo.widget.TreeContextMenu", dojo.widget.PopupMenu2, function () {
16
	this.listenedTrees = [];
17
}, {open:function (x, y, parentMenu, explodeSrc) {
18
	var result = dojo.widget.PopupMenu2.prototype.open.apply(this, arguments);
19
	dojo.event.topic.publish(this.eventNames.open, {menu:this});
20
	return result;
21
}, listenTree:function (tree) {
22
	var nodes = tree.getDescendants();
23
	for (var i = 0; i < nodes.length; i++) {
24
		if (!nodes[i].isTreeNode) {
25
			continue;
26
		}
27
		this.bindDomNode(nodes[i].labelNode);
28
	}
29
	var _this = this;
30
	dojo.event.topic.subscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
31
	dojo.event.topic.subscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
32
	dojo.event.topic.subscribe(tree.eventNames.moveTo, this, "onMoveTo");
33
	dojo.event.topic.subscribe(tree.eventNames.removeNode, this, "onRemoveNode");
34
	dojo.event.topic.subscribe(tree.eventNames.addChild, this, "onAddChild");
35
	dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
36
	this.listenedTrees.push(tree);
37
}, unlistenTree:function (tree) {
38
	dojo.event.topic.unsubscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
39
	dojo.event.topic.unsubscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
40
	dojo.event.topic.unsubscribe(tree.eventNames.moveTo, this, "onMoveTo");
41
	dojo.event.topic.unsubscribe(tree.eventNames.removeNode, this, "onRemoveNode");
42
	dojo.event.topic.unsubscribe(tree.eventNames.addChild, this, "onAddChild");
43
	dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
44
	for (var i = 0; i < this.listenedTrees.length; i++) {
45
		if (this.listenedTrees[i] === tree) {
46
			this.listenedTrees.splice(i, 1);
47
			break;
48
		}
49
	}
50
}, onTreeDestroy:function (message) {
51
	this.unlistenTree(message.source);
52
}, bindTreeNode:function (node) {
53
	var _this = this;
54
	dojo.lang.forEach(node.getDescendants(), function (e) {
55
		_this.bindDomNode(e.labelNode);
56
	});
57
}, unBindTreeNode:function (node) {
58
	var _this = this;
59
	dojo.lang.forEach(node.getDescendants(), function (e) {
60
		_this.unBindDomNode(e.labelNode);
61
	});
62
}, onCreateDOMNode:function (message) {
63
	this.bindTreeNode(message.source);
64
}, onMoveFrom:function (message) {
65
	if (!dojo.lang.inArray(this.listenedTrees, message.newTree)) {
66
		this.unBindTreeNode(message.child);
67
	}
68
}, onMoveTo:function (message) {
69
	if (dojo.lang.inArray(this.listenedTrees, message.newTree)) {
70
		this.bindTreeNode(message.child);
71
	}
72
}, onRemoveNode:function (message) {
73
	this.unBindTreeNode(message.child);
74
}, onAddChild:function (message) {
75
	if (message.domNodeInitialized) {
76
		this.bindTreeNode(message.child);
77
	}
78
}});
79
dojo.widget.defineWidget("dojo.widget.TreeMenuItem", dojo.widget.MenuItem2, {treeActions:"", initialize:function (args, frag) {
80
	this.treeActions = this.treeActions.split(",");
81
	for (var i = 0; i < this.treeActions.length; i++) {
82
		this.treeActions[i] = this.treeActions[i].toUpperCase();
83
	}
84
}, getTreeNode:function () {
85
	var menu = this;
86
	while (!(menu instanceof dojo.widget.TreeContextMenu)) {
87
		menu = menu.parent;
88
	}
89
	var source = menu.getTopOpenEvent().target;
90
	while (!source.getAttribute("treeNode") && source.tagName != "body") {
91
		source = source.parentNode;
92
	}
93
	if (source.tagName == "body") {
94
		dojo.raise("treeNode not detected");
95
	}
96
	var treeNode = dojo.widget.manager.getWidgetById(source.getAttribute("treeNode"));
97
	return treeNode;
98
}, menuOpen:function (message) {
99
	var treeNode = this.getTreeNode();
100
	this.setDisabled(false);
101
	var _this = this;
102
	dojo.lang.forEach(_this.treeActions, function (action) {
103
		_this.setDisabled(treeNode.actionIsDisabled(action));
104
	});
105
}, toString:function () {
106
	return "[" + this.widgetType + " node " + this.getTreeNode() + "]";
107
}});
108