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.

84 lines
2.9KB

  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.config = (function() {
  17. var content = document.createElement("div");
  18. content.id = "tab-config";
  19. content.style.paddingTop = "4px";
  20. content.style.paddingLeft = "4px";
  21. content.style.paddingRight = "4px";
  22. var list = $("<ul>",{class:"tab-config-list"}).appendTo(content);
  23. $("#btn-config-nodes").click(function(){
  24. if (!RED.sidebar.containsTab("config")) {
  25. RED.sidebar.addTab("config",content,true);
  26. }
  27. refresh();
  28. RED.sidebar.show("config");
  29. });
  30. function refresh() {
  31. list.empty();
  32. RED.nodes.eachConfig(function(node) {
  33. var li = list.find("#tab-config-list-type-"+node.type);
  34. if (li.length === 0) {
  35. li = $("<li>",{id:"tab-config-list-type-"+node.type}).appendTo(list);
  36. $('<div class="tab-config-list-type">'+node.type+'</div>').appendTo(li);
  37. }
  38. var label = "";
  39. if (typeof node._def.label == "function") {
  40. label = node._def.label.call(node);
  41. } else {
  42. label = node._def.label;
  43. }
  44. label = label || "&nbsp;";
  45. var entry = $('<div class="tab-config-list-entry"></div>').appendTo(li);
  46. entry.on('dblclick',function(e) {
  47. RED.editor.editConfig("", node.type, node.id);
  48. });
  49. var userArray = node.users.map(function(n) { return n.id });
  50. entry.on('mouseover',function(e) {
  51. RED.nodes.eachNode(function(node) {
  52. if( userArray.indexOf(node.id) != -1) {
  53. node.highlighted = true;
  54. node.dirty = true;
  55. }
  56. });
  57. RED.view.redraw();
  58. });
  59. entry.on('mouseout',function(e) {
  60. RED.nodes.eachNode(function(node) {
  61. if(node.highlighted) {
  62. node.highlighted = false;
  63. node.dirty = true;
  64. }
  65. });
  66. RED.view.redraw();
  67. });
  68. $('<div class="tab-config-list-label">'+label+'</div>').appendTo(entry);
  69. $('<div class="tab-config-list-users">'+node.users.length+'</div>').appendTo(entry);
  70. });
  71. }
  72. return {
  73. refresh:refresh
  74. }
  75. })();