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.

67 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. console.log(input)
  45. this.state.loading = true
  46. logsApi.edit(input).then(data => {
  47. this.emit("edited", data)
  48. this.emit("close")
  49. }).catch(errs => {
  50. console.warn("Failed to edit:", errs)
  51. this.state.error = "Failed to edit: " + errs[0].message
  52. }).then(() => {
  53. this.state.loading = false
  54. })
  55. }
  56. }