author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sun, 29 Mar 2020 16:11:21 +0200 | |
branch | svghmi |
changeset 2904 | 92d115d8828d |
parent 2903 | 881d0248b3ce |
child 2906 | 3b4a1319da09 |
permissions | -rw-r--r-- |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
1 |
// widget_jump.ysl2 |
2779
75c6a31caca6
SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents:
2763
diff
changeset
|
2 |
|
2903
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
3 |
function "jump_widget_activity" { |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
4 |
param "hmi_element"; |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
5 |
optional_labels("active inactive"); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
6 |
} |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
7 |
|
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
8 |
template "widget[@type='Jump']", mode="widget_defs" { |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
9 |
param "hmi_element"; |
2903
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
10 |
const "opts" call "jump_widget_activity" with "hmi_element", "$hmi_element"; |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
11 |
const "have_opt","string-length($opts)>0"; |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
12 |
value "$opts"; |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
13 |
| on_click: function(evt) { |
2898
a2910281fcb5
SVGHMI: Alow relative relative Jump. (i.e, relative jump from a foreach widget)
Edouard Tisserant
parents:
2883
diff
changeset
|
14 |
| const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
2902 | 15 |
| const name = this.args[0]; |
16 |
| switch_page(name, index); |
|
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
17 |
| }, |
2903
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
18 |
if "$have_opt" { |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
19 |
| notify_page_change: function(page_name, index){ |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
20 |
| const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
21 |
| const ref_name = this.args[0]; |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
22 |
| if((ref_name == undefined || ref_name == page_name) && index == ref_index) { |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
23 |
| console.log("active", ref_name, ref_index, page_name, index); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
24 |
| /* show active */ |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
25 |
| this.active_elt.setAttribute("style", this.active_elt_style); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
26 |
| /* hide inactive */ |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
27 |
| this.inactive_elt.setAttribute("style", "display:none"); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
28 |
| } else { |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
29 |
| console.log("inactive",ref_name, ref_index, page_name, index); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
30 |
| /* show inactive */ |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
31 |
| this.inactive_elt.setAttribute("style", this.inactive_elt_style); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
32 |
| /* hide active */ |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
33 |
| this.active_elt.setAttribute("style", "display:none"); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
34 |
| } |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
35 |
| }, |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
36 |
} |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
37 |
| init: function() { |
2901
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
38 |
/* registering event this way does not "click" through svg:use |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
39 |
| this.element.onclick = evt => switch_page(this.args[0]); |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
40 |
event must be registered by adding attribute to element instead |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
41 |
TODO : generalize mouse event handling by global event capture + getElementsAtPoint() |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
42 |
*/ |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
43 |
| this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); |
2903
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
44 |
if "$have_opt" { |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
45 |
| this.active_elt_style = this.active_elt.getAttribute("style"); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
46 |
| this.inactive_elt_style = this.inactive_elt.getAttribute("style"); |
881d0248b3ce
SVGHMI: Jump widget can now display as active or inactive, if corresponfing "active" and "inactive labeled elements are provided.
Edouard Tisserant
parents:
2902
diff
changeset
|
47 |
} |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
48 |
| }, |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
diff
changeset
|
49 |
} |
2901
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
50 |
|
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
51 |
template "widget[@type='Jump']", mode="per_page_widget_template"{ |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
52 |
param "page_desc"; |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
53 |
/* check that given path is compatible with page's reference path */ |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
54 |
if "path" { |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
55 |
/* when no page name provided, check for same page */ |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
56 |
const "target_page_name" choose { |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
57 |
when "arg" value "arg[1]/@value"; |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
58 |
otherwise value "$page_desc/arg[1]/@value"; |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
59 |
} |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
60 |
const "target_page_path" choose { |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
61 |
when "arg" value "$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value"; |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
62 |
otherwise value "$page_desc/path[1]/@value"; |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
63 |
} |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
64 |
|
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
65 |
if "not(func:same_class_paths($target_page_path, path[1]/@value))" |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
66 |
error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»") |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
67 |
} |
3f5194bba67d
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
Edouard Tisserant
parents:
2900
diff
changeset
|
68 |
} |