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