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.

82 lines
1.7 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. newNick: "",
  10. }
  11. }
  12. }
  13. change(key, ev) {
  14. this.state.values[key] = ev.target.value
  15. }
  16. open() {
  17. }
  18. close() {
  19. this.emit("close")
  20. }
  21. addNick() {
  22. if (this.state.loading) {
  23. return
  24. }
  25. const input = {id: this.input.character.id, nick: this.state.values.newNick}
  26. this.state.loading = true
  27. charactersApi.addNick(input).then((res) => {
  28. this.emit("nicks", res.nicks)
  29. this.state.values = {newNick: ""}
  30. }).catch(errs => {
  31. console.warn("Failed to add nick:", errs)
  32. this.state.error = errs[0].message
  33. }).then(() => {
  34. this.state.loading = false
  35. })
  36. }
  37. selectUnknown(nick) {
  38. if (this.state.loading) {
  39. return
  40. }
  41. const input = {id: this.input.character.id, nick}
  42. this.state.loading = true
  43. charactersApi.addNick(input).then((res) => {
  44. this.emit("nicks", res.nicks)
  45. }).catch(errs => {
  46. this.state.error = errs[0].message
  47. }).then(() => {
  48. this.state.loading = false
  49. })
  50. }
  51. removeNick(nick) {
  52. if (this.state.loading) {
  53. return
  54. }
  55. const input = {id: this.input.character.id, nick}
  56. this.state.loading = true
  57. charactersApi.removeNick(input).then((res) => {
  58. this.emit("nicks", res.nicks)
  59. }).catch(errs => {
  60. console.warn("Failed to remove nick:", errs)
  61. this.state.error = "Failed to remove nick: " + errs[0].message
  62. }).then(() => {
  63. this.state.loading = false
  64. })
  65. }
  66. }