# HG changeset patch # User Edouard Tisserant # Date 1585228912 -3600 # Node ID 1fcb50af0335c7953672b4282f1c497be0c7f09d # Parent 3f5194bba67d179803cad99681b97864da8eae8c SVGHMI: added Back widget. diff -r 3f5194bba67d -r 1fcb50af0335 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Thu Mar 26 13:33:20 2020 +0100 +++ b/svghmi/gen_index_xhtml.xslt Thu Mar 26 14:21:52 2020 +0100 @@ -694,6 +694,33 @@ + + + on_click: function(evt) { + + console.log("Back !"); + + 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[' + + '].on_click(evt)"); + + }, + + frequency: 5, @@ -890,7 +917,9 @@ const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; - switch_page(this.args[0], index); + const name = this.args[0]; + + switch_page(name, index); }, @@ -1195,6 +1224,8 @@ var need_cache_apply = []; + var jump_history = [[default_page, undefined]]; + function dispatch_value_to_widget(widget, index, value, oldval) { @@ -1731,7 +1762,7 @@ /* TODO LOG ERROR */ - return; + return false; } @@ -1743,7 +1774,7 @@ - switch_subscribed_page(page_name, page_index); + return switch_subscribed_page(page_name, page_index); }; @@ -1935,7 +1966,7 @@ /* TODO LOG ERROR */ - return; + return false; } @@ -1975,6 +2006,14 @@ requestHMIAnimation(); + + + jump_history.push([page_name, page_index]); + + + + return true; + } diff -r 3f5194bba67d -r 1fcb50af0335 svghmi/svghmi.js --- a/svghmi/svghmi.js Thu Mar 26 13:33:20 2020 +0100 +++ b/svghmi/svghmi.js Thu Mar 26 14:21:52 2020 +0100 @@ -3,6 +3,7 @@ var cache = hmitree_types.map(_ignored => undefined); var updates = {}; var need_cache_apply = []; +var jump_history = [[default_page, undefined]]; function dispatch_value_to_widget(widget, index, value, oldval) { try { @@ -271,13 +272,13 @@ if(current_subscribed_page != current_visible_page){ /* page switch already going */ /* TODO LOG ERROR */ - return; + return false; } if(page_name == undefined) page_name = current_subscribed_page; - switch_subscribed_page(page_name, page_index); + return switch_subscribed_page(page_name, page_index); }; function* chain(a,b){ @@ -373,7 +374,7 @@ if(new_desc == undefined){ /* TODO LOG ERROR */ - return; + return false; } if(page_index == undefined){ @@ -393,6 +394,10 @@ current_subscribed_page = page_name; requestHMIAnimation(); + + jump_history.push([page_name, page_index]); + + return true; } function switch_visible_page(page_name) { diff -r 3f5194bba67d -r 1fcb50af0335 svghmi/widget_back.ysl2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/svghmi/widget_back.ysl2 Thu Mar 26 14:21:52 2020 +0100 @@ -0,0 +1,18 @@ +// widget_back.ysl2 + +template "widget[@type='Back']", mode="widget_defs" { + param "hmi_element"; + + | on_click: function(evt) { + | console.log("Back !"); + | 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)"); + | }, +} + diff -r 3f5194bba67d -r 1fcb50af0335 svghmi/widget_jump.ysl2 --- a/svghmi/widget_jump.ysl2 Thu Mar 26 13:33:20 2020 +0100 +++ b/svghmi/widget_jump.ysl2 Thu Mar 26 14:21:52 2020 +0100 @@ -5,7 +5,8 @@ | on_click: function(evt) { | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; - | switch_page(this.args[0], index); + | const name = this.args[0]; + | switch_page(name, index); | }, | init: function() { /* registering event this way does not "click" through svg:use