-
Notifications
You must be signed in to change notification settings - Fork 1
/
mmg2-maintained-list.html
203 lines (166 loc) · 4.54 KB
/
mmg2-maintained-list.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<script type="text/javascript">
const
DATA_SET_OPTIONS = [
{
value: 3,
label: "Sites",
idField: "locationID",
nameField: "locationName"
},
{
value: 4,
label: "Locations",
idField: "locationID",
nameField: "locationName"
},
{
value: 11,
label: "Alarms"
},
{
value: 13,
label: "Control Instructions"
},
{
value: 101,
label: "Device Types (Static)",
idField: "deviceTypeID",
nameField: "deviceTypeName"
},
{
value: 102,
label: "Service Classifications (Static)",
idField: "serviceClassID",
nameField: "name"
}
],
OUTPUT_FORMATS = [
{ value: 1, label: "Raw" },
{ value: 2, label: "FlexDash Simple Table" },
{ value: 3, label: "FlexDash Dropdown Select" }
],
getDataSetProperties = (id) => {
for (let a = 0; a < DATA_SET_OPTIONS.length; a += 1) {
if (DATA_SET_OPTIONS[a].value === parseInt(id)) {
return DATA_SET_OPTIONS[a];
}
}
return null;
},
getFormatName = (id) => {
for (let a = 0; a < OUTPUT_FORMATS.length; a += 1) {
if (OUTPUT_FORMATS[a].value === parseInt(id)) {
return OUTPUT_FORMATS[a].label;
}
}
return null;
};
RED.nodes.registerType(
"mmg2-maintained-list",
{
category: "MMG2",
color: "#299FD3",
defaults: {
connection: {
value: "",
type: "mmg2-connector",
required: true
},
dataset: {
value: 4,
required: true
},
format: {
value: 1,
required: true,
validate: (x) => {
if (x.value > 1) {
return !!getDataSetProperties(parseInt($("#node-input-dataset").val())).idField;
}
return true;
}
},
deviceTypeID: {
value: ""
},
locationID: {
value: 0
},
serviceClassID: {
value: undefined
}
},
inputs: 1,
outputs: 1,
icon: "white-globe.svg",
label: function() {
return "List: " + getDataSetProperties(this.dataset).label;
},
oneditprepare: () => {
let el = $("#node-input-dataset");
el.typedInput({
types: [
{
value: "dataset",
options: DATA_SET_OPTIONS
}
]
});
el.on("change", () => {
let id = parseInt(el.val());
$("#node-input-deviceTypeID").prop("disabled", (id !== 4) || (id > 100));
$("#node-input-serviceClassID").prop("disabled", (id !== 4) || (id > 100));
$("#node-input-locationID").prop("disabled", (id === 3) || (id > 100));
});
el = $("#node-input-format");
el.typedInput({
types: [
{
value: "Format",
options: OUTPUT_FORMATS
}
]
});
el.on("change", () => {
let id = parseInt(el.val());
$("#node-input-deviceTypeID").prop("disabled", (id !== 4) || (id > 100));
$("#node-input-serviceClassID").prop("disabled", (id !== 4) || (id > 100));
$("#node-input-locationID").prop("disabled", (id === 3) || (id > 100));
});
}
}
);
</script>
<script type="text/html" data-template-name="mmg2-maintained-list">
<div class="form-row">
<label for="node-input-connection"><i class="fa fa-tag"></i>Connection</label>
<input id="node-input-connection">
</div>
<div class="form-row">
<label for="node-input-dataset"><i class="fa fa-tag"></i>Type</label>
<input type="text" id="node-input-dataset">
</div>
<div class="form-row">
<label for="node-input-format"><i class="fa fa-tag"></i>Format</label>
<input type="text" id="node-input-format">
</div>
<p>New format needed? Let us know.</p>
<div class="form-row">
<label for="node-input-locationID"><i class="fa fa-tag"></i>locationID</label>
<input type="text" id="node-input-locationID" placeholder="locationID">
</div>
<p>Parent location. Override by setting msg.locationID</p>
<div class="form-row">
<label for="node-input-deviceTypeID"><i class="fa fa-tag"></i>deviceTypeID</label>
<input type="text" id="node-input-deviceTypeID" placeholder="Device Type Identifier">
</div>
<p>Restrict to devices of type. Override by setting msg.deviceTypeID</p>
<div class="form-row">
<label for="node-input-serviceClassID"><i class="fa fa-tag"></i>serviceClassID</label>
<input type="text" id="node-input-serviceClassID" placeholder="Service Classification ID">
</div>
<p>Restict to locations providing a particular service type. Override by setting msg.serviceClassID</p>
</script>
<script type="text/html" data-help-name="mmg2-maintained-list">
<p>A simple node that maintains a list of entities.</p>
</script>