switch: rename show_values to showValues and clean

This commit is contained in:
jean-emmanuel 2018-01-04 14:45:03 +01:00
parent 040c462ae8
commit c544a37434

View file

@ -27,7 +27,7 @@ module.exports = class Switch extends _widgets_base {
_switch:'switch',
horizontal:false,
show_values:false,
showValues:false,
values:{"Value 1":1,"Value 2":2},
value:'',
@ -51,10 +51,17 @@ module.exports = class Switch extends _widgets_base {
this.values = []
var isArray = Array.isArray(this.getProp('values'))
for (var k in this.getProp('values')) {
this.values.push(this.getProp('values')[k])
var the_val = (this.getProp('show_values')) ? ': ' + this.getProp('values')[k] : ''
$(`<div class="value">${iconify(parseFloat(k) != k ? k : this.getProp("values")[k]) + the_val}</div>`).data({value:this.getProp('values')[k]}).appendTo(this.widget)
var label = isArray ? this.getProp('values')[k]: k
if (this.getProp('showValues') && !isArray) label = label + ': ' + this.getProp('values')[k]
$(`<div class="value"> ${iconify(label)}</div>`).data({value:this.getProp('values')[k]}).appendTo(this.widget)
}
this.value = undefined