1 // widget_jump.ysl2 |
1 // widget_jump.ysl2 |
2 |
2 |
3 template "widget[@type='Jump']", mode="widget_defs" { |
3 template "widget[@type='Jump']", mode="widget_defs" { |
4 param "hmi_element"; |
4 param "hmi_element"; |
5 |
|
6 /* check that given path is compatible with page's reference path */ |
|
7 if "count(arg) > 0 and count(path) > 0" { |
|
8 const "target_page_name", "arg[1]/@value"; |
|
9 const "target_page_desc", "$hmi_pages_descs[arg[1]/@value = $target_page_name]"; |
|
10 const "target_page_path", "$target_page_desc/path[1]/@value"; |
|
11 if "not(func:same_class_paths($target_page_path, path[1]/@value))" |
|
12 warning > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value»" |
|
13 } |
|
14 /* TODO check that path is also matching in case of implicit local jump (no page name given) */ |
|
15 |
5 |
16 | on_click: function(evt) { |
6 | on_click: function(evt) { |
17 | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
7 | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
18 | switch_page(this.args[0], index); |
8 | switch_page(this.args[0], index); |
19 | }, |
9 | }, |
20 | init: function() { |
10 | init: function() { |
21 /* registering event this way doies not "click" through svg:use |
11 /* registering event this way does not "click" through svg:use |
22 | this.element.onclick = evt => switch_page(this.args[0]); |
12 | this.element.onclick = evt => switch_page(this.args[0]); |
23 event must be registered by adding attribute to element instead |
13 event must be registered by adding attribute to element instead |
24 TODO : generalize mouse event handling by global event capture + getElementsAtPoint() |
14 TODO : generalize mouse event handling by global event capture + getElementsAtPoint() |
25 */ |
15 */ |
26 | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); |
16 | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); |
27 | }, |
17 | }, |
28 } |
18 } |
|
19 |
|
20 template "widget[@type='Jump']", mode="per_page_widget_template"{ |
|
21 param "page_desc"; |
|
22 /* check that given path is compatible with page's reference path */ |
|
23 if "path" { |
|
24 /* when no page name provided, check for same page */ |
|
25 const "target_page_name" choose { |
|
26 when "arg" value "arg[1]/@value"; |
|
27 otherwise value "$page_desc/arg[1]/@value"; |
|
28 } |
|
29 const "target_page_path" choose { |
|
30 when "arg" value "$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value"; |
|
31 otherwise value "$page_desc/path[1]/@value"; |
|
32 } |
|
33 |
|
34 if "not(func:same_class_paths($target_page_path, path[1]/@value))" |
|
35 error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»") |
|
36 } |
|
37 } |