UNPKG

smart-nodes

Version:

Controls light, shutters and more. Includes common used logic and statistic nodes to control your home.

220 lines (204 loc) 9 kB
<script type="text/javascript"> RED.nodes.registerType("smart_compare", { category: "Smart Nodes", paletteLabel: "Compare", color: "#E2D96E", defaults: { name: { value: "" }, comparator: { value: "EQUAL" }, // EQUAL, GREATER, GREATER_EQUAL, SMALLER, SMALLER_EQUAL, UNEQUAL value1: { value: "" }, value1_type: { value: "NOTHING" }, value2: { value: "" }, value2_type: { value: "NOTHING" }, 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: "font-awesome/fa-sort", label: function () { return this.name || this.comparator || "Compare"; }, outputLabels: function (index) { return this.outputs == 1 ? "" : ["Wahr", "Falsch"][index]; }, oneditprepare: function () { let node = this; $("#node-input-comparator") .css("max-width", "70%") .typedInput({ types: [{ default: "EQUAL", value: "comperator", options: [ { value: "SMALLER", label: node._("compare.ui.smaller") }, { value: "SMALLER_EQUAL", label: node._("compare.ui.smaller_equal") }, { value: "EQUAL", label: node._("compare.ui.equal") }, { value: "UNEQUAL", label: node._("compare.ui.unequal") }, { value: "GREATER_EQUAL", label: node._("compare.ui.greater_equal") }, { value: "GREATER", label: node._("compare.ui.greater") }, ], }], }); $("#node-input-value1") .css("max-width", "70%") .typedInput({ type: "num", types: ["str", "num", "bool", { value: "NOTHING", label: node._("compare.ui.no_value"), icon: "fa fa-times", hasValue: false, }], typeField: "#node-input-value1_type" }); $("#node-input-value2") .css("max-width", "70%") .typedInput({ type: "num", types: ["str", "num", "bool", { value: "NOTHING", label: node._("compare.ui.no_value"), icon: "fa fa-times", hasValue: false, }], typeField: "#node-input-value2_type" }); $("#node-input-out_true") .css("max-width", "70%") .typedInput({ type: "json", types: ["json", { value: "NOTHING", label: node._("compare.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: "NOTHING", label: node._("compare.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: "1", value: "send_only_change", options: [ { value: "true", label: node._("compare.ui.send_only_change") }, { value: "false", label: node._("compare.ui.always") }, ] }] }); $("#node-input-outputs") .css("max-width", "70%") .typedInput({ type: "num", types: [{ value: "1", value: "outputs", options: [ { value: "1", label: node._("compare.ui.common_output") }, { value: "2", label: node._("compare.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"); // Backward compatibility if (this.value1_type == "null") { this.value1_type = "NOTHING"; $("#node-input-value1_type").val("NOTHING"); } if (this.value2_type == "null") { this.value2_type = "NOTHING"; $("#node-input-value2_type").val("NOTHING"); } }, }); </script> <script type="text/html" data-template-name="smart_compare"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="compare.ui.name"></span></label> <input type="text" id="node-input-name" data-i18n="[placeholder]compare.ui.name"/> </div> <div class="form-row"> <label for="node-input-comparator"><i class="fa fa-sort"></i> <span data-i18n="compare.ui.compare"></span></label> <input id="node-input-comparator" /> </div> <div class="form-row" style="max-width: 28rem"> <span data-i18n="compare.ui.note_default_values"></span> </div> <div class="form-row"> <label for="node-input-value1"><i class="fa fa-hashtag"></i> <span data-i18n="compare.ui.value_1"></span></label> <input type="text" id="node-input-value1"> <input type="hidden" id="node-input-value1_type"> </div> <div class="form-row"> <label for="node-input-value2"><i class="fa fa-hashtag"></i> <span data-i18n="compare.ui.value_2"></span></label> <input type="text" id="node-input-value2"/> <input type="hidden" id="node-input-value2_type"> </div> <hr/> <h4 style="margin: 0.5rem 0;"><span data-i18n="compare.ui.output_messages"></span></h4> <div class="form-row"> <label for="node-input-out_true"><i class="fa fa-check-circle"></i> <span data-i18n="compare.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="compare.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="compare.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="compare.ui.outputs"></span></label> <input id="node-input-outputs" /> </div> <div class="form-row" style="max-width: 28rem"> <div><strong data-i18n="compare.ui.note"></strong></div> <div data-i18n="[html]compare.ui.note_text"></div> </div> <hr/> <h4 style="margin: 0.5rem 0;"><span data-i18n="compare.ui.system_start"></span></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);"><span data-i18n="compare.ui.save_state"></span></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);"><span data-i18n="compare.ui.send_after_start"></span></label> </div> </script>