svghmi/widget_jsontable.ysl2
branchsvghmi
changeset 3048 d46d545ff7b7
parent 3043 d7b009e49e87
child 3065 c369a742443d
equal deleted inserted replaced
3047:c113904f0e62 3048:d46d545ff7b7
     2 
     2 
     3 template "widget[@type='JsonTable']", mode="widget_class"
     3 template "widget[@type='JsonTable']", mode="widget_class"
     4     ||
     4     ||
     5     class JsonTableWidget extends Widget{
     5     class JsonTableWidget extends Widget{
     6         cache = [];
     6         cache = [];
     7         do_http_request() {
     7         do_http_request(...opt) {
     8             const query = {
     8             const query = {
     9                 args: this.args,
     9                 args: this.args,
    10                 vars: this.cache,
    10                 vars: this.cache,
    11                 visible: this.visible
    11                 visible: this.visible,
       
    12                 options: opt
    12             };
    13             };
    13 
    14 
    14             const options = {
    15             const options = {
    15                  method: 'POST',
    16                  method: 'POST',
    16                  body: JSON.stringify(query),
    17                  body: JSON.stringify(query),
    24         }
    25         }
    25         dispatch(value, oldval, index) {
    26         dispatch(value, oldval, index) {
    26             this.cache[index] = value;
    27             this.cache[index] = value;
    27             this.do_http_request();
    28             this.do_http_request();
    28         }
    29         }
    29         on_click(evt) {
    30         on_click(evt, ...options) {
    30             this.do_http_request();
    31             this.do_http_request(...options);
    31         }
       
    32         init() {
       
    33             this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
       
    34         }
    32         }
    35     }
    33     }
    36     ||
    34     ||
    37 
    35 
    38 template "svg:*", mode="json_table_elt_render" {
    36 template "svg:*", mode="json_table_elt_render" {
   156             with "widget_elts", "$widget_elts";
   154             with "widget_elts", "$widget_elts";
   157             with "label", "$label";
   155             with "label", "$label";
   158         }
   156         }
   159 }
   157 }
   160 
   158 
       
   159 
   161 template "svg:*", mode="json_table_render" {
   160 template "svg:*", mode="json_table_render" {
   162     param "expressions";
   161     param "expressions";
   163     param "widget_elts";
   162     param "widget_elts";
   164     param "label";
   163     param "label";
       
   164 
       
   165     const "new_expressions", "func:json_expressions($expressions, $label)";
       
   166 
       
   167     const "elt",".";
       
   168     foreach "$new_expressions/expression[position() > 1][starts-with(@name,'onClick')]"
       
   169     |         id("«$elt/@id»").setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt, '«@name»', '"+«@content»+"')");
       
   170 
   165     apply ".", mode="json_table_elt_render"
   171     apply ".", mode="json_table_elt_render"
   166         with "expressions", "func:json_expressions($expressions, $label)";
   172         with "expressions", "$new_expressions";
   167 }
   173 }
   168 
   174 
   169 template "svg:g", mode="json_table_render" {
   175 template "svg:g", mode="json_table_render" {
   170     param "expressions";
   176     param "expressions";
   171     param "widget_elts";
   177     param "widget_elts";