UNPKG

node-red-contrib-bean

Version:
117 lines (105 loc) 5.38 kB
<!-- Copyright 2014 Punch Throguh Design. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <script type="text/x-red" data-template-name="bean"> <br/> <div class="form-row"> <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-config-input-name" style="width:60%;" placeholder="Name"> <a id="node-config-lookup-bean" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a> </div> <div class="form-row"> <label for="node-config-input-uuid"><i class="fa fa-tag"></i> UUID</label> <input type="text" id="node-config-input-uuid" placeholder="UUID"> </div> <div class="form-row"> <label for="node-config-input-connectiontype"><i class="fa fa-clock-o"></i> Connection</label> <select type="text" id="node-config-input-connectiontype" style="width:77%;"> <option value="timeout">connection on event</option> <option value="constant">constantly connected</option> </select> </div> <div class="form-row" id="node-config-connectiontimeout"> <label for="node-config-input-connectiontimeout"><i class="fa fa-clock-o"></i> Timeout</label> <input type="text" id="node-config-input-connectiontimeout" style="width:52%;" value="60"> <span id="node-units">seconds</span> </div> <div class="form-tips" id="tip-timeout">Tip: the "connnection on event" setting is used when the Bean should only be connected to when a message is sent to it. The Bean will disconnect after "timeout" seconds of innactivity.</div> <script> var previous = null; $("#node-config-input-connectiontype").on('focus', function () { previous = this.value; }).change(function() { if (previous == null) { previous = $("#node-config-input-connectiontype").val(); } if ($("#node-config-input-connectiontype").val() == "timeout") { // TODO: For some reason the previous functionality isn't working and this control isn't being reset to 60 if (previous != "timeout") { $("#node-config-input-connectiontimeout").val("60"); } $("#node-config-connectiontimeout").show(); $("#tip-timeout").show(); } else { if (previous != "constant") { $("#node-config-input-connectiontimeout").val("0"); } $("#node-config-connectiontimeout").hide(); $("#tip-timeout").hide(); } }); </script> </script> <script type="text/javascript"> RED.nodes.registerType('bean',{ category: 'config', // the palette category defaults: { // defines the editable properties of the node name: {value:"", required:true}, // along with default values. uuid: {value:""}, connectiontype: {value:"timeout",required:true}, connectiontimeout: {value:"60",required:true} }, label: function() { // sets the default label contents return this.name||"Bean"; }, labelStyle: function() { // sets the class to apply to the label return this.name?"node_label_italic":""; }, oneditprepare: function() { try { $("#node-config-input-name").autocomplete( "destroy" ); } catch(err) { } $("#node-config-lookup-bean").click(function() { $("#node-config-lookup-bean").addClass('disabled'); $.getJSON('discoveredbeans',function(data) { $("#node-config-lookup-bean").removeClass('disabled'); var beanNames = []; $.each(data, function(i, bean){ beanNames.push({ "label":bean.name, "value":bean.name, "rssi":bean.rssi }); }); $("#node-config-input-name").autocomplete({ source:beanNames, minLength:0, close: function( event, ui ) { $("#node-config-input-name").autocomplete( "destroy" ); } }) .data( "ui-autocomplete" )._renderItem = function( ul, item ) { return $( "<li>" ) .data( "ui-autocomplete-item", item ) .append( "<a>" + item.label + "<span style=\"float:right; color:LightGray;\">RSSI: " + item.rssi + "</span></a>" ) .appendTo( ul ); }; $("#node-config-input-name").autocomplete("search",""); }); }); } }); </script>