/
template.js
54 lines (46 loc) · 1.84 KB
/
template.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
/*
ioBroker.vis template Widget-Set
version: "0.0.1"
Copyright 2020 Author author@mail.com
*/
'use strict';
// add translations for edit mode
$.get( 'adapter/template/words.js', function(script) {
let translation = script.substring(script.indexOf('{'), script.length);
translation = translation.substring(0, translation.lastIndexOf(';'));
$.extend(systemDictionary, JSON.parse(translation));
});
// this code can be placed directly in template.html
vis.binds['template'] = {
version: '0.0.1',
showVersion: function () {
if (vis.binds['template'].version) {
console.log('Version template: ' + vis.binds['template'].version);
vis.binds['template'].version = null;
}
},
createWidget: function (widgetID, view, data, style) {
var $div = $('#' + widgetID);
// if nothing found => wait
if (!$div.length) {
return setTimeout(function () {
vis.binds['template'].createWidget(widgetID, view, data, style);
}, 100);
}
var text = '';
text += 'OID: ' + data.oid + '</div><br>';
text += 'OID value: <span class="myset-value">' + vis.states[data.oid + '.val'] + '</span><br>';
text += 'Color: <span style="color: ' + data.myColor + '">' + data.myColor + '</span><br>';
text += 'extraAttr: ' + data.extraAttr + '<br>';
text += 'Browser instance: ' + vis.instance + '<br>';
text += 'htmlText: <textarea readonly style="width:100%">' + (data.htmlText || '') + '</textarea><br>';
$('#' + widgetID).html(text);
// subscribe on updates of value
if (data.oid) {
vis.states.bind(data.oid + '.val', function (e, newVal, oldVal) {
$div.find('.template-value').html(newVal);
});
}
}
};
vis.binds['template'].showVersion();