The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

  1. const moment = require("moment")
  2. const {chapterApi} = require("../../../../../rpdata/api/Chapter")
  3. module.exports = class {
  4. onCreate(input) {
  5. this.state = {
  6. error: null,
  7. loading: false,
  8. values: {
  9. title: "",
  10. source: "",
  11. fictionalDate: "",
  12. },
  13. }
  14. this.first = false
  15. }
  16. onInput(input) {
  17. if (input.chapter && !this.first) {
  18. let {fictionalDate, title, source} = input.chapter
  19. if (fictionalDate != null) {
  20. fictionalDate = moment.utc(fictionalDate).format("MMM D, YYYY")
  21. }
  22. this.state.values = {fictionalDate, title, source}
  23. }
  24. }
  25. change(key, ev) {
  26. this.state.values[key] = ev.target.value
  27. }
  28. open() {
  29. }
  30. close() {
  31. this.first = false
  32. this.emit("close")
  33. }
  34. save() {
  35. const values = this.state.values
  36. let fictionalDate = new Date(values.fictionalDate + " UTC")
  37. if (values.fictionalDate != "") {
  38. if (Number.isNaN(fictionalDate)) {
  39. this.state.error = `Could not parse ${values.fictionalDate} as date`
  40. return
  41. }
  42. } else {
  43. fictionalDate = null
  44. }
  45. const input = {id: this.input.chapter.id, title: values.title, source: values.source}
  46. if (fictionalDate != null) {
  47. input.fictionalDate = fictionalDate
  48. } else {
  49. input.clearFictionalDate = true
  50. }
  51. chapterApi.editChapter(input).then(data => {
  52. this.emit("edit", data)
  53. this.emit("close")
  54. }).catch(errs => {
  55. console.warn("Failed to edit:", errs)
  56. this.state.error = "Failed to edit: " + errs[0].message
  57. }).then(() => {
  58. this.state.loading = false
  59. })
  60. }
  61. }