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

60 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Clock } from "./clock";
import { Counter } from "./counter";
2019-02-04 21:09:17 +01:00
import { Widget } from "./widget";
2019-02-04 21:09:17 +01:00
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
interface State {
validcounter: boolean;
color: "red" | "blue";
}
//------------------------------------------------------------------------------
// Discuss
//------------------------------------------------------------------------------
export class Discuss extends Widget<{}, State> {
template = "web.discuss";
widgets = { Clock, Counter, ColorWidget };
2019-02-05 08:56:33 +01:00
state: State = { validcounter: true, color: "red" };
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-02-04 21:09:17 +01:00
class ColorWidget extends Widget<{ color: "red" | "blue" }, {}> {
inlineTemplate = `
<div t-name="colorwidget">
<span>Current Color: </span>
<t t-esc="props.color"/>
</div>`;
}