Subversion Repositories Applications.papyrus

Rev

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