dgaberscek@2977: // widget_tooglebutton.ysl2 dgaberscek@2977: usveticic@3011: Edouard@3024: template "widget[@type='ToggleButton']", mode="widget_class"{ usveticic@3011: || usveticic@3011: class ToggleButtonWidget extends Widget{ usveticic@3011: frequency = 5; usveticic@3011: state = 0; usveticic@3011: active_style = undefined; usveticic@3011: inactive_style = undefined; usveticic@3011: usveticic@3011: dispatch(value) { usveticic@3059: this.state = value; usveticic@3059: //redraw toggle button usveticic@3059: this.request_animate(); usveticic@3011: } usveticic@3011: usveticic@3011: on_click(evt) { usveticic@3059: //toggle state and apply usveticic@3056: if (this.state) { usveticic@3056: this.state = 0; usveticic@3056: } else { usveticic@3056: this.state = 1; usveticic@3056: } Edouard@3018: this.apply_hmi_value(0, this.state); usveticic@3059: usveticic@3059: //redraw toggle button usveticic@3059: this.request_animate(); usveticic@3059: } usveticic@3059: usveticic@3059: animate(){ usveticic@3059: // redraw toggle button on screen refresh usveticic@3059: if (this.state) { usveticic@3059: this.active_elt.setAttribute("style", this.active_style); usveticic@3059: this.inactive_elt.setAttribute("style", "display:none"); usveticic@3059: } else { usveticic@3059: this.inactive_elt.setAttribute("style", this.inactive_style); usveticic@3059: this.active_elt.setAttribute("style", "display:none"); usveticic@3059: } usveticic@3011: } usveticic@3011: usveticic@3011: init() { usveticic@3059: this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; usveticic@3059: this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; usveticic@3059: usveticic@3059: if (this.active_style && this.inactive_style) { usveticic@3059: this.active_elt.setAttribute("style", "display:none"); usveticic@3059: this.inactive_elt.setAttribute("style", this.inactive_style); usveticic@3059: } usveticic@3059: usveticic@3011: this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); usveticic@3011: } usveticic@3011: } usveticic@3011: || Edouard@3024: } usveticic@3011: dgaberscek@2977: template "widget[@type='ToggleButton']", mode="widget_defs" { dgaberscek@2977: param "hmi_element"; usveticic@3059: optional_labels("active inactive"); usveticic@3011: |, edouard@3004: }