diff --git a/marko/page/logs/components/add-log-modal/component.js b/marko/page/logs/components/add-log-modal/component.js new file mode 100644 index 0000000..8127493 --- /dev/null +++ b/marko/page/logs/components/add-log-modal/component.js @@ -0,0 +1,61 @@ +const moment = require("moment") + +const {logsApi} = require("../../../../../rpdata/api/Log") + +module.exports = class { + onCreate(input) { + this.state = { + error: null, + loading: false, + values: { + date: "", + channel: "", + title: "", + event: "", + description: "", + open: false, + }, + } + + this.first = false + } + + 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({}, this.state.values) + + input.date = new Date(input.date) + if (Number.isNaN(input.date)) { + this.state.error = "Invalid date" + return + } + + this.state.loading = true + logsApi.add(input).then(log => { + window.location = `/logs/${log.id}/` + }).catch(errs => { + console.warn("Failed to add:", errs) + + this.state.error = "Failed to add: " + errs[0].message + }).then(() => { + this.state.loading = false + }) + } +} \ No newline at end of file diff --git a/marko/page/logs/components/add-log-modal/index.marko b/marko/page/logs/components/add-log-modal/index.marko new file mode 100644 index 0000000..818065d --- /dev/null +++ b/marko/page/logs/components/add-log-modal/index.marko @@ -0,0 +1,32 @@ +import moment from "moment" + + +

Add Log

+ +

${state.error}

+ + + + + + + + + + + + + + +