Sha256: 1ecac50cf75559d6c0a7aad46bcb2f9f78975317eb286f324f002dec89a4e10b

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

function initTree(containerID, jsonData) {
	$("#" + containerID).jstree({
		"plugins" : [ 
			//"themes",
			"json_data","ui","crrm","cookies","dnd","search","types","hotkeys","contextmenu" 
		],
		"json_data" : { 
			"data" : prepareTreeNode(jsonData)
		}
	})
}

function prepareTreeNode(node, newParent, depth) {
	if(!depth) depth = 0;
	
	if(!newParent) {
		var root = new Object();
		root["children"] = new Array();
		root["data"] = "root";
		root["state"] = "open";
		return prepareTreeNode(node, root, depth);
	}

	var numChildren = 0;
	for(i in node) {
		numChildren ++;
		var newNode = new Object();
		newNode["metadata"] = new Object();
		newNode["metadata"]["propName"] = i;
		if (typeof node[i] == 'object'){
			newNode["data"] = i;
			newNode["children"] = new Array();
			prepareTreeNode(node[i], newNode, depth+1);
		} else {
			var value = node[i];
			value = value.length > 50 ? (value.substring(0,50) + " [...]") : value;
			newNode["data"] = i + " = " + value;
			newNode["metadata"]["propValue"] = node[i];
		}
		if(depth < 2) {
			newNode["state"] = "open";
		}
		if(newParent) {
			if(!newParent["children"]) {
				newParent["children"] = new Array();
			}
			newParent["children"].push(newNode);
		}
	}
	if(numChildren <= 0) {
		newParent["children"] = null;
	}
	return newParent;
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cloud-toaster-1.1.6 webapp/app/assets/javascripts/jstree.util.js