@tbowmo/node-red-small-timer
Version:
Small timer node for Node-RED with support for sunrise, sunset etc. timers
63 lines (60 loc) • 2.41 kB
HTML
<script type="text/x-red" data-template-name="position">
<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" placeholder="Name" />
</div>
<div class="form-row">
<label></label>
<button type="button" id="getPosition" class="red-ui-button">
Get location from browser
</button>
</div>
<div class="form-row node-config-input-latitude-row">
<label for="node-config-input-latitude"><i class="fa fa-file"></i> latitude</label>
<input type="text" id="node-config-input-latitude" />
</div>
<div class="form-row node-config-input-longitude-row">
<label for="node-config-input-longitude"><i class="fa fa-file"></i> longitude</label>
<input type="text" id="node-config-input-longitude" />
</div>
</script>
<script type="text/x-red" data-help-name="position">
<p>
Configuration node for small-timer
</p>
<h3>Details</h3>
<p>
Stores a latitude / longitude pair for use in small timer, this is used to calculate
sunrise, sunset etc. times for your exact location
</p>
<p>
Use the button <code>Get location from browser</code> to autofill the input fields
with location provided by your browser
</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('position',{
category: 'config',
defaults: {
name: {value: ""},
latitude: {value: "latitude", required: true},
longitude: {value: "longitude", require: true},
},
label: function() {
return `${this.name || this.prefix} (${this.latitude}, ${this.longitude})`
},
oneditprepare: function() {
$('#getPosition').on('click', () => {
navigator.geolocation.getCurrentPosition(function (position) {
$('#node-config-input-latitude').val(Number(position.coords.latitude.toFixed(5)));
$('#node-config-input-longitude').val(Number(position.coords.longitude.toFixed(5)));
});
})
},
oneditsave: function() {
var node = this
node.latitude = $('#node-input-latitude')
node.longitude = $('#node-input-longitude')
}
})
</script>