# HG changeset patch # User Edouard Tisserant # Date 1585087674 -3600 # Node ID 99c5335ed59fc48c74492782ddadff189a70a6dd # Parent 89c02b452717ff9c6d847d3aea16c33702836e6e SVGHMI: Widget ForEach buttons now call corresponding methods. diff -r 89c02b452717 -r 99c5335ed59f svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Tue Mar 24 14:03:19 2020 +0100 +++ b/svghmi/gen_index_xhtml.xslt Tue Mar 24 23:07:54 2020 +0100 @@ -723,29 +723,23 @@ ], - buttons: [ + init: function() { - - [" - - ", id(" + + + + id(" - ")] - - , - - + ").setAttribute("onclick", "hmi_widgets[' + + '].on_click(' + + ', evt)"); - ], - - init: function() { - - /* TODO elt.setAttribute("onclick", "hmi_widgets[' - - '].on_click(evt)");*/ + this.items = [ @@ -779,9 +773,9 @@ " is having wrong path. Accroding to ForEach widget ancestor id=" - ", path should be descendant of + ", path should be descendant of " - . + ". hmi_widgets[" @@ -804,19 +798,25 @@ }, + on_click: function(opstr, evt) { + + console.log(opstr); + + }, + item_offset: 0, sub: function(off){ - subscribe_foreach.call(this,off); + foreach_subscribe.call(this,off); }, unsub: function(){ - unsubscribe_foreach.call(this); + foreach_unsubscribe.call(this); }, @@ -1751,7 +1751,7 @@ - function unsubscribe_foreach(){ + function foreach_unsubscribe(){ for(let item of this.items){ @@ -1767,7 +1767,7 @@ - function subscribe_foreach(new_offset=0){ + function foreach_subscribe(new_offset=0){ for(let i = 0; i < this.items.length; i++) { diff -r 89c02b452717 -r 99c5335ed59f svghmi/svghmi.js --- a/svghmi/svghmi.js Tue Mar 24 14:03:19 2020 +0100 +++ b/svghmi/svghmi.js Tue Mar 24 23:07:54 2020 +0100 @@ -303,7 +303,7 @@ } } -function unsubscribe_foreach(){ +function foreach_unsubscribe(){ for(let item of this.items){ for(let widget of item) { unsubscribe.call(widget); @@ -311,7 +311,7 @@ } } -function subscribe_foreach(new_offset=0){ +function foreach_subscribe(new_offset=0){ for(let i = 0; i < this.items.length; i++) { let item = this.items[i]; let orig_item_index = this.index_pool[i]; diff -r 89c02b452717 -r 99c5335ed59f svghmi/widget_foreach.ysl2 --- 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); | }, }