data: Added character list/add/edit/remove

This commit is contained in:
2018-10-06 14:26:38 +02:00
parent 0e7f2d0f7e
commit 5b28ce4bc2
28 changed files with 551 additions and 3 deletions
@@ -0,0 +1,69 @@
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
})
}
}
@@ -0,0 +1,22 @@
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
<h1>Add Character</h1>
<p class="color-error">${state.error}</p>
<label>Full Name</label>
<input key="name" placeholder="" class="big" on-change("change", "name") value=state.values.name />
<label>Short Name</label>
<input key="shortName" placeholder="(Optional)" on-change("change", "shortName") value=state.values.shortName />
<label>IRC Nick</label>
<input key="nick" placeholder="" class="big" on-change("change", "nick") value=state.values.nick />
<label>Author</label>
<input key="author" placeholder=(input.user.name) on-change("change", "author") value=state.values.author />
<label>Description</label>
<textarea key="description" placeholder="Description" on-change("change", "description") value=state.values.description />
<button disabled=state.loading on-click("save")>Save character!</button>
</modal>