2019-01-24 10:33:11 +01:00
|
|
|
import { Widget } from "../core/widget";
|
2019-01-23 14:28:41 +01:00
|
|
|
import { Env } from "../env";
|
2019-01-24 13:48:31 +01:00
|
|
|
import { Clock } from "./clock";
|
|
|
|
|
import { Counter } from "./counter";
|
2019-01-22 10:38:44 +01:00
|
|
|
|
|
|
|
|
const template = `
|
2019-01-25 10:25:42 +01:00
|
|
|
<div class="o_discuss">
|
2019-01-24 13:48:31 +01:00
|
|
|
<span>DISCUSS!!</span>
|
2019-01-26 08:40:09 +01:00
|
|
|
<button t-on-click="resetCounter">Reset first counter</button>
|
|
|
|
|
<button t-on-click="resetCounterAsync">Reset counter 2 in 3s</button>
|
|
|
|
|
<button t-on-click="toggle">Toggle Clock/counters</button>
|
2019-01-22 10:38:44 +01:00
|
|
|
<input/>
|
|
|
|
|
<t t-if="state.validcounter">
|
|
|
|
|
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>
|
2019-01-26 08:40:09 +01:00
|
|
|
<t t-widget="Counter" t-ref="counter2" t-props="{initialState:400}"/>
|
2019-01-22 10:38:44 +01:00
|
|
|
</t>
|
|
|
|
|
<t t-else="1">
|
2019-01-24 13:48:31 +01:00
|
|
|
<t t-widget="Clock"/>
|
2019-01-22 10:38:44 +01:00
|
|
|
</t>
|
|
|
|
|
<div ref="target"/>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
2019-01-24 10:33:11 +01:00
|
|
|
export class Discuss extends Widget<Env> {
|
2019-01-22 10:38:44 +01:00
|
|
|
name = "discuss";
|
|
|
|
|
template = template;
|
2019-01-24 13:48:31 +01:00
|
|
|
widgets = { Clock, Counter };
|
2019-01-22 10:38:44 +01:00
|
|
|
state = { validcounter: true };
|
|
|
|
|
|
2019-01-25 10:25:42 +01:00
|
|
|
mounted() {}
|
2019-01-22 10:38:44 +01:00
|
|
|
resetCounter(ev: MouseEvent) {
|
2019-01-25 10:25:42 +01:00
|
|
|
if (this.refs.counter instanceof Counter) {
|
|
|
|
|
this.refs.counter.updateState({ counter: 3 });
|
|
|
|
|
}
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetCounterAsync(ev: MouseEvent) {
|
|
|
|
|
setTimeout(() => {
|
2019-01-26 08:40:09 +01:00
|
|
|
if (this.refs.counter2 instanceof Counter) {
|
|
|
|
|
this.refs.counter2.updateState({ counter: 300 });
|
2019-01-25 10:25:42 +01:00
|
|
|
}
|
2019-01-22 10:38:44 +01:00
|
|
|
}, 3000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggle() {
|
2019-01-26 08:40:09 +01:00
|
|
|
this.updateState({ validcounter: !this.state.validcounter });
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|
|
|
|
|
}
|