SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
template "widget[@type='ForEach']", mode="widget_defs" {
param "hmi_element";
const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
const "class","arg[1]/@value";
const "base_path","path/@value";
const "hmi_index_base", "$indexed_hmitree/*[@hmipath = $base_path]";
const "hmi_tree_base", "$hmitree/descendant-or-self::*[@path = $hmi_index_base/@path]";
const "hmi_tree_items", "$hmi_tree_base/*[@class = $class]";
const "hmi_index_items", "$indexed_hmitree/*[@path = $hmi_tree_items/@path]";
const "items_paths", "$hmi_index_items/@hmipath";
| index_pool: [
foreach "$hmi_index_items" {
| «@index»`if "position()!=last()" > ,`
}
| ],
| buttons: [
const "prefix","concat($class,':')";
const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
foreach "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]" {
| ["«substring-after(@inkscape:label, concat(arg[1]/@value, ':'))»", id("«@id»")]`if "position()!=last()" > ,`
}
| ],
| init: function() {
| /* TODO elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");*/
| this.items = [
const "items_regex","concat('^',$prefix,'[0-9]+')";
const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
foreach "$unordered_items" {
const "elt_label","concat($prefix, string(position()))";
const "elt","$unordered_items[@inkscape:label = $elt_label]";
const "pos","position()";
const "item_path", "$items_paths[$pos]";
| [ /* item="«$elt_label»" path="«$item_path»" */
if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
if "not(func:is_descendant_path(func:widget(@id)/path/@value, $item_path))"
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».
| hmi_widgets["«@id»"]`if "position()!=last()" > ,`
}
| ]`if "position()!=last()" > ,`
}
| ]
| },
| item_offset: 0,
}
template "widget[@type='ForEach']", mode="widget_subscribe"{
// param "hmi_element";
| sub: function(off){
| subscribe_foreach.call(this,off);
| },
| unsub: function(){
| unsubscribe_foreach.call(this);
| },
}