svghmi/widget_foreach.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 02 May 2021 23:01:08 +0200
branchsvghmi
changeset 3232 7bdb766c2a4d
parent 3005 ff9ae4f4e3be
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.
2891
8927ae8326b2 SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     1
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: 3005
diff changeset
     2
widget_defs("ForEach") {
2891
8927ae8326b2 SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     3
    param "hmi_element";
2894
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
     4
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
     5
    if "count(path) != 1" error > ForEach widget «$hmi_element/@id» must have one HMI path given.
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
     6
    if "count(arg) != 1" error > ForEach widget «$hmi_element/@id» must have one argument given : a class name.
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
     7
2894
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
     8
    const "class","arg[1]/@value";
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
     9
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    10
    const "base_path","path/@value";
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    11
    const "hmi_index_base", "$indexed_hmitree/*[@hmipath = $base_path]";
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    12
    const "hmi_tree_base", "$hmitree/descendant-or-self::*[@path = $hmi_index_base/@path]";
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    13
    const "hmi_tree_items", "$hmi_tree_base/*[@class = $class]";
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    14
    const "hmi_index_items", "$indexed_hmitree/*[@path = $hmi_tree_items/@path]"; 
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    15
    const "items_paths", "$hmi_index_items/@hmipath"; 
2893
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    16
    |     index_pool: [
2894
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    17
    foreach "$hmi_index_items" {
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    18
    |       «@index»`if "position()!=last()" > ,`
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    19
    }
2893
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    20
    |     ],
2896
99c5335ed59f SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2895
diff changeset
    21
    |     init: function() {
2893
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    22
    const "prefix","concat($class,':')";
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    23
    const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
2896
99c5335ed59f SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2895
diff changeset
    24
    const "buttons", "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]"; 
99c5335ed59f SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2895
diff changeset
    25
    foreach "$buttons" {
99c5335ed59f SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2895
diff changeset
    26
        const "op","substring-after(@inkscape:label, $prefix)";
99c5335ed59f SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2895
diff changeset
    27
    |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click('«$op»', evt)");
2893
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    28
    }
2896
99c5335ed59f SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2895
diff changeset
    29
    |
2895
89c02b452717 SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents: 2894
diff changeset
    30
    |         this.items = [
2893
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    31
    const "items_regex","concat('^',$prefix,'[0-9]+')";
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    32
    const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    33
    foreach "$unordered_items" {
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    34
        const "elt_label","concat($prefix, string(position()))"; 
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    35
        const "elt","$unordered_items[@inkscape:label = $elt_label]";
2894
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    36
        const "pos","position()";
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    37
        const "item_path", "$items_paths[$pos]";
2895
89c02b452717 SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents: 2894
diff changeset
    38
    |           [ /* item="«$elt_label»" path="«$item_path»" */
2893
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    39
        if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2892
diff changeset
    40
        foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
2894
4cf9ad35e6d0 SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2893
diff changeset
    41
            if "not(func:is_descendant_path(func:widget(@id)/path/@value, $item_path))"
2896
99c5335ed59f SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2895
diff changeset
    42
                error > Widget id="«@id»" label="«@inkscape:label»" is having wrong path. Accroding to ForEach widget ancestor id="«$hmi_element/@id»", path should be descendant of "«$item_path»".
2895
89c02b452717 SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents: 2894
diff changeset
    43
    |             hmi_widgets["«@id»"]`if "position()!=last()" > ,`
2892
27dd409fba1d SVGHMI: ForEach knows its own widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2891
diff changeset
    44
        }
2895
89c02b452717 SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents: 2894
diff changeset
    45
    |           ]`if "position()!=last()" > ,`
2892
27dd409fba1d SVGHMI: ForEach knows its own widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2891
diff changeset
    46
    }
2895
89c02b452717 SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents: 2894
diff changeset
    47
    |         ]
89c02b452717 SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents: 2894
diff changeset
    48
    |     },
89c02b452717 SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents: 2894
diff changeset
    49
    |     item_offset: 0,
2891
8927ae8326b2 SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    50
}
8927ae8326b2 SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    51
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: 3005
diff changeset
    52
widget_class("ForEach")
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    53
||
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    54
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    55
    unsub_items(){
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    56
        for(let item of this.items){
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    57
            for(let widget of item) {
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    58
                widget.unsub();
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    59
            }
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    60
        }
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    61
    }
2891
8927ae8326b2 SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    62
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    63
    unsub(){
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    64
        this.unsub_items();
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    65
        this.offset = 0;
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    66
        this.relativeness = undefined;
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    67
    }
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    68
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    69
    sub_items(){
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    70
        for(let i = 0; i < this.items.length; i++) {
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    71
            let item = this.items[i];
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    72
            let orig_item_index = this.index_pool[i];
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    73
            let item_index = this.index_pool[i+this.item_offset];
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    74
            let item_index_offset = item_index - orig_item_index;
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    75
            if(this.relativeness[0])
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    76
                item_index_offset += this.offset;
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    77
            for(let widget of item) {
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    78
                /* all variables of all widgets in a ForEach are all relative. 
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    79
                   Really.
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    80
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    81
                   TODO: allow absolute variables in ForEach widgets
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    82
                */
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    83
                widget.sub(item_index_offset, widget.indexes.map(_=>true));
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    84
            }
2942
b07ad97e6019 SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
    85
        }
b07ad97e6019 SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
    86
    }
b07ad97e6019 SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
    87
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    88
    sub(new_offset=0, relativeness=[]){
3003
9771a724af09 SVGHMI: Better JS code semantic in ForEach widget class. Update lagging generated xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2959
diff changeset
    89
        this.offset = new_offset;
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    90
        this.relativeness = relativeness;
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    91
        this.sub_items();
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    92
    }
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    93
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    94
    apply_cache() {
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
    95
        this.items.forEach(item=>item.forEach(widget=>widget.apply_cache()));
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    96
    }
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    97
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    98
    on_click(opstr, evt) {
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
    99
        let new_item_offset = eval(String(this.item_offset)+opstr);
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   100
        if(new_item_offset + this.items.length > this.index_pool.length) {
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   101
            if(this.item_offset + this.items.length == this.index_pool.length)
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   102
                new_item_offset = 0;
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   103
            else
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   104
                new_item_offset = this.index_pool.length - this.items.length;
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   105
        } else if(new_item_offset < 0) {
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   106
            if(this.item_offset == 0)
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   107
                new_item_offset = this.index_pool.length - this.items.length;
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   108
            else
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   109
                new_item_offset = 0;
2942
b07ad97e6019 SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   110
        }
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   111
        this.item_offset = new_item_offset;
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
   112
        this.unsub_items();
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3003
diff changeset
   113
        this.sub_items();
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   114
        update_subscriptions();
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   115
        need_cache_apply.push(this);
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   116
        jumps_need_update = true;
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   117
        requestHMIAnimation();
2942
b07ad97e6019 SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   118
    }
2952
2adfce8908b4 SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2943
diff changeset
   119
||
2942
b07ad97e6019 SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   120