# HG changeset patch # User Edouard Tisserant # Date 1585571202 -7200 # Node ID 3b4a1319da09b36493e650f6a0557898379bd905 # Parent 3d7e3866cc51fc89cdf870ad217a1399452f08cc SVGHMI: Jump widget, if it has a 'disabled' labeled element, reflects value of the pointed HMITree variable by showing this element when value is False, and behaving normaly otherwise. diff -r 3d7e3866cc51 -r 3b4a1319da09 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Mar 30 11:06:12 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Mon Mar 30 14:26:42 2020 +0200 @@ -949,15 +949,104 @@ + + + + + + disabled + + + + - + - - + + + + + + + + + + + active: false, + + + disabled: false, + + frequency: 2, + + dispatch: function(value) { + + this.disabled = !Number(value); + + console.log("disbled",value); + + this.update(); + + }, + + + update: function(){ + + + if(this.disabled) { + + /* show disabled */ + + this.disabled_elt.setAttribute("style", this.active_elt_style); + + /* hide inactive */ + + this.inactive_elt.setAttribute("style", "display:none"); + + /* hide active */ + + this.active_elt.setAttribute("style", "display:none"); + + } else { + + /* hide disabled */ + + this.disabled_elt.setAttribute("style", "display:none"); + + + if(this.active) { + + /* show active */ + + this.active_elt.setAttribute("style", this.active_elt_style); + + /* hide inactive */ + + this.inactive_elt.setAttribute("style", "display:none"); + + } else { + + /* show inactive */ + + this.inactive_elt.setAttribute("style", this.inactive_elt_style); + + /* hide active */ + + this.active_elt.setAttribute("style", "display:none"); + + } + + + } + + + }, + + on_click: function(evt) { const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; @@ -968,38 +1057,16 @@ }, - + notify_page_change: function(page_name, index){ const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; const ref_name = this.args[0]; - if((ref_name == undefined || ref_name == page_name) && index == ref_index) { - - console.log("active", ref_name, ref_index, page_name, index); - - /* show active */ - - this.active_elt.setAttribute("style", this.active_elt_style); - - /* hide inactive */ - - this.inactive_elt.setAttribute("style", "display:none"); - - } else { - - console.log("inactive",ref_name, ref_index, page_name, index); - - /* show inactive */ - - this.inactive_elt.setAttribute("style", this.inactive_elt_style); - - /* hide active */ - - this.active_elt.setAttribute("style", "display:none"); - - } + this.active =((ref_name == undefined || ref_name == page_name) && index == ref_index); + + this.update(); }, @@ -1010,15 +1077,52 @@ '].on_click(evt)"); - + this.active_elt_style = this.active_elt.getAttribute("style"); this.inactive_elt_style = this.inactive_elt.getAttribute("style"); + + this.disabled_elt_style = this.disabled_elt.getAttribute("style"); + + }, + + + + + + + + + + + + + + + + + sub: subscribe, + + unsub: unsubscribe, + + apply_cache: widget_apply_cache, + + + + sub: function(){}, + + unsub: function(){}, + + apply_cache: function(){}, + + + + @@ -1903,7 +2007,7 @@ jump_history.push([page_name, page_index]); - if(jump_history.length > 4) + if(jump_history.length > 42) jump_history.shift(); diff -r 3d7e3866cc51 -r 3b4a1319da09 svghmi/widget_jump.ysl2 --- a/svghmi/widget_jump.ysl2 Mon Mar 30 11:06:12 2020 +0200 +++ b/svghmi/widget_jump.ysl2 Mon Mar 30 14:26:42 2020 +0200 @@ -5,33 +5,70 @@ optional_labels("active inactive"); } +function "jump_widget_disability" { + param "hmi_element"; + optional_labels("disabled"); +} + template "widget[@type='Jump']", mode="widget_defs" { param "hmi_element"; - const "opts" call "jump_widget_activity" with "hmi_element", "$hmi_element"; - const "have_opt","string-length($opts)>0"; - value "$opts"; + const "activity" call "jump_widget_activity" with "hmi_element", "$hmi_element"; + const "have_activity","string-length($activity)>0"; + value "$activity"; + const "disability" call "jump_widget_disability" with "hmi_element", "$hmi_element"; + const "have_disability","$have_activity and string-length($disability)>0"; + value "$disability"; + if "$have_activity" { + | active: false, + if "$have_disability" { + | disabled: false, + | frequency: 2, + | dispatch: function(value) { + | this.disabled = !Number(value); + | console.log("disbled",value); + | this.update(); + | }, + } + | update: function(){ + if "$have_disability" { + | if(this.disabled) { + | /* show disabled */ + | this.disabled_elt.setAttribute("style", this.active_elt_style); + | /* hide inactive */ + | this.inactive_elt.setAttribute("style", "display:none"); + | /* hide active */ + | this.active_elt.setAttribute("style", "display:none"); + | } else { + | /* hide disabled */ + | this.disabled_elt.setAttribute("style", "display:none"); + } + | if(this.active) { + | /* show active */ + | this.active_elt.setAttribute("style", this.active_elt_style); + | /* hide inactive */ + | this.inactive_elt.setAttribute("style", "display:none"); + | } else { + | /* show inactive */ + | this.inactive_elt.setAttribute("style", this.inactive_elt_style); + | /* hide active */ + | this.active_elt.setAttribute("style", "display:none"); + | } + if "$have_disability" { + | } + } + | }, + } | on_click: function(evt) { | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; | const name = this.args[0]; | switch_page(name, index); | }, - if "$have_opt" { + if "$have_activity" { | notify_page_change: function(page_name, index){ | const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; | const ref_name = this.args[0]; - | if((ref_name == undefined || ref_name == page_name) && index == ref_index) { - | console.log("active", ref_name, ref_index, page_name, index); - | /* show active */ - | this.active_elt.setAttribute("style", this.active_elt_style); - | /* hide inactive */ - | this.inactive_elt.setAttribute("style", "display:none"); - | } else { - | console.log("inactive",ref_name, ref_index, page_name, index); - | /* show inactive */ - | this.inactive_elt.setAttribute("style", this.inactive_elt_style); - | /* hide active */ - | this.active_elt.setAttribute("style", "display:none"); - | } + | this.active =((ref_name == undefined || ref_name == page_name) && index == ref_index); + | this.update(); | }, } | init: function() { @@ -41,13 +78,37 @@ TODO : generalize mouse event handling by global event capture + getElementsAtPoint() */ | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); - if "$have_opt" { + if "$have_activity" { | this.active_elt_style = this.active_elt.getAttribute("style"); | this.inactive_elt_style = this.inactive_elt.getAttribute("style"); } + if "$have_disability" { + | this.disabled_elt_style = this.disabled_elt.getAttribute("style"); + } | }, } +// default : normal subscribing +template "widget[@type='Jump']", mode="widget_subscribe" { + param "hmi_element"; + const "activity" call "jump_widget_activity" with "hmi_element", "$hmi_element"; + const "have_activity","string-length($activity)>0"; + const "disability" call "jump_widget_disability" with "hmi_element", "$hmi_element"; + const "have_disability","$have_activity and string-length($disability)>0"; + choose { + when "$have_disability" { + | sub: subscribe, + | unsub: unsubscribe, + | apply_cache: widget_apply_cache, + } + otherwise { + | sub: function(){}, + | unsub: function(){}, + | apply_cache: function(){}, + } + } +} + template "widget[@type='Jump']", mode="per_page_widget_template"{ param "page_desc"; /* check that given path is compatible with page's reference path */