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.

56 lines
1.1 KiB

  1. const moment = require("moment")
  2. const {charactersApi} = require("../../../../../rpdata/api/Character")
  3. module.exports = class {
  4. onCreate(input) {
  5. this.state = {
  6. error: null,
  7. loading: false,
  8. values: {
  9. name: "",
  10. shortName: "",
  11. description: "",
  12. }
  13. }
  14. }
  15. change(key, ev) {
  16. this.state.values[key] = ev.target.value
  17. }
  18. onInput(input) {
  19. this.state.values = {
  20. name: input.character.name,
  21. shortName: input.character.shortName,
  22. description: input.character.description,
  23. }
  24. }
  25. open() {
  26. }
  27. close() {
  28. this.emit("close")
  29. }
  30. save() {
  31. if (this.state.loading) {
  32. return
  33. }
  34. const input = Object.assign({id: this.input.character.id}, this.state.values)
  35. this.state.loading = true
  36. charactersApi.edit(input).then((res) => {
  37. this.emit("edited", res)
  38. this.emit("close")
  39. }).catch(errs => {
  40. console.warn("Failed to edit:", errs)
  41. this.state.error = "Failed to edit: " + errs[0].message
  42. }).then(() => {
  43. this.state.loading = false
  44. })
  45. }
  46. }