svghmi/widget_jsontable.ysl2
branchsvghmi
changeset 3034 793ce2117258
parent 3031 440d74319a74
child 3035 d1fc8c55c1d3
equal deleted inserted replaced
3033:52f6548982d4 3034:793ce2117258
     1 // widget_jsontable.ysl2
     1 // widget_jsontable.ysl2
     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         do_http_request() {
     7         do_http_request() {
     7             const query = {
     8             const query = {
     8                  offset: '42',
     9                 args: this.args,
     9                  filter: '*powerloss*',
    10                 vars: this.cache
    10                  args: this.args
       
    11             };
    11             };
    12 
    12 
    13             const options = {
    13             const options = {
    14                  method: 'POST',
    14                  method: 'POST',
    15                  body: JSON.stringify(query),
    15                  body: JSON.stringify(query),
    16                  headers: {'Content-Type': 'application/json'}
    16                  headers: {'Content-Type': 'application/json'}
    17             }
    17             };
    18 
    18 
    19             fetch(this.args[0], options)
    19             fetch(this.args[0], options)
    20                 .then(res => res.json())
    20                 .then(res => res.json())
    21                 .then(this.spread_json_data);
    21                 .then(this.spread_json_data);
    22 
    22 
    23         }
    23         }
    24         dispatch(value) {
    24         dispatch(value, oldval, index) {
       
    25             console.log("mhooo", index);
       
    26             this.cache[index] = value;
    25             this.do_http_request();
    27             this.do_http_request();
    26         }
    28         }
    27         on_click(evt) {
    29         on_click(evt) {
    28             this.do_http_request();
    30             this.do_http_request();
    29         }
    31         }