--- a/svghmi/widget_foreach.ysl2 Tue Mar 24 14:03:19 2020 +0100
+++ b/svghmi/widget_foreach.ysl2 Tue Mar 24 23:07:54 2020 +0100
@@ -16,16 +16,15 @@
| «@index»`if "position()!=last()" > ,`
}
| ],
- | buttons: [
+ | init: function() {
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()" > ,`
+ const "buttons", "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]";
+ foreach "$buttons" {
+ const "op","substring-after(@inkscape:label, $prefix)";
+ | id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click('«$op»', evt)");
}
- | ],
- | 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)]";
@@ -38,23 +37,26 @@
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».
+ 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()" > ,`
}
| ]
| },
+ | on_click: function(opstr, evt) {
+ | console.log(opstr);
+ | },
| item_offset: 0,
}
template "widget[@type='ForEach']", mode="widget_subscribe"{
// param "hmi_element";
| sub: function(off){
- | subscribe_foreach.call(this,off);
+ | foreach_subscribe.call(this,off);
| },
| unsub: function(){
- | unsubscribe_foreach.call(this);
+ | foreach_unsubscribe.call(this);
| },
}