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.

66 lines
1.3 KiB

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