-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebthingsio-get-property.html
89 lines (85 loc) · 3.9 KB
/
webthingsio-get-property.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<script type="text/javascript">
RED.nodes.registerType('webthingsio-get-property', {
category: 'Web Things IO',
color: '#5d9bc7',
defaults: {
/* eslint-disable no-undefined */
name: {value: ''},
gateway: {value: '', type: 'webthingsio-gateway', required: true},
thing: {value: undefined, validate: (v) => v ? true : false},
property: {value: undefined, validate: (v) => v ? true : false},
},
inputs: 1,
outputs: 1,
icon: 'webthingsio.svg',
label: function() {
if (this.name) {
return this.name;
} else if (this.gateway && this.thing && this.property) {
const decodedThing = decodeURIComponent(this.thing);
if (RED.settings.webthingsioGatewayShorterLabels) {
return this._('webthingsio-get-property.shortLabel')
.replace('%property', this.property)
.replace('%thing', decodedThing);
} else {
return this._('webthingsio-get-property.longLabel')
.replace('%property', this.property)
.replace('%thing', decodedThing);
}
}
return this._('webthingsio-get-property.defaultLabel');
},
paletteLabel: 'Get property',
oneditprepare: async function() {
async function initializeInputs(node) {
if (
$('#node-input-gateway')[0].options.length > 1 &&
!node.gateway
) {
$('#node-input-gateway')[0].selectedIndex = 0;
$('#node-input-gateway').removeClass('input-error');
}
await webthingsio.updateThing(false);
$('#node-input--thing').prop('value', node.thing);
await webthingsio.updateProperty(false, false, true);
$('#node-input--property').prop('value', node.property);
}
function addListeners() {
$('#node-input-gateway')[0].addEventListener(
'change',
() => webthingsio.updateThing(),
);
$('#node-input--thing')[0].addEventListener(
'change',
() => webthingsio.updateProperty(true, false, true),
);
}
await initializeInputs(this);
addListeners();
},
oneditsave: function() {
webthingsio.saveThing(this);
webthingsio.saveProperty(this);
},
});
</script>
<script type="text/html" data-template-name="webthingsio-get-property">
<div class="form-row" id="node-errorGatewayConnect" data-i18n="webthingsio-get-property.errorGatewayConnect" style="display: none; color: red;">
</div>
<div class="form-row">
<label for="node-input-name" data-i18n="webthingsio-get-property.labelName"><i class="fa fa-tag"></i></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]webthingsio-get-property.placeholderName">
</div>
<div class="form-row">
<label for="node-input-gateway" data-i18n="webthingsio-get-property.labelGateway"><i class="fa fa-tag"></i></label>
<input type="text" id="node-input-gateway">
</div>
<div class="form-row" id="thing-row" style="display: none;">
<label for="node-input--thing" data-i18n="webthingsio-get-property.labelThing"><i class="fa fa-tag"></i></label>
<select id="node-input--thing" style="width: 70%;"></select>
</div>
<div class="form-row" id="property-row" style="display: none;">
<label for="node-input--property" data-i18n="webthingsio-get-property.labelProperty"><i class="fa fa-tag"></i></label>
<select id="node-input--property" style="width: 70%;"></select>
</div>
</script>