logs-content: Added edit log form.

This commit is contained in:
2018-10-01 21:02:03 +02:00
parent 640244faf4
commit fd737fbbdb
9 changed files with 221 additions and 13 deletions
@@ -0,0 +1,68 @@
const moment = require("moment")
const {logsApi} = require("../../../../../rpdata/api/Log")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
values: {
title: "",
event: "",
description: "",
open: false,
},
}
this.first = false
}
onInput(input) {
if (input.log && !this.first) {
this.state.values = {
title: input.log.title,
event: input.log.eventName,
description: input.log.description,
open: input.log.open,
}
this.first = true
}
}
change(key, ev) {
this.state.values[key] = ev.target.value
this.state.values = Object.assign({}, this.state.values)
}
open() {
this.state.loading = false
}
close() {
this.first = false
this.emit("close")
}
save() {
if (this.state.loading) {
return
}
const input = Object.assign({id: this.input.log.id}, this.state.values)
console.log(input)
this.state.loading = true
logsApi.edit(input).then(data => {
this.emit("edited", data)
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,25 @@
import moment from "moment"
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
<h1>Edit Log</h1>
<p key="error" class="color-error">${state.error}</p>
<label>Title</label>
<input key="title" placeholder=(input.log.channel.name + " – " + moment(input.log.date).format("MMMM D, YYYY")) class="big" on-change("change", "title") value=state.values.title />
<label>Event Name</label>
<input key="event" placeholder="(Optional)" class="big" on-change("change", "event") value=state.values.event />
<label>Description</label>
<textarea key="description" placeholder="(Optional)" on-change("change", "description") value=state.values.description />
<toggle value=state.values.open on="Open" off="Closed"
onDesc=("New posts in "+input.log.channel.name+" will end up here.")
offDesc="The logbot will not append to this log."
on-change("change", "open") />
<p if(state.values.open) key="warning" class="color-danger">Opening a log will close all others for the same channels.</p>
<button disabled=state.loading on-click("save")>Save</button>
</modal>