1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Improve inject node payload options

This commit is contained in:
Nick O'Leary 2014-02-02 15:37:34 +00:00
parent d52cd1ce00
commit c47c72cf48
2 changed files with 39 additions and 4 deletions

View File

@ -16,7 +16,15 @@
<script type="text/x-red" data-template-name="inject">
<div class="form-row node-input-payload">
<label for="node-input-payload"><i class="icon-envelope"></i> Payload</label>
<label for="node-input-payloadType"><i class="icon-envelope"></i> Payload</label>
<select id="node-input-payloadType" style="width:125px !important">
<option value="date">timestamp</option>
<option value="none">blank</option>
<option value="string">string</option>
</select>
</div>
<div class="form-row" id="node-input-row-payload">
<label for="node-input-payload"></label>
<input type="text" id="node-input-payload" placeholder="Payload">
</div>
@ -61,7 +69,6 @@
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips">Tip: Injects Date.now() if no payload set</div>
<script>
{
@ -187,6 +194,7 @@
name: {value:""},
topic: {value:""},
payload: {value:""},
payloadType: {value:"date"},
repeat: {value:""},
crontab: {value:""},
once: {value:false}
@ -277,6 +285,24 @@
$(".inject-time-row").hide();
$("#inject-time-type-select option").filter(function() {return $(this).val() == repeattype;}).attr('selected',true);
$("#inject-time-row-"+repeattype).show();
if (this.payloadType == null) {
if (this.payload == "") {
this.payloadType = "date";
} else {
this.payloadType = "string";
}
}
$("#node-input-payloadType").change(function() {
var id = $("#node-input-payloadType option:selected").val();
if (id == "string") {
$("#node-input-row-payload").show();
} else {
$("#node-input-row-payload").hide();
}
});
$("#node-input-payloadType").val(this.payloadType);
},

View File

@ -25,6 +25,7 @@ function InjectNode(n) {
RED.nodes.createNode(this,n);
this.topic = n.topic;
this.payload = n.payload;
this.payloadType = n.payloadType;
this.repeat = n.repeat;
this.crontab = n.crontab;
this.once = n.once;
@ -56,8 +57,16 @@ function InjectNode(n) {
}
this.on("input",function(msg) {
var msg = {topic:this.topic,payload:this.payload};
if (msg.payload == "") { msg.payload = Date.now(); }
var msg = {topic:this.topic};
console.log(this.payloadType);
console.log(this.payload);
if ( (this.payloadType == null && this.payload == "") || this.payloadType == "date") {
msg.payload = Date.now();
} else if (this.payloadType == null || this.payloadType == "string") {
msg.payload = this.payload;
} else {
msg.payload = "";
}
this.send(msg);
msg = null;
});