Files
owl/web/static/src/ts/widgets/Discuss.ts
T

69 lines
2.2 KiB
TypeScript
Raw Normal View History

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";
import { Clock } from "./clock";
import { Counter } from "./counter";
const template = `
2019-01-25 10:25:42 +01:00
<div class="o_discuss">
<span>DISCUSS!!</span>
<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-28 12:13:03 +01:00
<button t-on-click="toggleColor">Toggle Color</button>
2019-01-26 18:12:54 +01:00
<button t-on-click="updateState({})">Rerender this widget</button>
2019-01-29 15:19:02 +01:00
<input t-ref="textinput"/>
<t t-if="state.validcounter">
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>
<t t-widget="Counter" t-ref="counter2" t-props="{initialState:400}"/>
</t>
<t t-else="1">
<t t-widget="Clock"/>
</t>
2019-01-28 12:13:03 +01:00
<t t-widget="ColorWidget" t-props="{color: state.color}"/>
2019-01-29 16:13:05 +01:00
<button t-on-click="addNotif(false)">Add notif</button>
<button t-on-click="addNotif(true)">Add sticky notif</button>
</div>
`;
2019-01-28 21:32:21 +01:00
export class Discuss extends Widget<Env, {}> {
name = "discuss";
template = template;
2019-01-28 12:13:03 +01:00
widgets = { Clock, Counter, ColorWidget };
state = { validcounter: true, color: "red" };
2019-01-25 10:25:42 +01:00
mounted() {}
resetCounter(ev: MouseEvent) {
2019-01-25 10:25:42 +01:00
if (this.refs.counter instanceof Counter) {
this.refs.counter.updateState({ counter: 3 });
}
}
resetCounterAsync(ev: MouseEvent) {
setTimeout(() => {
if (this.refs.counter2 instanceof Counter) {
this.refs.counter2.updateState({ counter: 300 });
2019-01-25 10:25:42 +01:00
}
}, 3000);
}
toggle() {
this.updateState({ validcounter: !this.state.validcounter });
}
2019-01-28 12:13:03 +01:00
toggleColor() {
const newColor = this.state.color === "red" ? "blue" : "red";
this.updateState({ color: newColor });
}
2019-01-29 15:19:02 +01:00
2019-01-29 16:13:05 +01:00
addNotif(sticky: boolean) {
2019-01-29 15:19:02 +01:00
const text = (<any>this.refs.textinput).value;
const message = `It is now ${new Date().toLocaleTimeString()}.<br/> Msg: ${text}`;
2019-01-29 16:13:05 +01:00
this.env.notifications.add({ title: "hey", message: message, sticky });
2019-01-29 15:19:02 +01:00
}
2019-01-28 12:13:03 +01:00
}
2019-01-28 21:32:21 +01:00
class ColorWidget extends Widget<Env, { color: "red" | "blue" }> {
2019-01-28 12:13:03 +01:00
name = "colorwidget";
template = `<div>Current Color: <t t-esc="props.color"/></div>`;
}