# HG changeset patch # User Edouard Tisserant # Date 1591262061 -7200 # Node ID 2a21d6060d64a278318699fe939979f8fc404257 # Parent 9442f6a6449ed19a5e2c4d318faf55f1fd29c859 SVGHMI: add "unsubscribable" property to widgets in order to generalize what already happens for jump buttons. In most cases jump buttons do not really subscribe to pointed HMI variable, path is given as a relative page jump path. When widget.unsubscribable is set to true, no subscription is made on page switch, but still offset is updated. This fixes bug happening on relative jump buttons without "disabled" element where offset did not change on relative page switch. diff -r 9442f6a6449e -r 2a21d6060d64 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Wed Jun 03 13:31:55 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Thu Jun 04 11:14:21 2020 +0200 @@ -912,6 +912,8 @@ frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ + unsubscribable = false; + constructor(elt_id,args,indexes,members){ this.element_id = elt_id; @@ -932,7 +934,7 @@ /* remove subsribers */ - for(let index of this.indexes){ + if(!this.unsubscribable) for(let index of this.indexes){ let idx = index + this.offset; @@ -954,7 +956,7 @@ /* add this's subsribers */ - for(let index of this.indexes){ + if(!this.unsubscribable) for(let index of this.indexes){ subscribers[index + new_offset].add(this); @@ -968,7 +970,7 @@ apply_cache() { - for(let index of this.indexes){ + if(!this.unsubscribable) for(let index of this.indexes){ /* dispatch current cache in newly opened page widgets */ @@ -2292,11 +2294,7 @@ - this.sub = function(){}; - - this.unsub = function(){}; - - this.apply_cache = function(){}; + this.unsubscribable = true; diff -r 9442f6a6449e -r 2a21d6060d64 svghmi/widget_jump.ysl2 --- a/svghmi/widget_jump.ysl2 Wed Jun 03 13:31:55 2020 +0200 +++ b/svghmi/widget_jump.ysl2 Thu Jun 04 11:14:21 2020 +0200 @@ -86,9 +86,7 @@ | this.disabled_elt_style = this.disabled_elt.getAttribute("style"); } otherwise { - | this.sub = function(){}; - | this.unsub = function(){}; - | this.apply_cache = function(){}; + | this.unsubscribable = true; } } | }, diff -r 9442f6a6449e -r 2a21d6060d64 svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Wed Jun 03 13:31:55 2020 +0200 +++ b/svghmi/widgets_common.ysl2 Thu Jun 04 11:14:21 2020 +0200 @@ -67,6 +67,7 @@ class Widget { offset = 0; frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ + unsubscribable = false; constructor(elt_id,args,indexes,members){ this.element_id = elt_id; this.element = id(elt_id); @@ -77,7 +78,7 @@ unsub(){ /* remove subsribers */ - for(let index of this.indexes){ + if(!this.unsubscribable) for(let index of this.indexes){ let idx = index + this.offset; subscribers[idx].delete(this); } @@ -88,14 +89,14 @@ /* set the offset because relative */ this.offset = new_offset; /* add this's subsribers */ - for(let index of this.indexes){ + if(!this.unsubscribable) for(let index of this.indexes){ subscribers[index + new_offset].add(this); } need_cache_apply.push(this); } apply_cache() { - for(let index of this.indexes){ + if(!this.unsubscribable) for(let index of this.indexes){ /* dispatch current cache in newly opened page widgets */ let realindex = index+this.offset; let cached_val = cache[realindex];