SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 04 Aug 2020 11:53:39 +0200
branchsvghmi
changeset 3004 705e34c6fe93
parent 3003 9771a724af09
child 3005 ff9ae4f4e3be
child 3009 7c6960f09881
SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
svghmi/gen_index_xhtml.xslt
svghmi/widget_button.ysl2
svghmi/widget_dropdown.ysl2
svghmi/widget_input.ysl2
svghmi/widget_tooglebutton.ysl2
svghmi/widgets_common.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Mon Aug 03 18:25:23 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Tue Aug 04 11:53:39 2020 +0200
@@ -1009,6 +1009,20 @@
 </xsl:text>
     <xsl:text>    }
 </xsl:text>
+    <xsl:text>    change_hmi_value(index,opstr) {
+</xsl:text>
+    <xsl:text>        return change_hmi_value(this.get_idx(index), opstr);
+</xsl:text>
+    <xsl:text>    }
+</xsl:text>
+    <xsl:text>
+</xsl:text>
+    <xsl:text>    apply_hmi_value(index, new_val) {
+</xsl:text>
+    <xsl:text>        return apply_hmi_value(this.get_idx(0), new_val);
+</xsl:text>
+    <xsl:text>    }
+</xsl:text>
     <xsl:text>}
 </xsl:text>
     <xsl:text>
@@ -1196,7 +1210,7 @@
 </xsl:text>
     <xsl:text>    }
 </xsl:text>
-    <xsl:text>    apply_hmi_value(this.get_idx(0), 1);
+    <xsl:text>    this.apply_hmi_value(0, 1);
 </xsl:text>
     <xsl:text>},
 </xsl:text>
@@ -1210,7 +1224,7 @@
 </xsl:text>
     <xsl:text>    }
 </xsl:text>
-    <xsl:text>    apply_hmi_value(this.get_idx(0), 0);
+    <xsl:text>    this.apply_hmi_value(0, 0);
 </xsl:text>
     <xsl:text>},
 </xsl:text>
@@ -1445,7 +1459,7 @@
 </xsl:text>
     <xsl:text>        this.close();
 </xsl:text>
-    <xsl:text>        apply_hmi_value(this.get_idx(0), selection);
+    <xsl:text>        this.apply_hmi_value(0, selection);
 </xsl:text>
     <xsl:text>    },
 </xsl:text>
@@ -2138,7 +2152,7 @@
 </xsl:text>
     <xsl:text>    on_op_click: function(opstr) {
 </xsl:text>
-    <xsl:text>        let new_val = change_hmi_value(this.get_idx(0), opstr);
+    <xsl:text>        let new_val = this.change_hmi_value(0, opstr);
 </xsl:text>
     <xsl:text>    },
 </xsl:text>
@@ -2154,7 +2168,7 @@
 </xsl:text>
     <xsl:text>    edit_callback: function(new_val) {
 </xsl:text>
-    <xsl:text>        apply_hmi_value(this.get_idx(0), new_val);
+    <xsl:text>        this.apply_hmi_value(0, new_val);
 </xsl:text>
     <xsl:text>    },
 </xsl:text>
@@ -2958,7 +2972,7 @@
 </xsl:text>
     <xsl:text>    on_click: function(evt) {
 </xsl:text>
-    <xsl:text>        change_hmi_value(this.indexes[0], "="+this.state);
+    <xsl:text>        this.apply_hmi_value(0, this.state);
 </xsl:text>
     <xsl:text>    },
 </xsl:text>
--- a/svghmi/widget_button.ysl2	Mon Aug 03 18:25:23 2020 +0200
+++ b/svghmi/widget_button.ysl2	Tue Aug 04 11:53:39 2020 +0200
@@ -9,14 +9,14 @@
     |         this.active_elt.setAttribute("style", this.active_style);
     |         this.inactive_elt.setAttribute("style", "display:none");
     |     }
-    |     apply_hmi_value(this.get_idx(0), 1);
+    |     this.apply_hmi_value(0, 1);
     | },
     | on_mouse_up: function(evt) {
     |     if (this.active_style && this.inactive_style) {
     |         this.active_elt.setAttribute("style", "display:none");
     |         this.inactive_elt.setAttribute("style", this.inactive_style);
     |     }
-    |     apply_hmi_value(this.get_idx(0), 0);
+    |     this.apply_hmi_value(0, 0);
     | },
     | active_style: undefined,
     | inactive_style: undefined,
--- a/svghmi/widget_dropdown.ysl2	Mon Aug 03 18:25:23 2020 +0200
+++ b/svghmi/widget_dropdown.ysl2	Tue Aug 04 11:53:39 2020 +0200
@@ -38,7 +38,7 @@
     // Called when a menu entry is clicked
     on_selection_click: function(selection) {
         this.close();
-        apply_hmi_value(this.get_idx(0), selection);
+        this.apply_hmi_value(0, selection);
     },
     on_button_click: function() {
         this.open();
--- a/svghmi/widget_input.ysl2	Mon Aug 03 18:25:23 2020 +0200
+++ b/svghmi/widget_input.ysl2	Tue Aug 04 11:53:39 2020 +0200
@@ -26,7 +26,7 @@
     }
     |     },
     |     on_op_click: function(opstr) {
-    |         let new_val = change_hmi_value(this.get_idx(0), opstr);
+    |         let new_val = this.change_hmi_value(0, opstr);
     //     if "$have_value"{
     // |         this.value_elt.textContent = String(new_val);
     //           /* TODO gray out value until refreshed */
@@ -37,7 +37,7 @@
     |     },
 
     |     edit_callback: function(new_val) {
-    |         apply_hmi_value(this.get_idx(0), new_val);
+    |         this.apply_hmi_value(0, new_val);
     //     if "$have_value"{
     // |         this.value_elt.textContent = String(new_val);
     //           /* TODO gray out value until refreshed */
--- a/svghmi/widget_tooglebutton.ysl2	Mon Aug 03 18:25:23 2020 +0200
+++ b/svghmi/widget_tooglebutton.ysl2	Tue Aug 04 11:53:39 2020 +0200
@@ -18,7 +18,7 @@
     |         }
     |     },
     |     on_click: function(evt) {
-    |         change_hmi_value(this.indexes[0], "="+this.state);
+    |         this.apply_hmi_value(0, this.state);
     |     },
     |     active_style: undefined,
     |     inactive_style: undefined,
@@ -27,4 +27,4 @@
     |         this.inactive_style = this.inactive_elt.style.cssText;
     |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
     |     },
-}
\ No newline at end of file
+}
--- a/svghmi/widgets_common.ysl2	Mon Aug 03 18:25:23 2020 +0200
+++ b/svghmi/widgets_common.ysl2	Tue Aug 04 11:53:39 2020 +0200
@@ -109,6 +109,13 @@
              let orig = this.indexes[index];
              return this.offset ? orig + this.offset : orig;
         }
+        change_hmi_value(index,opstr) {
+            return change_hmi_value(this.get_idx(index), opstr);
+        }
+
+        apply_hmi_value(index, new_val) {
+            return apply_hmi_value(this.get_idx(0), new_val);
+        }
     }
     ||
 }