author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sun, 02 May 2021 23:01:08 +0200 | |
branch | svghmi |
changeset 3232 | 7bdb766c2a4d |
parent 3018 | 22b969b409b0 |
child 3241 | fe945f1f48b7 |
permissions | -rw-r--r-- |
3014
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
1 |
// widget_multistate.ysl2 |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
2 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3018
diff
changeset
|
3 |
widget_class("MultiState") |
3014
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
4 |
|| |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
5 |
frequency = 5; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
6 |
state = 0; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
7 |
dispatch(value) { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
8 |
this.state = value; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
9 |
for(let choice of this.choices){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
10 |
if(this.state != choice.value){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
11 |
choice.elt.setAttribute("style", "display:none"); |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
12 |
} else { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
13 |
choice.elt.setAttribute("style", choice.style); |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
14 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
15 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
16 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
17 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
18 |
on_click(evt) { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
19 |
//get current selected value |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
20 |
let next_ind; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
21 |
for(next_ind=0; next_ind<this.choices.length; next_ind++){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
22 |
if(this.state == this.choices[next_ind].value){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
23 |
next_ind = next_ind + 1; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
24 |
break; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
25 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
26 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
27 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
28 |
//get next selected value |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
29 |
if(this.choices.length > next_ind){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
30 |
this.state = this.choices[next_ind].value; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
31 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
32 |
else{ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
33 |
this.state = this.choices[0].value; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
34 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
35 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
36 |
//post value to plc |
3018 | 37 |
this.apply_hmi_value(0, this.state); |
3014
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
38 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
39 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
40 |
init() { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
41 |
this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
42 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
43 |
|| |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
44 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3018
diff
changeset
|
45 |
widget_defs("MultiState") { |
3014
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
46 |
param "hmi_element"; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
47 |
| choices: [ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
48 |
const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
49 |
foreach "$result_svg_ns//*[@id = $hmi_element/@id]//*[regexp:test(@inkscape:label,$regex)]" { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
50 |
const "literal", "regexp:match(@inkscape:label,$regex)[2]"; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
51 |
| { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
52 |
| elt:id("«@id»"), |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
53 |
| style:"«@style»", |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
54 |
| value:«$literal» |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
55 |
| }`if "position()!=last()" > ,` |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
56 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
57 |
| ], |
3018 | 58 |
} |