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.require("dojo.lang.declare");
12
dojo.provide("dojo.widget.TreeWithNode");
13
dojo.declare("dojo.widget.TreeWithNode", null, function () {
14
}, {loadStates:{UNCHECKED:"UNCHECKED", LOADING:"LOADING", LOADED:"LOADED"}, state:"UNCHECKED", objectId:"", isContainer:true, lockLevel:0, lock:function () {
15
	this.lockLevel++;
16
}, unlock:function () {
17
	if (!this.lockLevel) {
18
		dojo.raise(this.widgetType + " unlock: not locked");
19
	}
20
	this.lockLevel--;
21
}, expandLevel:0, loadLevel:0, hasLock:function () {
22
	return this.lockLevel > 0;
23
}, isLocked:function () {
24
	var node = this;
25
	while (true) {
26
		if (node.lockLevel) {
27
			return true;
28
		}
29
		if (!node.parent || node.isTree) {
30
			break;
31
		}
32
		node = node.parent;
33
	}
34
	return false;
35
}, flushLock:function () {
36
	this.lockLevel = 0;
37
}, actionIsDisabled:function (action) {
38
	var disabled = false;
39
	if (dojo.lang.inArray(this.actionsDisabled, action)) {
40
		disabled = true;
41
	}
42
	if (this.isTreeNode) {
43
		if (!this.tree.allowAddChildToLeaf && action == this.actions.ADDCHILD && !this.isFolder) {
44
			disabled = true;
45
		}
46
	}
47
	return disabled;
48
}, actionIsDisabledNow:function (action) {
49
	return this.actionIsDisabled(action) || this.isLocked();
50
}, setChildren:function (childrenArray) {
51
	if (this.isTreeNode && !this.isFolder) {
52
		this.setFolder();
53
	} else {
54
		if (this.isTreeNode) {
55
			this.state = this.loadStates.LOADED;
56
		}
57
	}
58
	var hadChildren = this.children.length > 0;
59
	if (hadChildren && childrenArray) {
60
		this.destroyChildren();
61
	}
62
	if (childrenArray) {
63
		this.children = childrenArray;
64
	}
65
	var hasChildren = this.children.length > 0;
66
	if (this.isTreeNode && hasChildren != hadChildren) {
67
		this.viewSetHasChildren();
68
	}
69
	for (var i = 0; i < this.children.length; i++) {
70
		var child = this.children[i];
71
		if (!(child instanceof dojo.widget.Widget)) {
72
			child = this.children[i] = this.tree.createNode(child);
73
			var childWidgetCreated = true;
74
		} else {
75
			var childWidgetCreated = false;
76
		}
77
		if (!child.parent) {
78
			child.parent = this;
79
			if (this.tree !== child.tree) {
80
				child.updateTree(this.tree);
81
			}
82
			child.viewAddLayout();
83
			this.containerNode.appendChild(child.domNode);
84
			var message = {child:child, index:i, parent:this, childWidgetCreated:childWidgetCreated};
85
			delete dojo.widget.manager.topWidgets[child.widgetId];
86
			dojo.event.topic.publish(this.tree.eventNames.afterAddChild, message);
87
		}
88
		if (this.tree.eagerWidgetInstantiation) {
89
			dojo.lang.forEach(this.children, function (child) {
90
				child.setChildren();
91
			});
92
		}
93
	}
94
}, doAddChild:function (child, index) {
95
	return this.addChild(child, index, true);
96
}, addChild:function (child, index, dontPublishEvent) {
97
	if (dojo.lang.isUndefined(index)) {
98
		index = this.children.length;
99
	}
100
	if (!child.isTreeNode) {
101
		dojo.raise("You can only add TreeNode widgets to a " + this.widgetType + " widget!");
102
		return;
103
	}
104
	this.children.splice(index, 0, child);
105
	child.parent = this;
106
	child.addedTo(this, index, dontPublishEvent);
107
	delete dojo.widget.manager.topWidgets[child.widgetId];
108
}, onShow:function () {
109
	this.animationInProgress = false;
110
}, onHide:function () {
111
	this.animationInProgress = false;
112
}});
113