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.TreeDemo");
12
dojo.require("dojo.Deferred");
13
dojo.widget.TreeDemo = {reportIfDefered:function (res) {
14
	if (res instanceof dojo.Deferred) {
15
		res.addCallbacks(function (res) {
16
			return res;
17
		}, function (err) {
18
			dojo.debug("Error");
19
			dojo.debugShallow(err);
20
		});
21
	}
22
}, resetRandomChildren:function (maxCount) {
23
	this.randomChildrenMaxCount = maxCount;
24
	this.randomChildrenCount = 0;
25
	this.randomChildrenDepth = 0;
26
}, makeRandomChildren:function (title) {
27
	this.randomChildrenDepth++;
28
	var children = [];
29
	for (var i = 1; i <= 5; i++) {
30
		var t = title + (this.randomChildrenDepth == 1 ? "" : ".") + i;
31
		var node = {title:t};
32
		children.push(node);
33
		this.randomChildrenCount++;
34
		if (this.randomChildrenCount >= this.randomChildrenMaxCount) {
35
			break;
36
		}
37
	}
38
	var i = 1;
39
	var _this = this;
40
	dojo.lang.forEach(children, function (child) {
41
		var t = title + (_this.randomChildrenDepth == 1 ? "" : ".") + i;
42
		i++;
43
		if (_this.randomChildrenCount < _this.randomChildrenMaxCount && (_this.randomChildrenDepth == 1 && child === children[0] || _this.randomChildrenDepth < 5 && Math.random() > 0.3)) {
44
			child.children = _this.makeRandomChildren(t);
45
		}
46
	});
47
	this.randomChildrenDepth--;
48
	return children;
49
}, bindDemoMenu:function (controller) {
50
	var _t = this;
51
	dojo.event.topic.subscribe("treeContextMenuDestroy/engage", function (menuItem) {
52
		var node = menuItem.getTreeNode();
53
		_t.reportIfDefered(controller.destroyChild(node));
54
	});
55
	dojo.event.topic.subscribe("treeContextMenuRefresh/engage", function (menuItem) {
56
		var node = menuItem.getTreeNode();
57
		_t.reportIfDefered(controller.refreshChildren(node));
58
	});
59
	dojo.event.topic.subscribe("treeContextMenuCreate/engage", function (menuItem) {
60
		var node = menuItem.getTreeNode();
61
		var d = controller.createAndEdit(node, 0);
62
		_t.reportIfDefered(d);
63
	});
64
	dojo.event.topic.subscribe("treeContextMenuUp/engage", function (menuItem) {
65
		var node = menuItem.getTreeNode();
66
		if (node.isFirstChild()) {
67
			return;
68
		}
69
		_t.reportIfDefered(controller.move(node, node.parent, node.getParentIndex() - 1));
70
	});
71
	dojo.event.topic.subscribe("treeContextMenuDown/engage", function (menuItem) {
72
		var node = menuItem.getTreeNode();
73
		if (node.isLastChild()) {
74
			return;
75
		}
76
		_t.reportIfDefered(controller.move(node, node.parent, node.getParentIndex() + 1));
77
	});
78
	dojo.event.topic.subscribe("treeContextMenuEdit/engage", function (menuItem) {
79
		var node = menuItem.getTreeNode();
80
		_t.reportIfDefered(controller.editLabelStart(node));
81
	});
82
}};
83