You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.3KB

  1. /**
  2. * Copyright 2013 IBM Corp.
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. **/
  16. RED.sidebar.info = (function() {
  17. var content = document.createElement("div");
  18. content.id = "tab-info";
  19. content.style.paddingTop = "4px";
  20. content.style.paddingLeft = "4px";
  21. content.style.paddingRight = "4px";
  22. RED.sidebar.addTab("info",content);
  23. function jsonFilter(key,value) {
  24. if (key === "") {
  25. return value;
  26. }
  27. var t = typeof value;
  28. if ($.isArray(value)) {
  29. return "[array:"+value.length+"]";
  30. } else if (t === "object") {
  31. return "[object]"
  32. } else if (t === "string") {
  33. if (value.length > 30) {
  34. return value.substring(0,30)+" ...";
  35. }
  36. }
  37. return value;
  38. }
  39. function refresh(node) {
  40. var table = '<table class="node-info"><tbody>';
  41. table += "<tr><td>Type</td><td>&nbsp;"+node.type+"</td></tr>";
  42. table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
  43. table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>';
  44. for (var n in node._def.defaults) {
  45. if (node._def.defaults.hasOwnProperty(n)) {
  46. var val = node[n]||"";
  47. var type = typeof val;
  48. if (type === "string") {
  49. if (val.length > 30) {
  50. val = val.substring(0,30)+" ...";
  51. }
  52. val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  53. } else if (type === "number") {
  54. val = val.toString();
  55. } else if ($.isArray(val)) {
  56. val = "[<br/>";
  57. for (var i=0;i<Math.min(node[n].length,10);i++) {
  58. var vv = JSON.stringify(node[n][i],jsonFilter," ").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  59. val += "&nbsp;"+i+": "+vv+"<br/>";
  60. }
  61. if (node[n].length > 10) {
  62. val += "&nbsp;... "+node[n].length+" items<br/>";
  63. }
  64. val += "]";
  65. } else {
  66. val = JSON.stringify(val,jsonFilter," ");
  67. val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  68. }
  69. table += "<tr><td>&nbsp;"+n+"</td><td>"+val+"</td></tr>";
  70. }
  71. }
  72. table += "</tbody></table><br/>";
  73. table += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>";
  74. $("#tab-info").html(table);
  75. }
  76. return {
  77. refresh:refresh,
  78. clear: function() {
  79. $("#tab-info").html("");
  80. }
  81. }
  82. })();