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.

68 lines
1.3 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. nick: "",
  11. shortName: "",
  12. author: "",
  13. description: "",
  14. }
  15. }
  16. }
  17. onInput(input) {
  18. this.state.values = Object.assign({}, this.state.values, {author: input.user.name})
  19. }
  20. change(key, ev) {
  21. this.state.values[key] = ev.target.value
  22. }
  23. open() {
  24. }
  25. close() {
  26. this.emit("close")
  27. }
  28. save() {
  29. if (this.state.loading) {
  30. return
  31. }
  32. const values = Object.assign({}, this.state.values)
  33. if (values.name.length < 2) {
  34. this.state.error = "Name is too short (min: 2)"
  35. return
  36. }
  37. if (values.author == "") {
  38. delete values.author
  39. }
  40. this.state.loading = true
  41. charactersApi.add(this.state.values).then((res) => {
  42. this.emit("added", res)
  43. this.emit("close")
  44. this.state.values = {
  45. name: "",
  46. nick: "",
  47. shortName: "",
  48. author: this.input.user.name,
  49. description: "",
  50. }
  51. }).catch(errs => {
  52. console.warn("Failed to edit:", errs)
  53. this.state.error = "Failed to edit: " + errs[0].message
  54. }).then(() => {
  55. this.state.loading = false
  56. })
  57. }
  58. }