The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
const moment = require("moment")
const {postApi} = require("../../../../../rpdata/api/Post")
module.exports = class { onCreate(input) { this.state = { error: null, loading: false, values: { time: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"), kind: "text", nick: "", text: "", }, } }
change(key, ev) { this.state.values[key] = ev.target.value }
open() { this.state.values.time = moment(new Date()).format("YYYY-MM-DD HH:mm:ss") }
close() { this.emit("close") }
save() { if (this.state.loading) { return }
const values = this.state.values let time = new Date(values.time) if (Number.isNaN(time)) { this.state.error = `Could not parse ${values.time} as date` return } const input = {logId: this.input.logId, time, kind: this.state.values.kind, nick: this.state.values.nick, text: this.state.values.text}
this.state.loading = true postApi.add(input).then(data => { this.emit("added", data) this.emit("close") }).catch(errs => { console.warn("Failed to add post:", errs) this.state.error = "Failed to add post: " + errs[0].message }).then(() => { this.state.loading = false }) } }
|