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.
 
 
 
 

69 lines
1.3 KiB

const moment = require("moment")
const {charactersApi} = require("../../../../../rpdata/api/Character")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
values: {
name: "",
nick: "",
shortName: "",
author: "",
description: "",
}
}
}
onInput(input) {
this.state.values = Object.assign({}, this.state.values, {author: input.user.name})
}
change(key, ev) {
this.state.values[key] = ev.target.value
}
open() {
}
close() {
this.emit("close")
}
save() {
if (this.state.loading) {
return
}
const values = Object.assign({}, this.state.values)
if (values.name.length < 2) {
this.state.error = "Name is too short (min: 2)"
return
}
if (values.author == "") {
delete values.author
}
this.state.loading = true
charactersApi.add(this.state.values).then((res) => {
this.emit("added", res)
this.emit("close")
this.state.values = {
name: "",
nick: "",
shortName: "",
author: this.input.user.name,
description: "",
}
}).catch(errs => {
console.warn("Failed to edit:", errs)
this.state.error = "Failed to edit: " + errs[0].message
}).then(() => {
this.state.loading = false
})
}
}