UNPKG

node-red-contrib-wio-seeed

Version:
89 lines (83 loc) 2.89 kB
<script type="text/javascript"> RED.nodes.registerType('wio-sensor', { paletteLabel: 'sensor', category: 'wio', color: '#C0EDC0', defaults: { name: { value: '' }, connection: { type: 'wio-config' }, node: { value: '' }, port: { value: '' }, method: { value: '' }, output: { value: 'value' } }, inputs: 1, outputs: 1, icon: 'feed.png', label: function () { return this.name || 'sensor'; }, oneditprepare: function () { var config = this; $.getJSON('wio-modules').done(function (skus) { $.getScript('wio-common').done(function (res) { WioCommon(config, skus); var ports = $('#node-input-port'); var modules = $('#node-input-module'); var methods = $('#node-input-method'); popModuleMethods(); ports.on('change', function () { popModuleMethods(ports.find('option:selected').attr('data-wio-sku')); }); function popModuleMethods(sku) { methods.html(''); if ((skus.hasOwnProperty(sku)) && (skus[sku].methods)) for (method in skus[sku].methods) $('<option/>') .attr('value', method + ((skus[sku].methods[method].value) ? ':' + skus[sku].methods[method].value : '')) .text(skus[sku].methods[method].name) .appendTo(methods); if ((config.method) && (methods.find('option[value="' + config.method + '"]').length)) methods.val(config.method); if (!methods.find('option').length) $('<option/>') .text('--No compatible methods found--') .appendTo(methods); } }); }); } }); </script> <script type="text/x-red" data-template-name="wio-sensor"> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-connection"><i class="icon-tag"></i> Connection</label> <select type="text" id="node-input-connection"></select> </div> <div class="form-row"> <label for="node-input-node"><i class="icon-tag"></i> Node</label> <select type="text" id="node-input-node"></select> </div> <div class="form-row"> <label for="node-input-port"><i class="icon-tag"></i> Port</label> <select type="text" id="node-input-port"></select> </div> <div class="form-row"> <label for="node-input-method"><i class="icon-tag"></i> Method</label> <select type="text" id="node-input-method"></select> </div> <div class="form-row"> <label for="node-input-output"><i class="icon-tag"></i> Output</label> <select type="text" id="node-input-output"> <option value="value">Parsed Value</option> <option value="object">Raw Object</option> </select> </div> </script> <script type="text/x-red" data-help-name="wio-sensor"> <p>Wio Sensor</p> </script>