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.

53 lines
1.1 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. }
  15. onInput(input) {
  16. if (input.chapter && !this.first) {
  17. let {fictionalDate, title, source} = input.chapter
  18. if (fictionalDate != null) {
  19. fictionalDate = moment.utc(fictionalDate).format("MMM D, YYYY")
  20. }
  21. this.state.values = {fictionalDate, title, source}
  22. }
  23. }
  24. change(key, ev) {
  25. this.state.values[key] = ev.target.value
  26. }
  27. open() {
  28. }
  29. close() {
  30. this.emit("close")
  31. }
  32. doIt() {
  33. chapterApi.removeChapter({id: this.input.chapter.id}).then(() => {
  34. this.emit("remove")
  35. this.emit("close")
  36. }).catch(errs => {
  37. console.warn("Failed to delete:", errs)
  38. this.state.error = "Failed to delete: " + errs.message || errs[0].message
  39. }).then(() => {
  40. this.state.loading = false
  41. })
  42. }
  43. }