-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsbwUtility.js
59 lines (50 loc) · 1.82 KB
/
sbwUtility.js
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
function core_Debug_HTML(line,sbw) {
var html = String.raw`
<script id="StatusBar` + sbw.Id+sbw.Type + `" type="text/javascript">
if (typeof nrStatusBar !== 'undefined') {
` + line + `;
} else {
console.log("StatusbarWidget: nrStatusBar undefined" + '` + sbw.Type + sbw.Id + `' );
}
</script>
`;
return html;
};
function core_HTML(line,sbw) {
var html = String.raw`<script id="StatusBar` + sbw.Id+sbw.Type + `" type="text/javascript">` + line + `;</script>`;
return html;
};
function create_HTML(msg) {
var line = "nrStatusBar.create(\"" + msg.sbw.Type + "\",\"" + msg.sbw.Id + "\"," + msg.sbw.Options + ")";
return core_HTML(line,msg.sbw)
};
function update_HTML(msg) {
var msgp = "";
if ( typeof msg.payload === "object") {
msgp = JSON.stringify(msg.payload);
} else if ( typeof msg.payload === "string") {
msgp = "\"" + msg.payload + "\"";
}
var line = "nrStatusBar.update(\"" + msg.sbw.Type + "\",\"" + msg.sbw.Id + "\"," + msgp + ")";
return core_HTML(line,msg.sbw)
};
function print_HTML(msg) {
var line = "nrStatusBar.print()";
return core_HTML(line,msg.sbw)
};
module.exports = {
createTemplate: function (msg, node, RED) {
if (msg.topic === "update") {
msg.template = update_HTML(msg);
} else if ( msg.topic === "create") {
msg.template = create_HTML(msg);
} else if ( msg.topic === "print") {
msg.template = print_HTML(msg);
} else {
// default is update template
msg.template = update_HTML(msg);
}
//console.log("sbwUtility cerateTemplate:\n" + msg.template);
return msg.template;
}
};