svghmi/widget_jsontable.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 14 Jul 2020 22:05:47 +0200
branchsvghmi
changeset 2994 b6a9ef7f7e43
child 2996 14635b09d329
permissions -rw-r--r--
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
// widget_jsontable.ysl2

template "widget[@type='JsonTable']", mode="widget_class"
    ||
    class JsonTableWidget extends Widget{
        on_click(evt) {
            const query = {
                 offset: '42',
                 filter: '*powerloss*',
                 args: this.args
            };

            const options = {
                 method: 'POST',
                 body: JSON.stringify(query),
                 headers: {'Content-Type': 'application/json'}
            }

            fetch(this.args[0], options)
                .then(res => res.json())
                .then(res => console.log(res));

        }
        init() {
            this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
        }
    }
    ||