# HG changeset patch
# User Edouard Tisserant
# Date 1598621375 -7200
# Node ID d46d545ff7b791b54fa7bcefbbbdf79f693d9238
# Parent c113904f0e62558358568e46b38d82b808b43a10
SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
diff -r c113904f0e62 -r d46d545ff7b7 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Fri Aug 28 11:31:18 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Fri Aug 28 15:29:35 2020 +0200
@@ -3467,7 +3467,7 @@
cache = [];
- do_http_request() {
+ do_http_request(...opt) {
const query = {
@@ -3475,7 +3475,9 @@
vars: this.cache,
- visible: this.visible
+ visible: this.visible,
+
+ options: opt
};
@@ -3511,15 +3513,9 @@
}
- on_click(evt) {
-
- this.do_http_request();
-
- }
-
- init() {
-
- this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+ on_click(evt, ...options) {
+
+ this.do_http_request(...options);
}
@@ -3705,8 +3701,20 @@
+
+
+
+ id("
+
+ ").setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt, '
+
+ ', '"+
+
+ +"')");
+
+
-
+
diff -r c113904f0e62 -r d46d545ff7b7 svghmi/widget_jsontable.ysl2
--- a/svghmi/widget_jsontable.ysl2 Fri Aug 28 11:31:18 2020 +0200
+++ b/svghmi/widget_jsontable.ysl2 Fri Aug 28 15:29:35 2020 +0200
@@ -4,11 +4,12 @@
||
class JsonTableWidget extends Widget{
cache = [];
- do_http_request() {
+ do_http_request(...opt) {
const query = {
args: this.args,
vars: this.cache,
- visible: this.visible
+ visible: this.visible,
+ options: opt
};
const options = {
@@ -26,11 +27,8 @@
this.cache[index] = value;
this.do_http_request();
}
- on_click(evt) {
- this.do_http_request();
- }
- init() {
- this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+ on_click(evt, ...options) {
+ this.do_http_request(...options);
}
}
||
@@ -158,12 +156,20 @@
}
}
+
template "svg:*", mode="json_table_render" {
param "expressions";
param "widget_elts";
param "label";
+
+ const "new_expressions", "func:json_expressions($expressions, $label)";
+
+ const "elt",".";
+ foreach "$new_expressions/expression[position() > 1][starts-with(@name,'onClick')]"
+ | id("«$elt/@id»").setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt, '«@name»', '"+«@content»+"')");
+
apply ".", mode="json_table_elt_render"
- with "expressions", "func:json_expressions($expressions, $label)";
+ with "expressions", "$new_expressions";
}
template "svg:g", mode="json_table_render" {
diff -r c113904f0e62 -r d46d545ff7b7 tests/svghmi/py_ext_0@py_ext/pyfile.xml
--- a/tests/svghmi/py_ext_0@py_ext/pyfile.xml Fri Aug 28 11:31:18 2020 +0200
+++ b/tests/svghmi/py_ext_0@py_ext/pyfile.xml Fri Aug 28 15:29:35 2020 +0200
@@ -9,13 +9,18 @@
-
+ inkscape:label=".status onClick[acknowledge]=.alarmid" />