edouard@2891: edouard@2891: template "widget[@type='ForEach']", mode="widget_defs" { edouard@2891: param "hmi_element"; edouard@2892: const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]"; edouard@2894: edouard@2894: const "class","arg[1]/@value"; edouard@2894: edouard@2894: const "base_path","path/@value"; edouard@2894: const "hmi_index_base", "$indexed_hmitree/*[@hmipath = $base_path]"; edouard@2894: const "hmi_tree_base", "$hmitree/descendant-or-self::*[@path = $hmi_index_base/@path]"; edouard@2894: const "hmi_tree_items", "$hmi_tree_base/*[@class = $class]"; edouard@2894: const "hmi_index_items", "$indexed_hmitree/*[@path = $hmi_tree_items/@path]"; edouard@2894: const "items_paths", "$hmi_index_items/@hmipath"; Edouard@2893: | index_pool: [ edouard@2894: foreach "$hmi_index_items" { edouard@2894: | «@index»`if "position()!=last()" > ,` edouard@2894: } Edouard@2893: | ], edouard@2896: | init: function() { Edouard@2893: const "prefix","concat($class,':')"; Edouard@2893: const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')"; edouard@2896: const "buttons", "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]"; edouard@2896: foreach "$buttons" { edouard@2896: const "op","substring-after(@inkscape:label, $prefix)"; edouard@2896: | id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click('«$op»', evt)"); Edouard@2893: } edouard@2896: | Edouard@2895: | this.items = [ Edouard@2893: const "items_regex","concat('^',$prefix,'[0-9]+')"; Edouard@2893: const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]"; Edouard@2893: foreach "$unordered_items" { Edouard@2893: const "elt_label","concat($prefix, string(position()))"; Edouard@2893: const "elt","$unordered_items[@inkscape:label = $elt_label]"; edouard@2894: const "pos","position()"; edouard@2894: const "item_path", "$items_paths[$pos]"; Edouard@2895: | [ /* item="«$elt_label»" path="«$item_path»" */ Edouard@2893: if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id» Edouard@2893: foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" { edouard@2894: if "not(func:is_descendant_path(func:widget(@id)/path/@value, $item_path))" edouard@2896: 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»". Edouard@2895: | hmi_widgets["«@id»"]`if "position()!=last()" > ,` edouard@2892: } Edouard@2895: | ]`if "position()!=last()" > ,` edouard@2892: } Edouard@2895: | ] Edouard@2895: | }, Edouard@2895: | item_offset: 0, Edouard@2897: | on_click: foreach_onclick, edouard@2891: } edouard@2891: edouard@2891: template "widget[@type='ForEach']", mode="widget_subscribe"{ edouard@2891: // param "hmi_element"; Edouard@2897: | sub: foreach_subscribe, Edouard@2897: | unsub: foreach_unsubscribe, Edouard@2897: | apply_cache: foreach_apply_cache, Edouard@2897: } edouard@2891: