data: Added character list/add/edit/remove
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
const moment = require("moment")
|
||||
|
||||
const {charactersApi} = require("../../../../../rpdata/api/Character")
|
||||
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
error: null,
|
||||
loading: false,
|
||||
values: {
|
||||
name: "",
|
||||
shortName: "",
|
||||
description: "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
change(key, ev) {
|
||||
this.state.values[key] = ev.target.value
|
||||
}
|
||||
|
||||
onInput(input) {
|
||||
this.state.values = {
|
||||
name: input.character.name,
|
||||
shortName: input.character.shortName,
|
||||
description: input.character.description,
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
}
|
||||
|
||||
close() {
|
||||
this.emit("close")
|
||||
}
|
||||
|
||||
save() {
|
||||
if (this.state.loading) {
|
||||
return
|
||||
}
|
||||
|
||||
const input = Object.assign({id: this.input.character.id}, this.state.values)
|
||||
|
||||
this.state.loading = true
|
||||
charactersApi.edit(input).then((res) => {
|
||||
this.emit("edited", res)
|
||||
this.emit("close")
|
||||
}).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,16 @@
|
||||
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
|
||||
<h1>Edit 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="E.g. first/given name" on-change("change", "shortName") value=state.values.shortName />
|
||||
|
||||
<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>
|
||||
Reference in New Issue
Block a user