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.TreeControllerExtension");
12
dojo.declare("dojo.widget.TreeControllerExtension", null, {saveExpandedIndices:function (node, field) {
13
	var obj = {};
14
	for (var i = 0; i < node.children.length; i++) {
15
		if (node.children[i].isExpanded) {
16
			var key = dojo.lang.isUndefined(field) ? i : node.children[i][field];
17
			obj[key] = this.saveExpandedIndices(node.children[i], field);
18
		}
19
	}
20
	return obj;
21
}, restoreExpandedIndices:function (node, savedIndices, field) {
22
	var _this = this;
23
	var handler = function (node, savedIndices) {
24
		this.node = node;
25
		this.savedIndices = savedIndices;
26
		this.process = function () {
27
			_this.restoreExpandedIndices(this.node, this.savedIndices, field);
28
		};
29
	};
30
	for (var i = 0; i < node.children.length; i++) {
31
		var child = node.children[i];
32
		var found = false;
33
		var key = -1;
34
		if (dojo.lang.isUndefined(field) && savedIndices[i]) {
35
			found = true;
36
			key = i;
37
		}
38
		if (field) {
39
			for (var key in savedIndices) {
40
				if (key == child[field]) {
41
					found = true;
42
					break;
43
				}
44
			}
45
		}
46
		if (found) {
47
			var h = new handler(child, savedIndices[key]);
48
			_this.expand(child, false, h, h.process);
49
		} else {
50
			if (child.isExpanded) {
51
				dojo.lang.forEach(child.getDescendants(), function (elem) {
52
					_this.collapse(elem);
53
				});
54
			}
55
		}
56
	}
57
}});
58