Node-Red configuration
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.

ui_dropdown.html 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <script type="text/javascript">
  2. RED.nodes.registerType('ui_dropdown',{
  3. category: RED._("node-red-dashboard/ui_base:ui_base.label.category"),
  4. color: 'rgb(176, 223, 227)',
  5. defaults: {
  6. name: {value: ''},
  7. label: {value: ''},
  8. tooltip: {value: ''},
  9. place: {value: 'Select option'},
  10. group: {type: 'ui_group', required:true},
  11. order: {value: 0},
  12. width: {value: 0, validate: function(v) {
  13. var width = v||0;
  14. var currentGroup = $('#node-input-group').val()||this.group;
  15. var groupNode = RED.nodes.node(currentGroup);
  16. var valid = !groupNode || +width <= +groupNode.width;
  17. $("#node-input-size").toggleClass("input-error",!valid);
  18. return valid;
  19. }
  20. },
  21. height: {value: 0},
  22. passthru: {value: true},
  23. multiple: {value: false},
  24. options: {value:[{value: '', label : ''}],
  25. validate:function(v) {
  26. var unique = new Set(v.map(function(o) {return o.value;}));
  27. return v.length == unique.size;
  28. }},
  29. payload: {value: ''},
  30. topic: {value: 'topic', validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('topicType'):function(v) { return true})},
  31. topicType: {value: 'msg'},
  32. className: {value: ''}
  33. },
  34. inputs:1,
  35. outputs:1,
  36. icon: "ui_dropdown.png",
  37. paletteLabel: 'dropdown',
  38. label: function() { return this.name || (~this.label.indexOf("{{") ? null : this.label) || 'dropdown'; },
  39. labelStyle: function() { return this.name?"node_label_italic":""; },
  40. oneditprepare: function() {
  41. if (this.multiple === undefined) {
  42. $("#node-input-multiple").prop('checked', false);;
  43. }
  44. $("#node-input-size").elementSizer({
  45. width: "#node-input-width",
  46. height: "#node-input-height",
  47. group: "#node-input-group"
  48. });
  49. var un = new Set(this.options.map(function(o) {return o.value}));
  50. if (this.options.length == un.size) { $("#valWarning").hide(); }
  51. else { $("#valWarning").show(); }
  52. function generateOption(i, option) {
  53. var container = $('<li/>',{style:"background: #fff; margin:0; padding:8px 0px 0px; border-bottom: 1px solid #ccc;"});
  54. var row = $('<div/>').appendTo(container);
  55. var row2 = $('<div/>',{style:"padding-top:5px; padding-left:175px;"}).appendTo(container);
  56. var row3 = $('<div/>',{style:"padding-top:5px; padding-left:120px;"}).appendTo(container);
  57. $('<i style="color:#eee; cursor:move; margin-left:3px;" class="node-input-option-handle fa fa-bars"></i>').appendTo(row);
  58. var valueField = $('<input/>',{class:"node-input-option-value",type:"text",style:"margin-left:7px; width:calc(50% - 32px);", placeholder: 'Value',value:option.value}).appendTo(row).typedInput({default:option.type||'str',types:['str','num','bool']});
  59. var labelField = $('<input/>',{class:"node-input-option-label",type:"text",style:"margin-left:7px; width:calc(50% - 32px);", placeholder: 'Label', value:option.label}).appendTo(row);
  60. var finalspan = $('<span/>',{style:"float:right; margin-right:8px;"}).appendTo(row);
  61. var deleteButton = $('<a/>',{href:"#",class:"editor-button editor-button-small", style:"margin-top:7px; margin-left:5px;"}).appendTo(finalspan);
  62. $('<i/>',{class:"fa fa-remove"}).appendTo(deleteButton);
  63. deleteButton.click(function() {
  64. container.css({"background":"#fee"});
  65. container.fadeOut(300, function() {
  66. $(this).remove();
  67. });
  68. });
  69. $("#node-input-option-container").append(container);
  70. }
  71. $("#node-input-add-option").click(function() {
  72. generateOption($("#node-input-option-container").children().length+1, {});
  73. $("#node-input-option-container-div").scrollTop($("#node-input-option-container-div").get(0).scrollHeight);
  74. });
  75. for (var i=0; i<this.options.length; i++) {
  76. var option = this.options[i];
  77. generateOption(i+1,option);
  78. }
  79. $( "#node-input-option-container" ).sortable({
  80. axis: "y",
  81. handle:".node-input-option-handle",
  82. cursor: "move"
  83. });
  84. $('#node-input-topic').typedInput({
  85. default: 'str',
  86. typeField: $("#node-input-topicType"),
  87. types: ['str','msg','flow','global']
  88. });
  89. },
  90. oneditsave: function() {
  91. var options = $("#node-input-option-container").children();
  92. var node = this;
  93. node.options = [];
  94. options.each(function(i) {
  95. var option = $(this);
  96. var o = {
  97. label: option.find(".node-input-option-label").val(),
  98. value: option.find(".node-input-option-value").typedInput('value'),
  99. type: option.find(".node-input-option-value").typedInput('type')
  100. };
  101. if (option.find(".node-input-option-value").typedInput('type') === "num") {
  102. o.value = Number(o.value);
  103. }
  104. if (option.find(".node-input-option-value").typedInput('type') === "bool") {
  105. o.value = (o.value == "true");
  106. }
  107. node.options.push(o);
  108. });
  109. },
  110. oneditresize: function() {
  111. }
  112. });
  113. </script>
  114. <script type="text/html" data-template-name="ui_dropdown">
  115. <div class="form-row">
  116. <label for="node-input-group"><i class="fa fa-table"></i> Group</label>
  117. <input type="text" id="node-input-group">
  118. </div>
  119. <div class="form-row">
  120. <label><i class="fa fa-object-group"></i> Size</label>
  121. <input type="hidden" id="node-input-width">
  122. <input type="hidden" id="node-input-height">
  123. <button class="editor-button" id="node-input-size"></button>
  124. </div>
  125. <div class="form-row">
  126. <label for="node-input-label"><i class="fa fa-tag"></i> Label</label>
  127. <input type="text" id="node-input-label" placeholder="optional label">
  128. </div>
  129. <div class="form-row">
  130. <label for="node-input-tooltip"><i class="fa fa-info-circle"></i> Tooltip</label>
  131. <input type="text" id="node-input-tooltip" placeholder="optional tooltip">
  132. </div>
  133. <div class="form-row">
  134. <label for="node-input-place"><i class="fa fa-tag"></i> Placeholder</label>
  135. <input type="text" id="node-input-place" placeholder="optional placeholder">
  136. </div>
  137. <div class="form-row node-input-option-container-row" style="margin-bottom: 0px;width: 100%">
  138. <label for="node-input-width" style="vertical-align:top"><i class="fa fa-list-alt"></i> Options</label>
  139. <div id="node-input-option-container-div" style="box-sizing:border-box; border-radius:5px; height:257px; padding:5px; border:1px solid #ccc; overflow-y:scroll; display:inline-block; width:calc(70% + 15px);">
  140. <span id="valWarning" style="color:#910000"><b>All Values must be unique.</b></span>
  141. <ol id="node-input-option-container" style="list-style-type:none; margin:0;"></ol>
  142. </div>
  143. </div>
  144. <div class="form-row">
  145. <a href="#" class="editor-button editor-button-small" id="node-input-add-option" style="margin-top:4px; margin-left:103px;"><i class="fa fa-plus"></i> <span>option</span></a>
  146. </div>
  147. <div class="form-row">
  148. <label style="width:auto" for="node-input-multiple"><i class="fa fa-th-list"></i> Allow multiple selections from list: </label>
  149. <input type="checkbox" checked id="node-input-multiple" style="display:inline-block; width:auto; vertical-align:top;">
  150. </div>
  151. <div class="form-row">
  152. <label style="width:auto" for="node-input-passthru"><i class="fa fa-arrow-right"></i> If <code>msg</code> arrives on input, pass through to output: </label>
  153. <input type="checkbox" checked id="node-input-passthru" style="display:inline-block; width:auto; vertical-align:top;">
  154. </div>
  155. <div class="form-row">
  156. <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
  157. <input type="text" id="node-input-topic" placeholder="optional msg.topic">
  158. <input type="hidden" id="node-input-topicType">
  159. </div>
  160. <div class="form-row">
  161. <label for="node-input-className"><i class="fa fa-code"></i> Class</label>
  162. <input type="text" id="node-input-className" placeholder="Optional CSS class name(s) for widget"/>
  163. </div>
  164. <div class="form-row">
  165. <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
  166. <input type="text" id="node-input-name">
  167. </div>
  168. </script>