1 // widget_tooglebutton.ysl2 |
1 // widget_tooglebutton.ysl2 |
|
2 |
|
3 |
|
4 template "widget[@type='ToggleButton']", mode="widget_class" |
|
5 || |
|
6 class ToggleButtonWidget extends Widget{ |
|
7 frequency = 5; |
|
8 state = 0; |
|
9 active_style = undefined; |
|
10 inactive_style = undefined; |
|
11 |
|
12 dispatch(value) { |
|
13 this.state = value; |
|
14 if (this.state) { |
|
15 this.active_elt.setAttribute("style", this.active_style); |
|
16 this.inactive_elt.setAttribute("style", "display:none"); |
|
17 this.state = 0; |
|
18 } else { |
|
19 this.inactive_elt.setAttribute("style", this.inactive_style); |
|
20 this.active_elt.setAttribute("style", "display:none"); |
|
21 this.state = 1; |
|
22 } |
|
23 } |
|
24 |
|
25 on_click(evt) { |
|
26 this.apply_hmi_value(0, this.state); |
|
27 } |
|
28 |
|
29 init() { |
|
30 this.active_style = this.active_elt.style.cssText; |
|
31 this.inactive_style = this.inactive_elt.style.cssText; |
|
32 this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); |
|
33 } |
|
34 } |
|
35 || |
2 |
36 |
3 template "widget[@type='ToggleButton']", mode="widget_defs" { |
37 template "widget[@type='ToggleButton']", mode="widget_defs" { |
4 param "hmi_element"; |
38 param "hmi_element"; |
5 labels("active inactive"); |
39 labels("active inactive"); |
6 | frequency: 5, |
40 |, |
7 | state: 0, |
|
8 | dispatch: function(value) { |
|
9 | this.state = value; |
|
10 | if (this.state) { |
|
11 | this.active_elt.setAttribute("style", this.active_style); |
|
12 | this.inactive_elt.setAttribute("style", "display:none"); |
|
13 | this.state = 0; |
|
14 | } else { |
|
15 | this.inactive_elt.setAttribute("style", this.inactive_style); |
|
16 | this.active_elt.setAttribute("style", "display:none"); |
|
17 | this.state = 1; |
|
18 | } |
|
19 | }, |
|
20 | on_click: function(evt) { |
|
21 | this.apply_hmi_value(0, this.state); |
|
22 | }, |
|
23 | active_style: undefined, |
|
24 | inactive_style: undefined, |
|
25 | init: function() { |
|
26 | this.active_style = this.active_elt.style.cssText; |
|
27 | this.inactive_style = this.inactive_elt.style.cssText; |
|
28 | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); |
|
29 | }, |
|
30 } |
41 } |