edouard@2883: // widget_jump.ysl2 Edouard@2779: Edouard@2903: function "jump_widget_activity" { Edouard@2903: param "hmi_element"; Edouard@2903: optional_labels("active inactive"); Edouard@2903: } Edouard@2903: Edouard@2906: function "jump_widget_disability" { Edouard@2906: param "hmi_element"; Edouard@2906: optional_labels("disabled"); Edouard@2906: } Edouard@2906: edouard@2883: template "widget[@type='Jump']", mode="widget_defs" { edouard@2883: param "hmi_element"; Edouard@2906: const "activity" call "jump_widget_activity" with "hmi_element", "$hmi_element"; Edouard@2906: const "have_activity","string-length($activity)>0"; Edouard@2906: value "$activity"; Edouard@2906: const "disability" call "jump_widget_disability" with "hmi_element", "$hmi_element"; Edouard@2906: const "have_disability","$have_activity and string-length($disability)>0"; Edouard@2906: value "$disability"; Edouard@2906: if "$have_activity" { Edouard@2906: | active: false, Edouard@2906: if "$have_disability" { Edouard@2906: | disabled: false, Edouard@2906: | frequency: 2, Edouard@2906: | dispatch: function(value) { Edouard@2906: | this.disabled = !Number(value); Edouard@2906: | this.update(); Edouard@2906: | }, Edouard@2906: } Edouard@2906: | update: function(){ Edouard@2906: if "$have_disability" { Edouard@2906: | if(this.disabled) { Edouard@2906: | /* show disabled */ Edouard@2906: | this.disabled_elt.setAttribute("style", this.active_elt_style); Edouard@2906: | /* hide inactive */ Edouard@2906: | this.inactive_elt.setAttribute("style", "display:none"); Edouard@2906: | /* hide active */ Edouard@2906: | this.active_elt.setAttribute("style", "display:none"); Edouard@2906: | } else { Edouard@2906: | /* hide disabled */ Edouard@2906: | this.disabled_elt.setAttribute("style", "display:none"); Edouard@2906: } Edouard@2906: | if(this.active) { Edouard@2906: | /* show active */ Edouard@2906: | this.active_elt.setAttribute("style", this.active_elt_style); Edouard@2906: | /* hide inactive */ Edouard@2906: | this.inactive_elt.setAttribute("style", "display:none"); Edouard@2906: | } else { Edouard@2906: | /* show inactive */ Edouard@2906: | this.inactive_elt.setAttribute("style", this.inactive_elt_style); Edouard@2906: | /* hide active */ Edouard@2906: | this.active_elt.setAttribute("style", "display:none"); Edouard@2906: | } Edouard@2906: if "$have_disability" { Edouard@2906: | } Edouard@2906: } Edouard@2906: | }, Edouard@2906: } edouard@2883: | on_click: function(evt) { Edouard@2898: | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; Edouard@2902: | const name = this.args[0]; Edouard@2902: | switch_page(name, index); edouard@2883: | }, Edouard@2906: if "$have_activity" { Edouard@2903: | notify_page_change: function(page_name, index){ Edouard@2903: | const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; Edouard@2903: | const ref_name = this.args[0]; Edouard@2906: | this.active =((ref_name == undefined || ref_name == page_name) && index == ref_index); Edouard@2906: | this.update(); Edouard@2903: | }, Edouard@2903: } edouard@2883: | init: function() { Edouard@2901: /* registering event this way does not "click" through svg:use edouard@2883: | this.element.onclick = evt => switch_page(this.args[0]); edouard@2883: event must be registered by adding attribute to element instead edouard@2883: TODO : generalize mouse event handling by global event capture + getElementsAtPoint() edouard@2883: */ edouard@2883: | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); Edouard@2906: if "$have_activity" { Edouard@2903: | this.active_elt_style = this.active_elt.getAttribute("style"); Edouard@2903: | this.inactive_elt_style = this.inactive_elt.getAttribute("style"); Edouard@2903: } edouard@2953: choose { edouard@2953: when "$have_disability" { Edouard@2906: | this.disabled_elt_style = this.disabled_elt.getAttribute("style"); edouard@2953: } edouard@2953: otherwise { Edouard@2980: | this.unsubscribable = true; edouard@2953: } Edouard@2906: } edouard@2883: | }, Edouard@2753: } Edouard@2901: Edouard@2901: template "widget[@type='Jump']", mode="per_page_widget_template"{ Edouard@2901: param "page_desc"; Edouard@2901: /* check that given path is compatible with page's reference path */ Edouard@2901: if "path" { Edouard@2901: /* when no page name provided, check for same page */ Edouard@2901: const "target_page_name" choose { Edouard@2901: when "arg" value "arg[1]/@value"; Edouard@2901: otherwise value "$page_desc/arg[1]/@value"; Edouard@2901: } Edouard@2901: const "target_page_path" choose { Edouard@2901: when "arg" value "$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value"; Edouard@2901: otherwise value "$page_desc/path[1]/@value"; Edouard@2901: } Edouard@2901: Edouard@2901: if "not(func:same_class_paths($target_page_path, path[1]/@value))" Edouard@2901: error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»") Edouard@2901: } Edouard@2901: } edouard@2942: edouard@2943: emit "declarations:jump" edouard@2942: || edouard@2942: var jumps_need_update = false; edouard@2942: var jump_history = [[default_page, undefined]]; edouard@2942: edouard@2942: function update_jumps() { edouard@2942: page_desc[current_visible_page].jumps.map(w=>w.notify_page_change(current_visible_page,current_page_index)); edouard@2942: jumps_need_update = false; edouard@2942: }; edouard@2942: edouard@2942: || edouard@2942: