2019-01-24 13:48:31 +01:00
|
|
|
import { Clock } from "./clock";
|
|
|
|
|
import { Counter } from "./counter";
|
2019-02-04 21:09:17 +01:00
|
|
|
import { Widget } from "./widget";
|
2019-01-22 10:38:44 +01:00
|
|
|
|
2019-02-04 21:09:17 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Types
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
|
validcounter: boolean;
|
|
|
|
|
color: "red" | "blue";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Discuss
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
export class Discuss extends Widget<{}, State> {
|
2019-02-03 14:07:25 +01:00
|
|
|
template = "web.discuss";
|
2019-01-31 15:14:26 +01:00
|
|
|
widgets = { Clock, Counter, ColorWidget };
|
|
|
|
|
state = { validcounter: true, color: "red" };
|
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
|
|
|
}
|
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" }, {}> {
|
2019-02-03 14:07:25 +01:00
|
|
|
inlineTemplate = `
|
|
|
|
|
<div t-name="colorwidget">
|
|
|
|
|
<span>Current Color: </span>
|
|
|
|
|
<t t-esc="props.color"/>
|
|
|
|
|
</div>`;
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|