svghmi/widget_tooglebutton.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Thu, 06 Aug 2020 14:59:04 +0200
branchsvghmi
changeset 3007 360300a8b995
parent 3004 705e34c6fe93
child 3011 601c6dbc1da7
permissions -rw-r--r--
SVGHMI : have to move some JS declarations from "preamble" to "declarations" and others from "declarations" to "definitions" section to make room for JS libraries that would be used by widget classes.
2977
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     1
// widget_tooglebutton.ysl2
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     2
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     3
template "widget[@type='ToggleButton']", mode="widget_defs" {
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     4
    param "hmi_element";
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     5
    labels("active inactive");
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     6
    |     frequency: 5,
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     7
    |     state: 0,
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     8
    |     dispatch: function(value) {
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     9
    |         this.state = value;
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    10
    |         if (this.state) {
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    11
    |             this.active_elt.setAttribute("style", this.active_style);
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    12
    |             this.inactive_elt.setAttribute("style", "display:none");
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    13
    |             this.state = 0;
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    14
    |         } else {
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    15
    |             this.inactive_elt.setAttribute("style", this.inactive_style);
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    16
    |             this.active_elt.setAttribute("style", "display:none");
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    17
    |             this.state = 1;
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    18
    |         }
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    19
    |     },
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    20
    |     on_click: function(evt) {
3004
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2977
diff changeset
    21
    |         this.apply_hmi_value(0, this.state);
2977
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    22
    |     },
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    23
    |     active_style: undefined,
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    24
    |     inactive_style: undefined,
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    25
    |     init: function() {
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    26
    |         this.active_style = this.active_elt.style.cssText;
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    27
    |         this.inactive_style = this.inactive_elt.style.cssText;
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    28
    |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    29
    |     },
3004
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2977
diff changeset
    30
}