@thingweb/node-red-node-wot
Version:
Web of Things nodes for Node-RED using node-wot
90 lines (84 loc) • 3.56 kB
HTML
<script type="text/javascript">
;(() => {
const BINDING_TYPE_LIST = ["http", "websocket", "coap", "mqtt"]
const BINDING_CONFIG_DEFAULT = {
http: {
port: 8080,
allowSelfSigned: true,
},
websocket: {
port: 9090,
allowSelfSigned: true,
},
coap: {
port: 5683,
},
mqtt: {
uri: "mqtt://test.mosquitto.org",
},
}
RED.nodes.registerType("wot-server-config", {
category: "config",
defaults: {
name: { value: "", required: true },
bindingType: { value: "http", required: true },
bindingConfigType: { value: "json", required: true },
bindingConfigConstValue: { value: "{}", required: true },
},
label: function () {
return this.name || this._("editor.configLabel")
},
labelStyle: function () {
return this.name ? "node_label_italic" : ""
},
oneditprepare: function () {
// 入力パラメータの指定項目作成
$("#node-config-input-bindingConfigConstValue").typedInput({
defaultType: "json",
defaultValue: "{}",
types: ["json"],
typeField: "#node-config-input-bindingConfigType",
})
BINDING_TYPE_LIST.forEach((type) => {
$("#node-config-input-bindingType").append(`<option value="${type}">${type}</option>`)
})
$("#node-config-input-bindingType").val(this.bindingType)
$("#node-config-input-bindingType").on("change", () => {
const selectedBindingType = $("#node-config-input-bindingType").val()
if (selectedBindingType === this.bindingType && this.bindingConfigConstValue !== "{}") {
$("#node-config-input-bindingConfigConstValue").typedInput(
"value",
this.bindingConfigConstValue
)
} else {
$("#node-config-input-bindingConfigConstValue").typedInput(
"value",
JSON.stringify(BINDING_CONFIG_DEFAULT[selectedBindingType])
)
}
})
},
})
})()
</script>
<script type="text/html" data-template-name="wot-server-config">
<div class="form-row">
<label for="node-config-input-name"><span data-i18n="editor.nameLabel"></span></label>
<input type="text" id="node-config-input-name" data-i18n="[placeholder]editor.nameLabel" />
</div>
<div class="form-row">
<label for="node-config-input-bindingType"><span data-i18n="editor.bindingTypeLabel"></span></label>
<select id="node-config-input-bindingType"></select>
</div>
<div class="form-row">
<label for="node-config-input-bindingConfigConstValue"
><span data-i18n="editor.bindingConfigLabel"></span
></label>
<input
type="text"
id="node-config-input-bindingConfigConstValue"
data-i18n="[placeholder]editor.bindingConfigPlaceholder"
/>
<input type="hidden" id="node-config-input-bindingConfigType" />
</div>
</script>