@janart19/node-red-fusebox
Version:
A comprehensive collection of custom nodes for interfacing with Fusebox automation controllers - data streams, energy management, and utilities
102 lines (91 loc) • 3.66 kB
HTML
<script type="text/javascript">
RED.nodes.registerType("fusebox-manual-ticker", {
category: "fusebox utils",
color: "#FFF3CD",
icon: "font-awesome/fa-hand-pointer-o",
defaults: {
name: { value: "" },
topic: { value: "heating/tick" },
periodSec: {
value: 1200,
validate: function (v) {
return Number(v) > 0;
}
}
},
inputs: 0,
outputs: 1,
label: function () {
return this.name || `manual ticker`;
},
paletteLabel: "manual ticker",
button: {
onclick: function () {
const node = this;
$.ajax({
url: `fusebox/manual-ticker/${node.id}/inject`,
type: "POST",
success: function (data) {
// Success - tick sent
},
error: function (xhr, status, error) {
RED.notify("Failed to send tick: " + (xhr.responseJSON?.error || error), "error");
}
});
}
},
oneditprepare: function () {
const node = this;
function updateTips() {
const topic = $("#node-input-topic").val() || "heating/tick";
const periodSec = Number($("#node-input-periodSec").val()) || 1200;
const tipText1 = `Sends a tick message to "${topic}" when triggered.`;
const tipText2 = `Payload: {ts: <current_unix_seconds>, periodSec: ${periodSec}}`;
$("#node-input-tip-text-1").text(tipText1);
$("#node-input-tip-text-2").text(tipText2);
}
$("#node-input-topic").on("change input", updateTips);
$("#node-input-periodSec").on("change input", updateTips);
updateTips();
}
});
</script>
<!-- Define style for the form fields -->
<style type="text/css">
.manual-ticker-div .form-row {
margin-bottom: 10px;
}
.manual-ticker-div .form-row label {
width: 33% ;
vertical-align: middle;
}
.manual-ticker-div .form-row div,
.manual-ticker-div .form-row input,
.manual-ticker-div .form-row textarea {
max-width: 66% ;
}
.manual-ticker-div .form-tips {
margin-top: 5px;
margin-bottom: 10px;
font-size: 11px;
color: #666;
text-align: center;
}
</style>
<!-- Node configuration form template -->
<script type="text/html" data-template-name="fusebox-manual-ticker">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="e.g. Manual tick" />
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-topic"></i> Output topic</label>
<input type="text" id="node-input-topic" placeholder="e.g. heating/tick" />
</div>
<div class="form-tips" id="node-input-tip-text-1">Sends a tick message to the configured topic when triggered.</div>
<div class="form-row">
<label for="node-input-periodSec"><i class="fa fa-clock-o"></i> Period (seconds)</label>
<input type="number" id="node-input-periodSec" min="1" step="1" placeholder="1200" />
</div>
<div class="form-tips" id="node-input-tip-text-2">Period value included in the tick payload.</div>
</script>