SVGHMI: Back button updated to class style svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 13 May 2020 18:26:38 +0200
branchsvghmi
changeset 2958 895d3f2b1786
parent 2957 c0ea5015e46f
child 2959 ae549ba1a116
SVGHMI: Back button updated to class style
svghmi/widget_back.ysl2
svghmi/widgets_common.ysl2
--- a/svghmi/widget_back.ysl2	Mon May 11 11:33:00 2020 +0200
+++ b/svghmi/widget_back.ysl2	Wed May 13 18:26:38 2020 +0200
@@ -1,17 +1,17 @@
 // widget_back.ysl2
 
-template "widget[@type='Back']", mode="widget_defs" {
-    param "hmi_element";
-
-    |     on_click: function(evt) {
-    |         if(jump_history.length > 1){
-    |            jump_history.pop();
-    |            let [page_name, index] = jump_history.pop();
-    |            switch_page(page_name, index);
-    |         }
-    |     },
-    |     init: function() {
-    |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
-    |     },
-}
-
+template "widget[@type='Back']", mode="widget_class"
+    ||
+    class BackWidget extends Widget{
+        on_click(evt) {
+            if(jump_history.length > 1){
+               jump_history.pop();
+               let [page_name, index] = jump_history.pop();
+               switch_page(page_name, index);
+            }
+        }
+        init() {
+            this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+        }
+    }
+    ||
--- a/svghmi/widgets_common.ysl2	Mon May 11 11:33:00 2020 +0200
+++ b/svghmi/widgets_common.ysl2	Wed May 13 18:26:38 2020 +0200
@@ -66,12 +66,14 @@
     ||    
     class Widget {
         constructor(elt_id,args,indexes,members){
+            this.element_id = elt_id;
             this.element = id(elt_id);
             this.args = args;
             this.indexes = indexes;
             this.offset = 0;
             Object.keys(members).forEach(prop => this[prop]=members[prop]);
         }
+
         unsub(){
             /* remove subsribers */
             for(let index of this.indexes){