Debian Codegraph @

src/main/org/h2/server/web/res/tree.js

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * * Initial Developer: H2 Group
5 */
6
7 var nodeList = new Array();
8 var icons = new Array();
9 var tables = new Array();
10 var tablesByName = new Object();
11
12 function Table(name, columns, i) {
13 this.name = name;
14 this.columns = columns;
15 this.id = i;
16 }
17
18 function addTable(name, columns, i) {
19 var t = new Table(name, columns, i);
20 tables[tables.length] = t;
21 tablesByName[name] = t;
22 }
23
24 function ins(s, isTable) {
25 if (parent.h2query) {
26 if (parent.h2query.insertText) {
27 parent.h2query.insertText(s, isTable);
28 }
29 }
30 }
31
32 function refreshQueryTables() {
33 if (parent.h2query) {
34 if (parent.h2query.refreshTables) {
35 parent.h2query.refreshTables();
36 }
37 }
38 }
39
40 function goToTable(s) {
41 var t = tablesByName[s];
42 if (t) {
43 hitOpen(t.id);
44 return true;
45 }
46 return false;
47 }
48
49 function loadIcons() {
50 icons[0] = new Image();
51 icons[0].src = "tree_minus.gif";
52 icons[1] = new Image();
53 icons[1].src = "tree_plus.gif";
54 }
55
56 function Node(level, type, icon, text, link) {
57 this.level = level;
58 this.type = type;
59 this.icon = icon;
60 this.text = text;
61 this.link = link;
62 }
63
64 function setNode(id, level, type, icon, text, link) {
65 nodeList[id] = new Node(level, type, icon, text, link);
66 }
67
68 function writeDiv(i, level, dist) {
69 if (dist>0) {
70 document.write("<div id=\"div"+(i-1)+"\" style=\"display: none;\">");
71 } else {
72 while (dist++<0) {
73 document.write("</div>");
74 }
75 }
76 }
77
78 function writeTree() {
79 loadIcons();
80 var last=nodeList[0];
81 for (var i=0; i<nodeList.length; i++) {
82 var node=nodeList[i];
83 writeDiv(i, node.level, node.level-last.level);
84 last=node;
85 var j=node.level;
86 while (j-->0) {
87 document.write("<img src=\"tree_empty.gif\"/>");
88 }
89 if (node.type==1) {
90 if (i < nodeList.length-1 && nodeList[i+1].level > node.level) {
91 document.write("<img onclick=\"hit("+i+");\" id=\"join"+i+"\" src=\"tree_plus.gif\"/>");
92 } else {
93 document.write("<img src=\"tree_empty.gif\"/>");
94 }
95 }
96 document.write("<img src=\"tree_"+node.icon+".gif\"/>&nbsp;");
97 if (node.link==null) {
98 document.write(node.text);
99 } else {
100 document.write("<a id='"+node.text+"' href=\""+node.link+"\" >"+node.text+"</a>");
101 }
102 document.write("<br />");
103 }
104 writeDiv(0, 0, -last.type);
105 }
106
107 function hit(i) {
108 var theDiv = document.getElementById("div"+i);
109 var theJoin = document.getElementById("join"+i);
110 if (theDiv.style.display == 'none') {
111 theJoin.src = icons[0].src;
112 theDiv.style.display = '';
113 } else {
114 theJoin.src = icons[1].src;
115 theDiv.style.display = 'none';
116 }
117 }
118
119 function hitOpen(i) {
120 var theDiv = document.getElementById("div"+i);
121 var theJoin = document.getElementById("join"+i);
122 theJoin.src = icons[0].src;
123 theDiv.style.display = '';
124 }