2 * Copyright 2013 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 RED.sidebar.info = (function() {
18 var content = document.createElement("div");
19 content.id = "tab-info";
20 content.style.paddingTop = "4px";
21 content.style.paddingLeft = "4px";
22 content.style.paddingRight = "4px";
24 RED.sidebar.addTab("info",content);
26 function jsonFilter(key,value) {
31 if ($.isArray(value)) {
32 return "[array:"+value.length+"]";
33 } else if (t === "object") {
35 } else if (t === "string") {
36 if (value.length > 30) {
37 return value.substring(0,30)+" ...";
43 function refresh(node) {
44 var table = '<table class="node-info"><tbody>';
46 table += '<tr class="blank"><td colspan="2">Node</td></tr>';
47 table += "<tr><td>Type</td><td> "+node.type+"</td></tr>";
48 table += "<tr><td>ID</td><td> "+node.id+"</td></tr>";
49 table += '<tr class="blank"><td colspan="2">Properties</td></tr>';
50 for (var n in node._def.defaults) {
51 if (node._def.defaults.hasOwnProperty(n)) {
52 var val = node[n]||"";
53 var type = typeof val;
54 if (type === "string") {
55 if (val.length > 30) {
56 val = val.substring(0,30)+" ...";
58 val = val.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
59 } else if (type === "number") {
61 } else if ($.isArray(val)) {
63 for (var i=0;i<Math.min(node[n].length,10);i++) {
64 var vv = JSON.stringify(node[n][i],jsonFilter," ").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
65 val += " "+i+": "+vv+"<br/>";
67 if (node[n].length > 10) {
68 val += " ... "+node[n].length+" items<br/>";
72 val = JSON.stringify(val,jsonFilter," ");
73 val = val.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
76 table += "<tr><td> "+n+"</td><td>"+val+"</td></tr>";
79 table += "</tbody></table><br/>";
80 table += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>";
81 $("#tab-info").html(table);
87 $("#tab-info").html("");