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.

65 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. 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 = "Failed to add nick: " + errs[0].message
  33. }).then(() => {
  34. this.state.loading = false
  35. })
  36. }
  37. removeNick(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.removeNick(input).then((res) => {
  44. this.emit("nicks", res.nicks)
  45. }).catch(errs => {
  46. console.warn("Failed to remove nick:", errs)
  47. this.state.error = "Failed to remove nick: " + errs[0].message
  48. }).then(() => {
  49. this.state.loading = false
  50. })
  51. }
  52. }