Blame view

test/FitNesseRoot/files/javascript/fitnesseTreeControl.js 1.24 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function add_fitnesse_methods_to_YUI_textnode() {
  YAHOO.widget.TextNode.prototype.fitnesse_path = function() {
    var node_list = this.path_labels();
    return node_list.join('.');
  };
  YAHOO.widget.TextNode.prototype.path_labels = function() {
    if (!this.parent.path_labels) {
      return [this.label];
    }
    return this.parent.path_labels().concat(this.label);
  };
}

function add_nodes_to_parent(child_node_names, parent_node) {
  $(child_node_names).sort().each(function() {
    var node = new YAHOO.widget.TextNode({label:this, target:"page_frame"}, parent_node, false);
    node.href = "/" + node.fitnesse_path();
  });
}

var tree;
function tree_init(div_id) {
  add_fitnesse_methods_to_YUI_textnode();

  tree = new YAHOO.widget.TreeView(div_id);
  tree.setDynamicLoad(load_child_nodes, 1);
  $.getJSON("/root?names&format=json",
    function(json) {
      add_nodes_to_parent(json, tree.getRoot());
      tree.render();
    }
    );
  tree.subscribe("clickEvent", function(node) {
    return false;
  });
}
function load_child_nodes(node, fnLoadComplete)
{
  var callback = function(json) {
    add_nodes_to_parent(json, node);
    fnLoadComplete();
  };
  var url = "/" + node.fitnesse_path() + "?names&format=json";
  $.getJSON(url, callback);
}