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.

62 lines
1.2 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. this.state.values = {
  19. title: input.log.title,
  20. event: input.log.eventName,
  21. description: input.log.description,
  22. open: input.log.open,
  23. }
  24. }
  25. change(key, ev) {
  26. this.state.values[key] = ev.target.value
  27. this.state.values = Object.assign({}, this.state.values)
  28. }
  29. open() {
  30. this.state.loading = false
  31. }
  32. close() {
  33. this.first = false
  34. this.emit("close")
  35. }
  36. save() {
  37. if (this.state.loading) {
  38. return
  39. }
  40. const input = Object.assign({id: this.input.log.id}, this.state.values)
  41. this.state.loading = true
  42. logsApi.edit(input).then(data => {
  43. this.emit("edited", data)
  44. this.emit("close")
  45. }).catch(errs => {
  46. console.warn("Failed to edit:", errs)
  47. this.state.error = "Failed to edit: " + errs[0].message
  48. }).then(() => {
  49. this.state.loading = false
  50. })
  51. }
  52. }