svghmi/widget_jsontable.ysl2
changeset 4056 4b2de1a0fbf9
parent 3386 608f48ad3dfc
equal deleted inserted replaced
4055:c325749651d1 4056:4b2de1a0fbf9
     4     longdesc
     4     longdesc
     5     || 
     5     || 
     6     Send given variables as POST to http URL argument, spread returned JSON in
     6     Send given variables as POST to http URL argument, spread returned JSON in
     7     SVG sub-elements of "data" labeled element.
     7     SVG sub-elements of "data" labeled element.
     8     
     8     
     9     Documentation to be written. see svghmi exemple.
     9     Documentation to be written. see svghmi example.
    10     ||
    10     ||
    11 
    11 
    12     shortdesc > Http POST variables, spread JSON back
    12     shortdesc > Http POST variables, spread JSON back
    13 
    13 
    14     arg name="url" accepts="string" >  
    14     arg name="url" accepts="string" >  
   111 def "func:json_expressions" {
   111 def "func:json_expressions" {
   112     param "expressions";
   112     param "expressions";
   113     param "label";
   113     param "label";
   114 
   114 
   115     // compute javascript expressions to access JSON data
   115     // compute javascript expressions to access JSON data
   116     // desscribed in given svg element's "label"
   116     // described in given svg element's "label"
   117     // knowing that parent element already has given "expressions".
   117     // knowing that parent element already has given "expressions".
   118 
   118 
   119     choose {
   119     choose {
   120         when "$label" {
   120         when "$label" {
   121             const "suffixes", "str:split($label)";
   121             const "suffixes", "str:split($label)";
   126                 const "expr","$expressions[position() <= $pos][last()]/expression";
   126                 const "expr","$expressions[position() <= $pos][last()]/expression";
   127                 choose {
   127                 choose {
   128                     when "contains($suffix,'=')" {
   128                     when "contains($suffix,'=')" {
   129                         const "name", "substring-before($suffix,'=')";
   129                         const "name", "substring-before($suffix,'=')";
   130                         if "$expr/@name[. != $name]"
   130                         if "$expr/@name[. != $name]"
   131                             error > JsonTable : missplaced '=' or inconsistent names in Json data expressions.
   131                             error > JsonTable : misplaced '=' or inconsistent names in Json data expressions.
   132                         attrib "name" value "$name";
   132                         attrib "name" value "$name";
   133                         attrib "content" > «$expr/@content»«substring-after($suffix,'=')»
   133                         attrib "content" > «$expr/@content»«substring-after($suffix,'=')»
   134                     }
   134                     }
   135                     otherwise {
   135                     otherwise {
   136                         copy "$expr/@name";
   136                         copy "$expr/@name";
   174     choose {
   174     choose {
   175 
   175 
   176         when "count($from_textstylelist) > 0" {
   176         when "count($from_textstylelist) > 0" {
   177             const "content_expr", "$expressions/expression[2]/@content";
   177             const "content_expr", "$expressions/expression[2]/@content";
   178             if "string-length($content_expr) = 0 or $expressions/expression[2]/@name != 'textContent'"
   178             if "string-length($content_expr) = 0 or $expressions/expression[2]/@name != 'textContent'"
   179                 error > Clones (svg:use) in JsonTable Widget pointing to a HMI:TextStyleList widget or item must have a "textContent=.someVal" assignement following value expression in label.
   179                 error > Clones (svg:use) in JsonTable Widget pointing to a HMI:TextStyleList widget or item must have a "textContent=.someVal" assignment following value expression in label.
   180             |         {
   180             |         {
   181             |           let elt = id("«@id»");
   181             |           let elt = id("«@id»");
   182             |           elt.textContent = String(«$content_expr»);
   182             |           elt.textContent = String(«$content_expr»);
   183             |           elt.style = hmi_widgets["«$from_textstylelist/@listid»"].styles[«$value_expr»];
   183             |           elt.style = hmi_widgets["«$from_textstylelist/@listid»"].styles[«$value_expr»];
   184             |         }
   184             |         }
   187             |         id("«@id»").textContent = String(«$value_expr»);
   187             |         id("«@id»").textContent = String(«$value_expr»);
   188         }
   188         }
   189     }
   189     }
   190 }
   190 }
   191 
   191 
   192 
   192 template "svg:image", mode="json_table_elt_render" {
   193 // only labels comming from Json widget are counted in
   193     param "expressions";
       
   194     const "value_expr", "$expressions/expression[1]/@content";
       
   195     |         id("«@id»").setAttribute('href', String(«$value_expr»));
       
   196 }
       
   197 
       
   198 // only labels coming from Json widget are counted in
   194 def "func:filter_non_widget_label" {
   199 def "func:filter_non_widget_label" {
   195     param "elt";
   200     param "elt";
   196     param "widget_elts";
   201     param "widget_elts";
   197     const "eltid" choose {
   202     const "eltid" choose {
   198         when "$elt/@original" value "$elt/@original";
   203         when "$elt/@original" value "$elt/@original";