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.

55 lines
1.1 KiB

  1. const moment = require("moment")
  2. const {storyApi} = require("../../../../../rpdata/api/Story")
  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. this.state.loading = true
  34. storyApi.remove({id: this.input.story.id}).then(() => {
  35. this.emit("remove")
  36. this.emit("close")
  37. }).catch(errs => {
  38. console.warn("Failed to delete:", errs)
  39. this.state.error = "Failed to delete: " + errs.message || errs[0].message
  40. }).then(() => {
  41. this.state.loading = false
  42. })
  43. }
  44. }