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