2 |
2 |
3 template "widget[@type='Button']", mode="widget_class"{ |
3 template "widget[@type='Button']", mode="widget_class"{ |
4 || |
4 || |
5 class ButtonWidget extends Widget{ |
5 class ButtonWidget extends Widget{ |
6 frequency = 5; |
6 frequency = 5; |
7 state = 0; |
7 state_plc = 0; |
|
8 state_hmi = 0; |
8 plc_lock = false; |
9 plc_lock = false; |
9 active_style = undefined; |
10 active_style = undefined; |
10 inactive_style = undefined; |
11 inactive_style = undefined; |
11 |
12 |
12 dispatch(value) { |
13 dispatch(value) { |
13 if(value){ |
14 this.state_plc = value; |
14 this.button_release(); |
15 if(this.plc_lock){ |
|
16 if(this.state_plc == 1){ |
|
17 this.apply_hmi_value(0, 0); |
|
18 this.plc_lock = false; |
|
19 } |
15 } |
20 } |
|
21 |
|
22 //redraw button |
|
23 this.state_hmi = this.state_plc; |
|
24 this.request_animate(); |
16 } |
25 } |
17 |
26 |
18 on_mouse_down(evt) { |
27 animate(){ |
19 if (this.active_style && this.inactive_style) { |
28 // redraw button on screen refresh |
20 this.active_elt.setAttribute("style", this.active_style); |
29 if (this.state_hmi) { |
21 this.inactive_elt.setAttribute("style", "display:none"); |
30 this.active_elt.setAttribute("style", this.active_style); |
22 } |
31 this.inactive_elt.setAttribute("style", "display:none"); |
23 this.apply_hmi_value(0, 1); |
32 } else { |
24 this.plc_lock = false; |
33 this.inactive_elt.setAttribute("style", this.inactive_style); |
25 } |
34 this.active_elt.setAttribute("style", "display:none"); |
|
35 } |
|
36 } |
26 |
37 |
27 on_mouse_up(evt) { |
38 on_click(evt) { |
28 this.button_release(); |
39 //set state and apply if plc is 0 |
29 } |
40 this.plc_lock = true; |
|
41 if(this.state_plc == 0){ |
|
42 this.apply_hmi_value(0, 1); |
|
43 } |
|
44 //redraw button |
|
45 this.request_animate(); |
|
46 } |
30 |
47 |
31 button_release(){ |
48 on_press(evt) { |
32 if(!this.plc_lock){ |
49 //set graphic |
33 this.plc_lock = true; |
50 this.state_hmi = 1; |
34 } |
51 //redraw button |
35 else{ |
52 this.request_animate(); |
36 if (this.active_style && this.inactive_style) { |
53 } |
37 this.active_elt.setAttribute("style", "display:none"); |
|
38 this.inactive_elt.setAttribute("style", this.inactive_style); |
|
39 } |
|
40 this.apply_hmi_value(0, 0); |
|
41 } |
|
42 } |
|
43 |
54 |
44 init() { |
55 init() { |
45 this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; |
56 this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; |
46 this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; |
57 this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; |
47 |
58 |
48 if (this.active_style && this.inactive_style) { |
59 if (this.active_style && this.inactive_style) { |
49 this.active_elt.setAttribute("style", "display:none"); |
60 this.active_elt.setAttribute("style", "display:none"); |
50 this.inactive_elt.setAttribute("style", this.inactive_style); |
61 this.inactive_elt.setAttribute("style", this.inactive_style); |
51 } |
62 } |
52 |
63 |
53 this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)"); |
64 this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); |
54 this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)"); |
65 this.element.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_press(evt)"); |
55 } |
66 } |
56 } |
67 } |
57 || |
68 || |
58 } |
69 } |
59 |
70 |