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