svghmi/widget_tooglebutton.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 02 May 2021 23:01:08 +0200
branchsvghmi
changeset 3232 7bdb766c2a4d
parent 3219 cc0ecc5e918f
child 3241 fe945f1f48b7
permissions -rw-r--r--
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
2977
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     1
// widget_tooglebutton.ysl2
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     2
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
     3
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3219
diff changeset
     4
widget_class("ToggleButton") {
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
     5
    ||
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
     6
        frequency = 5;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
     7
        state = 0;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
     8
        active_style = undefined;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
     9
        inactive_style = undefined;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    10
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    11
        dispatch(value) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    12
            this.state = value;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    13
            //redraw toggle button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    14
            this.request_animate();
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    15
        }
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    16
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    17
        on_click(evt) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    18
            //toggle state and apply
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    19
            this.state = this.state ? false : true;
3018
Edouard Tisserant
parents: 3011
diff changeset
    20
            this.apply_hmi_value(0, this.state);
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    21
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    22
            //redraw toggle button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    23
            this.request_animate();
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    24
        }
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    25
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    26
        activate(val) {
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    27
            let [active, inactive] = val ? ["none",""] : ["", "none"];
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    28
            if (this.active_elt)
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    29
                this.active_elt.style.display = active;
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    30
            if (this.inactive_elt)
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    31
                this.inactive_elt.style.display = inactive;
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    32
        }
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    33
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    34
        animate(){
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    35
            // redraw toggle button on screen refresh
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    36
            this.activate(this.state);
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    37
        }
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    38
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    39
        init() {
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    40
            this.activate(false);
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    41
            this.element.onclick = (evt) => this.on_click(evt);
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    42
        }
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    43
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    44
}
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    45
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3219
diff changeset
    46
widget_defs("ToggleButton") {
2977
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
    47
    param "hmi_element";
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    48
    optional_labels("active inactive");
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
    49
}