svghmi/widget_foreach.ysl2
branchsvghmi
changeset 2896 99c5335ed59f
parent 2895 89c02b452717
child 2897 bf8a39cc65e4
equal deleted inserted replaced
2895:89c02b452717 2896:99c5335ed59f
    14     |     index_pool: [
    14     |     index_pool: [
    15     foreach "$hmi_index_items" {
    15     foreach "$hmi_index_items" {
    16     |       «@index»`if "position()!=last()" > ,`
    16     |       «@index»`if "position()!=last()" > ,`
    17     }
    17     }
    18     |     ],
    18     |     ],
    19     |     buttons: [
    19     |     init: function() {
    20     const "prefix","concat($class,':')";
    20     const "prefix","concat($class,':')";
    21     const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
    21     const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
    22     foreach "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]" {
    22     const "buttons", "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]"; 
    23     |         ["«substring-after(@inkscape:label, concat(arg[1]/@value, ':'))»", id("«@id»")]`if "position()!=last()" > ,`
    23     foreach "$buttons" {
       
    24         const "op","substring-after(@inkscape:label, $prefix)";
       
    25     |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click('«$op»', evt)");
    24     }
    26     }
    25     |     ],
    27     |
    26     |     init: function() {
       
    27     |         /* TODO elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");*/
       
    28 
       
    29     |         this.items = [
    28     |         this.items = [
    30     const "items_regex","concat('^',$prefix,'[0-9]+')";
    29     const "items_regex","concat('^',$prefix,'[0-9]+')";
    31     const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
    30     const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
    32     foreach "$unordered_items" {
    31     foreach "$unordered_items" {
    33         const "elt_label","concat($prefix, string(position()))"; 
    32         const "elt_label","concat($prefix, string(position()))"; 
    36         const "item_path", "$items_paths[$pos]";
    35         const "item_path", "$items_paths[$pos]";
    37     |           [ /* item="«$elt_label»" path="«$item_path»" */
    36     |           [ /* item="«$elt_label»" path="«$item_path»" */
    38         if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
    37         if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
    39         foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
    38         foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
    40             if "not(func:is_descendant_path(func:widget(@id)/path/@value, $item_path))"
    39             if "not(func:is_descendant_path(func:widget(@id)/path/@value, $item_path))"
    41                 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».
    40                 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»".
    42     |             hmi_widgets["«@id»"]`if "position()!=last()" > ,`
    41     |             hmi_widgets["«@id»"]`if "position()!=last()" > ,`
    43         }
    42         }
    44     |           ]`if "position()!=last()" > ,`
    43     |           ]`if "position()!=last()" > ,`
    45     }
    44     }
    46     |         ]
    45     |         ]
       
    46     |     },
       
    47     |     on_click: function(opstr, evt) {
       
    48     |         console.log(opstr);
    47     |     },
    49     |     },
    48     |     item_offset: 0,
    50     |     item_offset: 0,
    49 }
    51 }
    50 
    52 
    51 template "widget[@type='ForEach']", mode="widget_subscribe"{
    53 template "widget[@type='ForEach']", mode="widget_subscribe"{
    52     // param "hmi_element";
    54     // param "hmi_element";
    53     |     sub: function(off){
    55     |     sub: function(off){
    54     |         subscribe_foreach.call(this,off);
    56     |         foreach_subscribe.call(this,off);
    55     |     },
    57     |     },
    56 
    58 
    57     |     unsub: function(){
    59     |     unsub: function(){
    58     |         unsubscribe_foreach.call(this);
    60     |         foreach_unsubscribe.call(this);
    59     |     },
    61     |     },
    60 }
    62 }