svghmi/widget_button.ysl2
branchsvghmi
changeset 3058 6ea4b7e1a9ed
parent 3039 5ca37a7b89e2
parent 3056 827bf284feec
child 3059 e0db3f6a5f39
equal deleted inserted replaced
3055:6dd617cc9c05 3058:6ea4b7e1a9ed
     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 = 0;
       
     8         plc_lock = false;
     8         active_style = undefined;
     9         active_style = undefined;
     9         inactive_style = undefined;
    10         inactive_style = undefined;
    10 
    11 
    11         // TODO decouple update of DOM from event (i.e use animate())
    12         dispatch(value) {
    12 
    13             if(value){
    13 
    14                 this.button_release();
    14         // TODO State of the button should distinguish UI feedbak from current PLC value
       
    15 
       
    16         on_mouse_down(evt) {
       
    17             if (this.active_style && this.inactive_style) {
       
    18                 this.active_elt.setAttribute("style", this.active_style);
       
    19                 this.inactive_elt.setAttribute("style", "display:none");
       
    20             }
    15             }
    21             this.apply_hmi_value(0, 1);
       
    22             // TODO inhibit all mouse/touch events except mouse up (in other word grab cursor)
       
    23         }
    16         }
    24 
    17 
    25         on_mouse_up(evt) {
    18          on_mouse_down(evt) {
       
    19              if (this.active_style && this.inactive_style) {
       
    20                  this.active_elt.setAttribute("style", this.active_style);
       
    21                  this.inactive_elt.setAttribute("style", "display:none");
       
    22              }
       
    23              this.apply_hmi_value(0, 1);
       
    24              this.plc_lock = false;
       
    25          }
       
    26 
       
    27          on_mouse_up(evt) {
       
    28              this.button_release();
       
    29          }
       
    30 
       
    31          button_release(){
       
    32             if(!this.plc_lock){
       
    33                 this.plc_lock = true;
       
    34             }
       
    35             else{
       
    36                 if (this.active_style && this.inactive_style) {
       
    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 
       
    44          init() {
       
    45             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;
       
    47 
    26             if (this.active_style && this.inactive_style) {
    48             if (this.active_style && this.inactive_style) {
    27                 this.active_elt.setAttribute("style", "display:none");
    49                 this.active_elt.setAttribute("style", "display:none");
    28                 this.inactive_elt.setAttribute("style", this.inactive_style);
    50                 this.inactive_elt.setAttribute("style", this.inactive_style);
    29             }
    51             }
    30             this.apply_hmi_value(0, 0);
       
    31             // TODO release inhibited events 
       
    32         }
       
    33 
    52 
    34         init() {
    53             this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)");
    35            // TODO : move to widget_defs so that we can have generated string literals directly
    54             this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)");
    36            this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
    55          }
    37            this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
       
    38 
       
    39            if (this.active_style && this.inactive_style) {
       
    40                this.active_elt.setAttribute("style", "display:none");
       
    41                this.inactive_elt.setAttribute("style", this.inactive_style);
       
    42            }
       
    43 
       
    44            this.element.setAttribute("onmousedown", "hmi_widgets[\""+this.element_id+"\"].on_mouse_down(evt)");
       
    45            this.element.setAttribute("onmouseup", "hmi_widgets[\""+this.element_id+"\"].on_mouse_up(evt)");
       
    46         }
       
    47     }
    56     }
    48     ||
    57     ||
    49 }
    58 }
    50 
    59 
    51 
    60