This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
const moment = require("moment")
|
||||
|
||||
const {commentApi} = require("../../../../../rpdata/api/Comment")
|
||||
const {charactersApi} = require("../../../../../rpdata/api/Character")
|
||||
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
error: null,
|
||||
loading: false,
|
||||
values: {
|
||||
subject: "",
|
||||
source: "",
|
||||
characterName: "",
|
||||
characterId: "",
|
||||
fictionalDate: "",
|
||||
},
|
||||
characters: [],
|
||||
opened: false,
|
||||
}
|
||||
|
||||
this.first = false
|
||||
}
|
||||
|
||||
onMount() {
|
||||
charactersApi.list({author: (this.input.user||{}).name}).then((characters) => {
|
||||
this.state.characters = characters.sort((a,b) => a.name.localeCompare(b.name))
|
||||
})
|
||||
}
|
||||
|
||||
change(key, ev) {
|
||||
this.state.values = Object.assign({}, this.state.values, {[key]: ev.target.value})
|
||||
}
|
||||
|
||||
open() {
|
||||
if (!this.state.opened) {
|
||||
charactersApi.list({author: (this.input.user||{}).name}).then((characters) => {
|
||||
this.state.characters = characters.sort((a,b) => a.name.localeCompare(b.name))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
this.first = false
|
||||
this.state.opened = false
|
||||
this.emit("close")
|
||||
}
|
||||
|
||||
save() {
|
||||
const values = this.state.values
|
||||
|
||||
if (values.source.length < 1) {
|
||||
this.state.error = "You cannot post an empty comment."
|
||||
console.warn(values)
|
||||
return
|
||||
}
|
||||
|
||||
let fictionalDate = new Date(values.fictionalDate + " UTC")
|
||||
if (values.fictionalDate != "") {
|
||||
if (Number.isNaN(fictionalDate)) {
|
||||
this.state.error = `Could not parse ${values.fictionalDate} as date!`
|
||||
return
|
||||
}
|
||||
} else {
|
||||
fictionalDate = null
|
||||
}
|
||||
|
||||
const input = {
|
||||
chapterId: this.input.chapter.id,
|
||||
subject: values.subject,
|
||||
source: values.source,
|
||||
characterName: values.characterName,
|
||||
characterId: values.characterId,
|
||||
fictionalDate: fictionalDate,
|
||||
}
|
||||
|
||||
commentApi.addComment(input).then(chapter => {
|
||||
this.emit("add", chapter)
|
||||
this.emit("close")
|
||||
|
||||
this.state.values = {
|
||||
subject: "",
|
||||
source: "",
|
||||
characterName: "",
|
||||
characterId: "",
|
||||
fictionalDate: "",
|
||||
}
|
||||
}).catch(errs => {
|
||||
console.warn("Failed to add comemnt:", errs)
|
||||
|
||||
this.state.error = "Failed to add comemnt: " + (errs[0]||errs||{}).message || errs
|
||||
}).then(() => {
|
||||
this.state.loading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
|
||||
<h1>Create Chapter</h1>
|
||||
|
||||
<p key="error" class="color-error">${state.error}</p>
|
||||
|
||||
<if(input.chapter.commentMode !== "Chat")>
|
||||
<label>Subject</label>
|
||||
<input key="subject" autofocus placeholder="(Optional)" class="big" on-change("change", "subject") value=state.values.subject />
|
||||
</if>
|
||||
|
||||
<label>Diaply Name</label>
|
||||
<input key="characterName" autofocus placeholder="(Optional)" on-change("change", "characterName") value=state.values.characterName />
|
||||
|
||||
<label>Character ${state.characterId}</label>
|
||||
<select on-change("change", "characterId")>
|
||||
<option value="" selected=state.values.characterId=="">Anonymous</option>
|
||||
<option for(character in state.characters) value=character.id selected=(state.values.characterId==character.id)>${character.name}</option>
|
||||
</select>
|
||||
|
||||
<label>IC Date</label>
|
||||
<input key="icdate" placeholder="(Optional)" on-change("change", "fictionalDate") value=state.values.fictionalDate />
|
||||
|
||||
<label>Content</label>
|
||||
<textarea key="source" placeholder="" class="tall" on-change("change", "source") value=state.values.source />
|
||||
|
||||
<button disabled=state.loading on-click("save")>Save</button>
|
||||
</modal>
|
||||
Reference in New Issue
Block a user