# HG changeset patch # User Edouard Tisserant # Date 1596534819 -7200 # Node ID 705e34c6fe93c813fa027a9261e8e4b61cbd5cb7 # Parent 9771a724af09e0b0a98d613e7fd2e18ccfd3a3db SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class. diff -r 9771a724af09 -r 705e34c6fe93 svghmi/gen_index_xhtml.xslt --- 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 @@ } + 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); + + } + } @@ -1196,7 +1210,7 @@ } - apply_hmi_value(this.get_idx(0), 1); + this.apply_hmi_value(0, 1); }, @@ -1210,7 +1224,7 @@ } - apply_hmi_value(this.get_idx(0), 0); + this.apply_hmi_value(0, 0); }, @@ -1445,7 +1459,7 @@ this.close(); - apply_hmi_value(this.get_idx(0), selection); + this.apply_hmi_value(0, selection); }, @@ -2138,7 +2152,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); }, @@ -2154,7 +2168,7 @@ edit_callback: function(new_val) { - apply_hmi_value(this.get_idx(0), new_val); + this.apply_hmi_value(0, new_val); }, @@ -2958,7 +2972,7 @@ on_click: function(evt) { - change_hmi_value(this.indexes[0], "="+this.state); + this.apply_hmi_value(0, this.state); }, diff -r 9771a724af09 -r 705e34c6fe93 svghmi/widget_button.ysl2 --- 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, diff -r 9771a724af09 -r 705e34c6fe93 svghmi/widget_dropdown.ysl2 --- 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(); diff -r 9771a724af09 -r 705e34c6fe93 svghmi/widget_input.ysl2 --- 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 */ diff -r 9771a724af09 -r 705e34c6fe93 svghmi/widget_tooglebutton.ysl2 --- 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 +} diff -r 9771a724af09 -r 705e34c6fe93 svghmi/widgets_common.ysl2 --- 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); + } } || }