dgaberscek@2944: // widget_button.ysl2 dgaberscek@2944: Edouard@3024: template "widget[@type='Button']", mode="widget_class"{ usveticic@3009: || usveticic@3009: class ButtonWidget extends Widget{ usveticic@3009: frequency = 5; usveticic@3059: state_plc = 0; usveticic@3059: state_hmi = 0; usveticic@3056: plc_lock = false; usveticic@3009: active_style = undefined; usveticic@3009: inactive_style = undefined; usveticic@3009: usveticic@3056: dispatch(value) { usveticic@3059: this.state_plc = value; usveticic@3059: if(this.plc_lock){ usveticic@3059: if(this.state_plc == 1){ usveticic@3059: this.apply_hmi_value(0, 0); usveticic@3059: this.plc_lock = false; usveticic@3059: } usveticic@3056: } usveticic@3059: usveticic@3059: //redraw button usveticic@3059: this.state_hmi = this.state_plc; usveticic@3059: this.request_animate(); usveticic@3056: } usveticic@3056: usveticic@3059: animate(){ usveticic@3062: if (this.active_style && this.inactive_style) { usveticic@3062: // redraw button on screen refresh usveticic@3062: if (this.state_hmi) { usveticic@3062: this.active_elt.setAttribute("style", this.active_style); usveticic@3062: this.inactive_elt.setAttribute("style", "display:none"); usveticic@3062: } else { usveticic@3062: this.inactive_elt.setAttribute("style", this.inactive_style); usveticic@3062: this.active_elt.setAttribute("style", "display:none"); usveticic@3062: } usveticic@3059: } usveticic@3059: } usveticic@3009: usveticic@3059: on_click(evt) { usveticic@3059: //set state and apply if plc is 0 usveticic@3059: this.plc_lock = true; usveticic@3059: if(this.state_plc == 0){ usveticic@3059: this.apply_hmi_value(0, 1); usveticic@3059: } usveticic@3059: //redraw button usveticic@3059: this.request_animate(); usveticic@3059: } usveticic@3056: usveticic@3059: on_press(evt) { usveticic@3059: //set graphic usveticic@3059: this.state_hmi = 1; usveticic@3059: //redraw button usveticic@3059: this.request_animate(); usveticic@3059: } usveticic@3009: usveticic@3009: init() { usveticic@3009: this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; usveticic@3009: this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; usveticic@3009: usveticic@3009: if (this.active_style && this.inactive_style) { usveticic@3009: this.active_elt.setAttribute("style", "display:none"); usveticic@3009: this.inactive_elt.setAttribute("style", this.inactive_style); usveticic@3009: } usveticic@3009: usveticic@3059: this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); usveticic@3059: this.element.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_press(evt)"); usveticic@3009: } usveticic@3009: } usveticic@3009: || Edouard@3024: } usveticic@3009: usveticic@3009: dgaberscek@2976: template "widget[@type='Button']", mode="widget_defs" { dgaberscek@2976: param "hmi_element"; dgaberscek@2976: optional_labels("active inactive"); usveticic@3009: |, edouard@3000: }