smart-nodes
Version:
225 lines (208 loc) • 8.83 kB
HTML
<script type="text/javascript">
RED.nodes.registerType("smart_logic", {
category: "Smart Nodes",
paletteLabel: "Binary Logic",
color: "#E2D96E",
defaults: {
name: { value: "" },
logic: { value: "AND" }, // OR XAND XOR
logic_inputs: { value: 2 },
inverts: { value: "" },
invert_output: { value: false },
out_false: { value: '{"topic": ""}' },
out_false_type: { value: 'json' },
out_true: { value: '{"topic": ""}' },
out_true_type: { value: 'json' },
send_only_change: { value: true },
outputs: { value: 1 },
save_state: { value: false },
resend_on_start: { value: false }
},
inputs: 1,
outputs: 1,
icon: "serial.svg",
label: function ()
{
return this.name || this.logic || "Binary Logic";
},
outputLabels: function (index)
{
return this.outputs == 1 ? "" : ["Wahr", "Falsch"][index];
},
oneditprepare: function ()
{
let node = this;
$("#node-input-logic")
.css("max-width", "70%")
.typedInput({
types: [{
value: "logic",
default: "AND",
options: [
{ value: "AND", label: "AND" },
{ value: "OR", label: "OR" },
{ value: "XOR", label: "XOR" }
],
}],
});
$("#node-input-logic_inputs")
.css("max-width", "4rem")
.spinner({
min: 1,
change: function (event, ui)
{
var value = parseInt(this.value);
value = isNaN(value) ? 0 : value;
value = Math.max(value, parseInt($(this).attr("aria-valuemin")));
// value = Math.min(value, parseInt($(this).attr("aria-valuemax")));
if (value !== this.value)
$(this).spinner("value", value);
refreshInverts(value);
},
});
$("#node-input-inverts")
.css("max-width", "70%")
.typedInput({
types: [{
value: "inverts",
multiple: true,
options: []
}],
});
refreshInverts(this.logic_inputs);
$("#node-input-inverts").typedInput("value", this.inverts);
$("#node-input-out_true")
.css("max-width", "70%")
.typedInput({
type: "json",
types: ["json", {
value: "NOTHING",
label: node._("logic.ui.send_nothing"),
icon: "fa fa-times",
hasValue: false,
}],
typeField: "#node-input-out_true_type"
});
$("#node-input-out_false")
.css("max-width", "70%")
.typedInput({
type: "json",
types: ["json", {
value: "NOTING",
label: node._("logic.ui.send_nothing"),
icon: "fa fa-times",
hasValue: false,
}],
typeField: "#node-input-out_false_type"
});
$("#node-input-send_only_change")
.css("max-width", "70%")
.typedInput({
type: "bool",
types: [{
value: "send_only_change",
options: [
{ value: "true", label: node._("logic.ui.send_only_change") },
{ value: "false", label: node._("logic.ui.always") },
]
}]
});
$("#node-input-outputs")
.css("max-width", "70%")
.typedInput({
type: "num",
types: [{
value: "outputs",
options: [
{ value: "1", label: node._("logic.ui.common_output") },
{ value: "2", label: node._("logic.ui.separate_output") },
]
}]
});
$("#node-input-save_state").on("change", ev =>
{
if (ev.target.checked)
$("#resend_on_start_row").show();
else
$("#resend_on_start_row").hide();
});
$("#node-input-save_state").trigger("change");
}
});
let refreshInverts = inputs =>
{
let options = [];
let oldValues = $("#node-input-inverts").typedInput("value").split(",");
let newValues = [];
for (let i = 1; i <= inputs; i++)
{
options.push({ value: "" + i, label: "Eingang " + i });
if (oldValues.includes("" + i))
newValues.push("" + i);
}
$("#node-input-inverts")
.typedInput("types", [{
value: "inverts",
multiple: true,
options: options
}]);
$("#node-input-inverts").typedInput("value", newValues.join(","));
}
</script>
<script type="text/html" data-template-name="smart_logic">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="logic.ui.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]logic.ui.name" />
</div>
<div class="form-row">
<label for="node-input-logic"><i class="fa fa-microchip"></i> <span data-i18n="logic.ui.logic"></span></label>
<input id="node-input-logic" />
</div>
<div class="form-row">
<label for="node-input-logic_inputs"><i class="fa fa-hashtag"></i> <span data-i18n="logic.ui.inputs"></span></label>
<input id="node-input-logic_inputs" />
</div>
<div class="form-row">
<label for="node-input-inverts"><i class="fa fa-circle-o"></i> <span data-i18n="logic.ui.invert"></span></label>
<input id="node-input-inverts" />
</div>
<div class="form-row">
<label for="node-input-invert_output"><i class="fa fa-circle-o"></i> <span data-i18n="logic.ui.output"></span></label>
<input type="checkbox" id="node-input-invert_output" style="width: unset; margin: 0;" />
<label for="node-input-invert_output" data-i18n="logic.ui.invert"></label>
</div>
<hr/>
<h4 style="margin: 0.5rem 0;" data-i18n="logic.ui.output_messages"></h4>
<div class="form-row">
<label for="node-input-out_true"><i class="fa fa-check-circle"></i> <span data-i18n="logic.ui.true"></span></label>
<input type="text" id="node-input-out_true"/>
<input type="hidden" id="node-input-out_true_type">
</div>
<div class="form-row">
<label for="node-input-out_false"><i class="fa fa-times-circle"></i> <span data-i18n="logic.ui.false"></span></label>
<input type="text" id="node-input-out_false" />
<input type="hidden" id="node-input-out_false_type">
</div>
<div class="form-row">
<label for="node-input-send_only_change"><i class="fa fa-repeat"></i> <span data-i18n="logic.ui.send"></span></label>
<input id="node-input-send_only_change" />
</div>
<div class="form-row">
<label for="node-input-outputs"><i class="fa fa-hashtag"></i> <span data-i18n="logic.ui.outputs"></span></label>
<input id="node-input-outputs" />
</div>
<div class="form-row">
<div><strong data-i18n="logic.ui.note"></strong></div>
<div data-i18n="[html]logic.ui.note_text"></div>
</div>
<hr/>
<h4 style="margin: 0.5rem 0;" data-i18n="logic.ui.system_start"></h4>
<div class="form-row">
<input type="checkbox" id="node-input-save_state" style="width: 20px;" />
<label for="node-input-save_state" style="width: calc(100% - 30px);" data-i18n="logic.ui.save_state"></label>
</div>
<div class="form-row" id="resend_on_start_row">
<input type="checkbox" id="node-input-resend_on_start" style="width: 20px;" />
<label for="node-input-resend_on_start" style="width: calc(100% - 30px);" data-i18n="logic.ui.send_after_start"></label>
</div>
</script>