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_switch.html 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <script type="text/javascript">
  2. RED.nodes.registerType('ui_switch',{
  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: 'switch'},
  8. tooltip: {value: ''},
  9. group: {type: 'ui_group', required: true},
  10. order: {value: 0},
  11. width: {value: 0, validate: function(v) {
  12. var width = v||0;
  13. var currentGroup = $('#node-input-group').val()||this.group;
  14. var groupNode = RED.nodes.node(currentGroup);
  15. var valid = !groupNode || +width <= +groupNode.width;
  16. $("#node-input-size").toggleClass("input-error",!valid);
  17. return valid;
  18. }
  19. },
  20. height: {value: 0},
  21. passthru: {value: true},
  22. decouple: {value: "false"},
  23. topic: {value: 'topic', validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('topicType'):function(v) { return true})},
  24. topicType: {value: 'msg'},
  25. style: {value: ''},
  26. onvalue: {value: true, required:true, validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('onvalueType'):function(v) { return true})},
  27. onvalueType: {value: 'bool'},
  28. onicon: {value: '' },
  29. oncolor: {value: ''},
  30. offvalue: {value: false, required:true, validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('offvalueType'):function(v) { return true})},
  31. offvalueType: {value: 'bool'},
  32. officon: {value: ''},
  33. offcolor: {value: ''},
  34. animate: {value: false},
  35. className: {value: ''}
  36. },
  37. inputs:1,
  38. outputs:1,
  39. icon: "ui_switch.png",
  40. paletteLabel: 'switch',
  41. label: function() { return this.name || (~this.label.indexOf("{{") ? null : this.label) || 'switch'; },
  42. labelStyle: function() { return this.name?"node_label_italic":""; },
  43. oneditprepare: function() {
  44. $("#node-input-size").elementSizer({
  45. width: "#node-input-width",
  46. height: "#node-input-height",
  47. group: "#node-input-group"
  48. });
  49. $('#node-input-custom-icons').on("change", function() {
  50. if ($('#node-input-custom-icons').val() === "default") {
  51. $(".form-row-custom-icons").hide();
  52. }
  53. else {
  54. $(".form-row-custom-icons").show();
  55. }
  56. });
  57. if (this.onicon !== "" || this.oncolor !== "" || this.officon !=="" || this.offcolor !== "") {
  58. $('#node-input-custom-icons').val('custom');
  59. }
  60. else {
  61. $(".form-row-custom-icons").hide();
  62. $('#node-input-custom-icons').change();
  63. }
  64. $('#node-input-onvalue').typedInput({
  65. default: 'str',
  66. typeField: $("#node-input-onvalueType"),
  67. types: ['str','num','bool','json','bin','date','flow','global']
  68. });
  69. $('#node-input-offvalue').typedInput({
  70. default: 'str',
  71. typeField: $("#node-input-offvalueType"),
  72. types: ['str','num','bool','json','bin','date','flow','global']
  73. });
  74. $('#node-input-topic').typedInput({
  75. default: 'str',
  76. typeField: $("#node-input-topicType"),
  77. types: ['str','msg','flow','global']
  78. });
  79. $('#node-input-passthru').on("change", function() {
  80. if (this.checked) {
  81. $('.form-row-decouple').hide();
  82. $('#node-input-decouple').val("false");
  83. }
  84. else {
  85. $('.form-row-decouple').show();
  86. }
  87. });
  88. },
  89. oneditsave: function() {
  90. if ($('#node-input-custom-icons').val() === 'default') {
  91. $('#node-input-onicon').val('');
  92. $('#node-input-officon').val('');
  93. $('#node-input-oncolor').val('');
  94. $('#node-input-offcolor').val('');
  95. }
  96. }
  97. });
  98. </script>
  99. <script type="text/html" data-template-name="ui_switch">
  100. <div class="form-row">
  101. <label for="node-input-group"><i class="fa fa-table"></i> Group</label>
  102. <input type="text" id="node-input-group">
  103. </div>
  104. <div class="form-row">
  105. <label><i class="fa fa-object-group"></i> Size</label>
  106. <input type="hidden" id="node-input-width">
  107. <input type="hidden" id="node-input-height">
  108. <button class="editor-button" id="node-input-size"></button>
  109. </div>
  110. <div class="form-row">
  111. <label for="node-input-label"><i class="fa fa-i-cursor"></i> Label</label>
  112. <input type="text" id="node-input-label">
  113. </div>
  114. <div class="form-row">
  115. <label for="node-input-tooltip"><i class="fa fa-info-circle"></i> Tooltip</label>
  116. <input type="text" id="node-input-tooltip" placeholder="optional tooltip">
  117. </div>
  118. <div class="form-row">
  119. <label for="node-input-custom-icons"><i class="fa fa-picture-o"></i> Icon</label>
  120. <select id="node-input-custom-icons" style="width:35%">
  121. <option value="default">Default</option>
  122. <option value="custom">Custom</option>
  123. </select>
  124. <span style="width:auto; padding-left:20px" class="form-row-custom-icons" for="node-input-animate"> Animate
  125. <input type="checkbox" checked id="node-input-animate" style="display:inline-block; width:auto; vertical-align:baseline;"></span>
  126. </div>
  127. <div class="form-row form-row-custom-icons">
  128. <label for="node-input-onicon" style="text-align:right;"><i class="fa fa-toggle-on"></i> On Icon</label>
  129. <input type="text" id="node-input-onicon" style="width:120px">
  130. <label for="node-input-oncolor" style="width:50px; text-align:right;">Colour</label>
  131. <input type="text" id="node-input-oncolor" style="width:120px">
  132. </div>
  133. <div class="form-row form-row-custom-icons">
  134. <label for="node-input-officon" style="text-align:right;"><i class="fa fa-toggle-off"></i> Off Icon</label>
  135. <input type="text" id="node-input-officon" style="width:120px">
  136. <label for="node-input-offcolor" style="width:50px; text-align:right;">Colour</label>
  137. <input type="text" id="node-input-offcolor" style="width:120px">
  138. </div>
  139. <div class="form-row">
  140. <label style="width:auto" for="node-input-passthru"><i class="fa fa-arrow-right"></i> Pass through <code>msg</code> if payload matches valid state: </label>
  141. <input type="checkbox" checked id="node-input-passthru" style="display:inline-block; width:auto; vertical-align:top;">
  142. </div>
  143. <div class="form-row form-row-decouple">
  144. <label for="node-input-decouple"><i class="fa fa-toggle-on"></i> Indicator</label>
  145. <select id="node-input-decouple" style="display: inline-block; vertical-align: middle; width:70%;">
  146. <option value="false">Switch icon shows state of the output</option>
  147. <option value="true">Switch icon shows state of the input</option>
  148. </select>
  149. </div>
  150. <div class="form-row">
  151. <label style="width:auto" for="node-input-onvalue"><i class="fa fa-envelope-o"></i> When clicked, send:</label>
  152. </div>
  153. <div class="form-row">
  154. <label for="node-input-onvalue" style="padding-left:25px; margin-right:-25px">On Payload</label>
  155. <input type="text" id="node-input-onvalue" style="width:70%">
  156. <input type="hidden" id="node-input-onvalueType">
  157. </div>
  158. <div class="form-row">
  159. <label for="node-input-offvalue" style="padding-left:25px; margin-right:-25px">Off Payload</label>
  160. <input type="text" id="node-input-offvalue" style="width:70%">
  161. <input type="hidden" id="node-input-offvalueType">
  162. </div>
  163. <div class="form-row">
  164. <label for="node-input-topic" style="padding-left:25px; margin-right:-25px">Topic</label>
  165. <input type="text" id="node-input-topic">
  166. <input type="hidden" id="node-input-topicType">
  167. </div>
  168. <div class="form-row">
  169. <label for="node-input-className"><i class="fa fa-code"></i> Class</label>
  170. <input type="text" id="node-input-className" placeholder="Optional CSS class name(s) for widget"/>
  171. </div>
  172. <div class="form-row">
  173. <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
  174. <input type="text" id="node-input-name">
  175. </div>
  176. </script>