2014-06-25 22:36:28 +02:00
|
|
|
<!--
|
2017-01-11 16:24:33 +01:00
|
|
|
Copyright JS Foundation and other contributors, http://js.foundation
|
2014-06-25 22:36:28 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
|
|
|
|
2020-01-24 19:20:14 +01:00
|
|
|
<script type="text/html" data-template-name="trigger">
|
2014-06-25 22:36:28 +02:00
|
|
|
<div class="form-row">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.send" for="node-input-op1"></label>
|
|
|
|
<input type="hidden" id="node-input-op1type">
|
2020-03-15 16:11:19 +01:00
|
|
|
<input style="width:70%" type="text" id="node-input-op1" placeholder="1">
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.then"></label>
|
|
|
|
<select id="node-then-type" style="width:70%;">
|
2015-07-01 23:36:27 +02:00
|
|
|
<option value="block" data-i18n="trigger.wait-reset"></option>
|
|
|
|
<option value="wait" data-i18n="trigger.wait-for"></option>
|
2017-02-07 21:11:34 +01:00
|
|
|
<option value="loop" data-i18n="trigger.wait-loop"></option>
|
2014-06-25 22:36:28 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2017-02-07 21:11:34 +01:00
|
|
|
<div class="form-row node-type-duration">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label></label>
|
|
|
|
<input type="text" id="node-input-duration" style="text-align:end; width:70px !important">
|
|
|
|
<select id="node-input-units" style="width:140px !important">
|
|
|
|
<option value="ms" data-i18n="trigger.duration.ms"></option>
|
|
|
|
<option value="s" data-i18n="trigger.duration.s"></option>
|
|
|
|
<option value="min" data-i18n="trigger.duration.m"></option>
|
|
|
|
<option value="hr" data-i18n="trigger.duration.h"></option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-row node-type-wait">
|
|
|
|
<label></label>
|
2020-03-15 16:11:19 +01:00
|
|
|
<input type="checkbox" id="node-input-extend" style="margin-left:0px; vertical-align:top; width:auto !important;"> <label style="width:auto !important;" for="node-input-extend" data-i18n="trigger.extend"></label>
|
2016-04-24 18:42:24 +02:00
|
|
|
</div>
|
2020-09-29 18:47:09 +02:00
|
|
|
<div class="form-row node-type-override">
|
2020-09-28 22:10:23 +02:00
|
|
|
<label></label>
|
|
|
|
<input type="checkbox" id="node-input-overrideDelay" style="margin-left:0px; vertical-align:top; width:auto !important;"> <label style="width:auto !important;" for="node-input-overrideDelay" data-i18n="trigger.override"></label>
|
|
|
|
</div>
|
2015-07-01 23:36:27 +02:00
|
|
|
<div class="form-row node-type-wait">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.then-send"></label>
|
|
|
|
<input type="hidden" id="node-input-op2type">
|
2020-03-15 16:11:19 +01:00
|
|
|
<input style="width:70%" type="text" id="node-input-op2" placeholder="0">
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
2020-05-16 23:24:29 +02:00
|
|
|
<div class="form-row" id="node-second-output">
|
2020-01-24 19:20:14 +01:00
|
|
|
<label></label>
|
|
|
|
<input type="checkbox" id="node-input-second" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-second" data-i18n="trigger.second"></label>
|
|
|
|
</div>
|
2016-02-04 22:05:15 +01:00
|
|
|
<div class="form-row">
|
2016-07-05 16:38:43 +02:00
|
|
|
<label data-i18n="trigger.label.reset" style="width:auto"></label>
|
|
|
|
<div style="display:inline-block; width:70%;vertical-align:top">
|
|
|
|
<ul>
|
|
|
|
<li data-i18n="trigger.label.resetMessage"></li>
|
|
|
|
<li><span data-i18n="trigger.label.resetPayload"></span> <input type="text" id="node-input-reset" style="width:150px" data-i18n="[placeholder]trigger.label.resetprompt"></li>
|
|
|
|
</ul>
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
2015-07-01 23:36:27 +02:00
|
|
|
<br/>
|
2017-11-17 18:35:18 +01:00
|
|
|
<div class="form-row">
|
|
|
|
<label data-i18n="trigger.for" for="node-input-bytopic"></label>
|
2020-01-30 22:39:34 +01:00
|
|
|
<select id="node-input-bytopic" style="width:120px;">
|
2017-11-17 18:35:18 +01:00
|
|
|
<option value="all" data-i18n="trigger.alltopics"></option>
|
|
|
|
<option value="topic" data-i18n="trigger.bytopics"></option>
|
|
|
|
</select>
|
2020-01-30 23:20:55 +01:00
|
|
|
<span class="form-row" id="node-stream-topic">
|
|
|
|
<input type="text" id="node-input-topic" style="width:46%;"/>
|
2020-01-30 22:39:34 +01:00
|
|
|
</span>
|
2017-11-17 18:35:18 +01:00
|
|
|
</div>
|
2014-06-25 22:36:28 +02:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2016-03-04 11:12:07 +01:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></input>
|
2020-06-05 12:22:38 +02:00
|
|
|
<input type="hidden" id="node-input-outputs" value="1">
|
2014-06-25 22:36:28 +02:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('trigger',{
|
|
|
|
category: 'function',
|
2014-06-26 14:05:34 +02:00
|
|
|
color:"#E6E0F8",
|
2014-06-25 22:36:28 +02:00
|
|
|
defaults: {
|
2020-01-30 22:39:34 +01:00
|
|
|
name: {value:""},
|
2022-02-14 02:40:49 +01:00
|
|
|
op1: {value:"1",
|
2022-04-12 01:09:46 +02:00
|
|
|
label: RED._("node-red:trigger.send"),
|
|
|
|
validate: RED.validators.typedInput("op1type", false)},
|
2022-02-14 02:40:49 +01:00
|
|
|
op2: {value:"0",
|
2022-04-12 01:09:46 +02:00
|
|
|
label: RED._("node-red:trigger.then-send"),
|
|
|
|
validate: RED.validators.typedInput("op2type", false)},
|
2015-03-21 20:27:22 +01:00
|
|
|
op1type: {value:"val"},
|
|
|
|
op2type: {value:"val"},
|
2022-02-14 02:40:49 +01:00
|
|
|
duration: {
|
|
|
|
value:"250", required:true,
|
|
|
|
label:RED._("node-red:trigger.label.duration"),
|
2022-04-12 01:09:46 +02:00
|
|
|
validate:RED.validators.number(false)},
|
2014-06-25 22:36:28 +02:00
|
|
|
extend: {value:"false"},
|
2020-09-28 22:10:23 +02:00
|
|
|
overrideDelay: {value:"false"},
|
2016-02-04 22:05:15 +01:00
|
|
|
units: {value:"ms"},
|
|
|
|
reset: {value:""},
|
2020-01-24 19:20:14 +01:00
|
|
|
bytopic: {value:"all"},
|
2022-02-14 02:40:49 +01:00
|
|
|
topic: {value:"topic", required:true,
|
|
|
|
label:RED._("node-red:trigger.label.topic")},
|
2020-01-31 18:56:06 +01:00
|
|
|
outputs: {value:1}
|
2014-06-25 22:36:28 +02:00
|
|
|
},
|
|
|
|
inputs:1,
|
|
|
|
outputs:1,
|
2019-06-21 13:36:20 +02:00
|
|
|
icon: "trigger.svg",
|
2014-06-25 22:36:28 +02:00
|
|
|
label: function() {
|
|
|
|
if (this.duration > 0) {
|
2015-07-01 23:36:27 +02:00
|
|
|
return this.name|| this._("trigger.label.trigger")+" "+this.duration+this.units;
|
2014-06-25 22:36:28 +02:00
|
|
|
}
|
2017-02-07 21:11:34 +01:00
|
|
|
if (this.duration < 0) {
|
|
|
|
return this.name|| this._("trigger.label.trigger-loop")+" "+(this.duration * -1)+this.units;
|
|
|
|
}
|
2014-06-25 22:36:28 +02:00
|
|
|
else {
|
2015-07-01 23:36:27 +02:00
|
|
|
return this.name|| this._("trigger.label.trigger-block");
|
2014-06-25 22:36:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
2020-01-24 19:20:14 +01:00
|
|
|
var that = this;
|
2020-01-31 18:56:06 +01:00
|
|
|
if (this.topic === undefined) { $("#node-input-topic").val("topic"); }
|
|
|
|
$("#node-input-topic").typedInput({default:'msg',types:['msg']});
|
2020-01-30 22:39:34 +01:00
|
|
|
$("#node-input-bytopic").on("change", function() {
|
|
|
|
if ($("#node-input-bytopic").val() === "all") {
|
2020-01-30 23:20:55 +01:00
|
|
|
$("#node-stream-topic").hide();
|
2020-01-30 22:39:34 +01:00
|
|
|
} else {
|
2020-01-30 23:20:55 +01:00
|
|
|
$("#node-stream-topic").show();
|
2020-01-30 22:39:34 +01:00
|
|
|
}
|
|
|
|
});
|
2020-02-15 02:13:37 +01:00
|
|
|
|
|
|
|
if (this.outputs == 2) { $("#node-input-second").prop('checked', true) }
|
|
|
|
else { $("#node-input-second").prop('checked', false) }
|
2020-09-28 22:10:23 +02:00
|
|
|
|
2020-01-24 19:20:14 +01:00
|
|
|
$("#node-input-second").change(function() {
|
|
|
|
if ($("#node-input-second").is(":checked")) {
|
2020-06-05 12:22:38 +02:00
|
|
|
$("#node-input-outputs").val(2);
|
2020-01-24 19:20:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-06-05 12:22:38 +02:00
|
|
|
$("#node-input-outputs").val(1);
|
2020-01-24 19:20:14 +01:00
|
|
|
}
|
|
|
|
});
|
2019-04-29 12:50:15 +02:00
|
|
|
$("#node-then-type").on("change", function() {
|
2015-07-01 23:36:27 +02:00
|
|
|
if ($(this).val() == "block") {
|
|
|
|
$(".node-type-wait").hide();
|
2020-09-29 18:47:09 +02:00
|
|
|
$(".node-type-override").hide();
|
2017-02-07 21:11:34 +01:00
|
|
|
$(".node-type-duration").hide();
|
2020-05-16 23:24:29 +02:00
|
|
|
$("#node-second-output").hide();
|
|
|
|
$("#node-input-second").prop('checked', false);
|
2020-06-05 12:22:38 +02:00
|
|
|
$("#node-input-outputs").val(1);
|
2017-02-07 21:11:34 +01:00
|
|
|
}
|
|
|
|
else if ($(this).val() == "loop") {
|
2020-03-15 16:11:19 +01:00
|
|
|
if ($("#node-input-duration").val() == 0) { $("#node-input-duration").val(250); }
|
2017-02-07 21:11:34 +01:00
|
|
|
$(".node-type-wait").hide();
|
2020-09-29 18:47:09 +02:00
|
|
|
$(".node-type-override").show();
|
2017-02-07 21:11:34 +01:00
|
|
|
$(".node-type-duration").show();
|
2020-05-16 23:24:29 +02:00
|
|
|
$("#node-second-output").hide();
|
|
|
|
$("#node-input-second").prop('checked', false);
|
2020-06-05 12:22:38 +02:00
|
|
|
$("#node-input-outputs").val(1);
|
2015-07-01 23:36:27 +02:00
|
|
|
} else {
|
2020-03-15 16:11:19 +01:00
|
|
|
if ($("#node-input-duration").val() == 0) { $("#node-input-duration").val(250); }
|
2015-07-01 23:36:27 +02:00
|
|
|
$(".node-type-wait").show();
|
2020-09-29 18:47:09 +02:00
|
|
|
$(".node-type-override").show();
|
2017-02-07 21:11:34 +01:00
|
|
|
$(".node-type-duration").show();
|
2020-05-16 23:24:29 +02:00
|
|
|
$("#node-second-output").show();
|
2015-07-01 23:36:27 +02:00
|
|
|
}
|
|
|
|
});
|
2016-07-05 16:38:43 +02:00
|
|
|
|
|
|
|
if (this.op1type === 'val') {
|
|
|
|
$("#node-input-op1type").val('str');
|
|
|
|
}
|
|
|
|
if (this.op2type === 'val') {
|
|
|
|
$("#node-input-op2type").val('str');
|
|
|
|
}
|
|
|
|
|
|
|
|
var optionNothing = {value:"nul",label:this._("trigger.output.nothing"),hasValue:false};
|
2017-03-06 20:06:10 +01:00
|
|
|
var optionPayload = {value:"pay",label:this._("trigger.output.existing"),hasValue:false};
|
|
|
|
var optionOriginalPayload = {value:"pay",label:this._("trigger.output.original"),hasValue:false};
|
|
|
|
var optionLatestPayload = {value:"payl",label:this._("trigger.output.latest"),hasValue:false};
|
2016-07-05 16:38:43 +02:00
|
|
|
|
|
|
|
$("#node-input-op1").typedInput({
|
|
|
|
default: 'str',
|
|
|
|
typeField: $("#node-input-op1type"),
|
2018-07-19 14:20:02 +02:00
|
|
|
types:['flow','global','str','num','bool','json','bin','date','env',
|
2016-07-05 16:38:43 +02:00
|
|
|
optionPayload,
|
|
|
|
optionNothing
|
|
|
|
]
|
2015-07-01 23:36:27 +02:00
|
|
|
});
|
2016-07-05 16:38:43 +02:00
|
|
|
$("#node-input-op2").typedInput({
|
|
|
|
default: 'str',
|
|
|
|
typeField: $("#node-input-op2type"),
|
2018-07-19 14:20:02 +02:00
|
|
|
types:['flow','global','str','num','bool','json','bin','date','env',
|
2016-07-05 16:38:43 +02:00
|
|
|
optionOriginalPayload,
|
|
|
|
optionLatestPayload,
|
|
|
|
optionNothing
|
|
|
|
]
|
2014-06-25 22:36:28 +02:00
|
|
|
});
|
2016-07-05 16:38:43 +02:00
|
|
|
|
2018-02-01 10:21:16 +01:00
|
|
|
if (this.bytopic === undefined) {
|
|
|
|
$("#node-input-bytopic").val("all");
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:36:27 +02:00
|
|
|
if (this.duration == "0") {
|
|
|
|
$("#node-then-type").val("block");
|
2017-02-07 21:11:34 +01:00
|
|
|
}
|
|
|
|
else if ((this.duration * 1) < 0) {
|
|
|
|
$("#node-then-type").val("loop");
|
2017-07-03 16:17:17 +02:00
|
|
|
$("#node-input-duration").val(this.duration*-1);
|
2015-07-01 23:36:27 +02:00
|
|
|
} else {
|
|
|
|
$("#node-then-type").val("wait");
|
|
|
|
}
|
2019-04-29 12:50:15 +02:00
|
|
|
$("#node-then-type").trigger("change");
|
2015-07-01 23:36:27 +02:00
|
|
|
|
|
|
|
if (this.extend === "true" || this.extend === true) {
|
|
|
|
$("#node-input-extend").prop("checked",true);
|
|
|
|
} else {
|
|
|
|
$("#node-input-extend").prop("checked",false);
|
|
|
|
}
|
2020-09-28 22:10:23 +02:00
|
|
|
if (this.overrideDelay === "true" || this.overrideDelay === true) {
|
|
|
|
$("#node-input-overrideDelay").prop("checked",true);
|
|
|
|
} else {
|
|
|
|
$("#node-input-overrideDelay").prop("checked",false);
|
|
|
|
}
|
2015-07-01 23:36:27 +02:00
|
|
|
},
|
|
|
|
oneditsave: function() {
|
|
|
|
if ($("#node-then-type").val() == "block") {
|
|
|
|
$("#node-input-duration").val("0");
|
|
|
|
}
|
2017-02-07 21:11:34 +01:00
|
|
|
if ($("#node-then-type").val() == "loop") {
|
|
|
|
$("#node-input-duration").val($("#node-input-duration").val() * -1);
|
|
|
|
}
|
2014-06-25 22:36:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|