31 frequency = 2; |
31 frequency = 2; |
32 |
32 |
33 update_activity() { |
33 update_activity() { |
34 if(this.active) { |
34 if(this.active) { |
35 /* show active */ |
35 /* show active */ |
36 this.active_elt.setAttribute("style", this.active_elt_style); |
36 this.active_elt.style.display = ""; |
37 /* hide inactive */ |
37 /* hide inactive */ |
38 this.inactive_elt.setAttribute("style", "display:none"); |
38 this.inactive_elt.style.display = "none"; |
39 } else { |
39 } else { |
40 /* show inactive */ |
40 /* show inactive */ |
41 this.inactive_elt.setAttribute("style", this.inactive_elt_style); |
41 this.inactive_elt.style.display = ""; |
42 /* hide active */ |
42 /* hide active */ |
43 this.active_elt.setAttribute("style", "display:none"); |
43 this.active_elt.style.display = "none"; |
|
44 } |
|
45 } |
|
46 |
|
47 update_disability() { |
|
48 if(this.disabled) { |
|
49 /* show disabled */ |
|
50 this.disabled_elt.style.display = ""; |
|
51 /* hide inactive */ |
|
52 this.inactive_elt.style.display = "none"; |
|
53 /* hide active */ |
|
54 this.active_elt.style.display = "none"; |
|
55 } else { |
|
56 /* hide disabled */ |
|
57 this.disabled_elt.style.display = "none"; |
|
58 this.update_activity(); |
44 } |
59 } |
45 } |
60 } |
46 |
61 |
47 make_on_click() { |
62 make_on_click() { |
48 let that = this; |
63 let that = this; |
49 const name = this.args[0]; |
64 const name = this.args[0]; |
50 return function(evt){ |
65 return function(evt){ |
51 /* TODO: suport path pointing to local variable whom value |
66 /* TODO: in order to allow jumps to page selected through for exemple a dropdown, |
52 would be an HMI_TREE index to jump to a relative page */ |
67 support path pointing to local variable whom value |
53 const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined; |
68 would be an HMI_TREE index and then jump to a relative page not hard-coded in advance */ |
54 switch_page(name, index); |
69 |
|
70 if(!that.disabled) { |
|
71 const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined; |
|
72 switch_page(name, index); |
|
73 } |
55 } |
74 } |
56 } |
75 } |
57 |
76 |
58 notify_page_change(page_name, index) { |
77 notify_page_change(page_name, index) { |
59 if(this.activable) { |
78 if(this.activable) { |
60 const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
79 const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
61 const ref_name = this.args[0]; |
80 const ref_name = this.args[0]; |
62 this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index); |
81 this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index); |
63 this.update_activity(); |
82 this.update_state(); |
64 } |
83 } |
65 } |
84 } |
66 |
85 |
67 dispatch(value) { |
86 dispatch(value) { |
68 this.disabled = !Number(value); |
87 this.disabled = !Number(value); |
69 if(this.disabled) { |
88 this.update_state(); |
70 /* show disabled */ |
|
71 this.disabled_elt.setAttribute("style", this.disabled_elt_style); |
|
72 /* hide inactive */ |
|
73 this.inactive_elt.setAttribute("style", "display:none"); |
|
74 /* hide active */ |
|
75 this.active_elt.setAttribute("style", "display:none"); |
|
76 } else { |
|
77 /* hide disabled */ |
|
78 this.disabled_elt.setAttribute("style", "display:none"); |
|
79 this.update_activity(); |
|
80 } |
|
81 } |
89 } |
82 || |
90 || |
83 } |
91 } |
84 |
92 |
85 widget_defs("Jump") { |
93 widget_defs("Jump") { |
93 value "$disability"; |
101 value "$disability"; |
94 |
102 |
95 | init: function() { |
103 | init: function() { |
96 | this.element.onclick = this.make_on_click(); |
104 | this.element.onclick = this.make_on_click(); |
97 if "$have_activity" { |
105 if "$have_activity" { |
98 | this.active_elt_style = this.active_elt.getAttribute("style"); |
|
99 | this.inactive_elt_style = this.inactive_elt.getAttribute("style"); |
|
100 | this.activable = true; |
106 | this.activable = true; |
101 } |
107 } |
|
108 if "not($have_disability)" { |
|
109 | this.unsubscribable = true; |
|
110 } |
|
111 > this.update_state = |
102 choose { |
112 choose { |
103 when "$have_disability" { |
113 when "$have_disability" { |
104 | this.disabled_elt_style = this.disabled_elt.getAttribute("style"); |
114 > this.update_disability |
105 } |
115 } |
106 otherwise { |
116 when "$have_activity" { |
107 | this.unsubscribable = true; |
117 > this.update_activity |
108 } |
118 } |
|
119 otherwise > null |
109 } |
120 } |
|
121 > ;\n |
110 | }, |
122 | }, |
|
123 |
111 } |
124 } |
112 |
125 |
113 widget_page("Jump"){ |
126 widget_page("Jump"){ |
114 param "page_desc"; |
127 param "page_desc"; |
115 /* check that given path is compatible with page's reference path */ |
128 /* check that given path is compatible with page's reference path */ |