UNPKG

node-red-dashboard

Version:
114 lines (111 loc) 5.77 kB
<script type="text/javascript"> RED.nodes.registerType('ui_button',{ category: 'dashboard', color: 'rgb(176, 223, 227)', defaults: { name: {value: ''}, group: {type: 'ui_group', required: true}, order: {value: 0}, width: {value: 0, validate: function(v) { var width = v||0; var currentGroup = $('#node-input-group').val()||this.group; var groupNode = RED.nodes.node(currentGroup); var valid = !groupNode || +width <= +groupNode.width; $("#node-input-size").toggleClass("input-error",!valid); return valid; } }, height: {value: 0}, passthru: {value: false}, label: {value: 'button'}, color: {value: ''}, bgcolor: {value: ''}, icon: {value: ''}, payload: {value: '',validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('payloadType'):function(v) { return true})}, payloadType: { value: 'str'}, topic: {value: ''} }, inputs:1, outputs:1, icon: "ui_button.png", paletteLabel: 'button', label: function() { return this.name || (~this.label.indexOf("{{") ? null : this.label) || 'button'; }, oneditprepare: function() { $("#node-input-size").elementSizer({ width: "#node-input-width", height: "#node-input-height", group: "#node-input-group" }); $('#node-input-payload').typedInput({ default: 'str', typeField: $("#node-input-payloadType"), types:['str','num','bool','json','bin','date'] }) } }); </script> <script type="text/x-red" data-template-name="ui_button"> <div class="form-row"> <label for="node-input-group"><i class="fa fa-table"></i> Group</label> <input type="text" id="node-input-group"> </div> <div class="form-row"> <label><i class="fa fa-object-group"></i> Size</label> <input type="hidden" id="node-input-width"> <input type="hidden" id="node-input-height"> <button class="editor-button" id="node-input-size"></button> </div> <div class="form-row"> <label for="node-input-icon"><i class="fa fa-picture-o"></i> Icon</label> <input type="text" id="node-input-icon" placeholder="optional icon "> </div> <div class="form-row"> <label for="node-input-label"><i class="fa fa-i-cursor"></i> Label</label> <input type="text" id="node-input-label" placeholder="optional label"> </div> <div class="form-row"> <label for="node-input-color"><i class="fa fa-tint"></i> Colour</label> <input type="text" id="node-input-color" placeholder="optional text/icon color"> </div> <div class="form-row"> <label for="node-input-bgcolor"><i class="fa fa-tint"></i> Background</label> <input type="text" id="node-input-bgcolor" placeholder="optional background color"> </div> <div class="form-row"> <label style="width:auto" for="node-input-payload"><i class="fa fa-envelope-o"></i> When clicked, send:</label> </div> <div class="form-row"> <label for="node-input-payload" style="padding-left: 25px; margin-right: -25px">Payload</label> <input type="text" id="node-input-payload" style="width:70%"> <input type="hidden" id="node-input-payloadType"> </div> <div class="form-row"> <label for="node-input-topic" style="padding-left: 25px; margin-right: -25px">Topic</label> <input type="text" id="node-input-topic"> </div> <div class="form-row"> <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> <input type="checkbox" id="node-input-passthru" style="display:inline-block; width:auto; vertical-align:top;"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name"> </div> </script> <script type="text/x-red" data-help-name="ui_button"> <p>Adds a button to the user interface.</p> <p>Clicking the button generates a message with <code>msg.payload</code> set to the <b>Payload</b> field. If no payload is specified, the node id is used.</p> <p>The <b>Size</b> defaults to 3 by 1.</p> <p>The <b>Icon</b> can be defined, as either a <a href="https://design.google.com/icons/" target="_blank">Material Design icon</a> <i>(e.g. 'check', 'close')</i> or a <a href="https://fontawesome.com/v4.7.0/icons/" target="_blank">Font Awesome icon</a> <i>(e.g. 'fa-fire')</i>, or a <a href="https://github.com/Paul-Reed/weather-icons-lite/blob/master/css/weather-icons-lite.css">Weather icon</a>.</p> <p>The colours of the text and background may be set. They can also be set by a message property by setting the field to the name of the property, for example <code>{{msg.background}}</code>.</p> <p>The label can also be set by a message property by setting the field to the name of the property, for example <code>{{msg.topic}}</code>.</p> <p>If set to pass through mode a message arriving on the input will act like pressing the button. The output payload will be as defined in the node configuration.</p> <p>The <b>Topic</b> field can be used to set the <code>msg.topic</code> property that is output.</p> <p>Setting <code>msg.enabled</code> to <code>false</code> will disable the button.</p> </script>