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.

60 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. date: "",
  10. channel: "",
  11. title: "",
  12. event: "",
  13. description: "",
  14. open: false,
  15. },
  16. }
  17. this.first = false
  18. }
  19. change(key, ev) {
  20. this.state.values[key] = ev.target.value
  21. this.state.values = Object.assign({}, this.state.values)
  22. }
  23. open() {
  24. this.state.loading = false
  25. }
  26. close() {
  27. this.first = false
  28. this.emit("close")
  29. }
  30. save() {
  31. if (this.state.loading) {
  32. return
  33. }
  34. const input = Object.assign({}, this.state.values)
  35. input.date = new Date(input.date)
  36. if (Number.isNaN(input.date)) {
  37. this.state.error = "Invalid date"
  38. return
  39. }
  40. this.state.loading = true
  41. logsApi.add(input).then(log => {
  42. window.location = `/logs/${log.id}/`
  43. }).catch(errs => {
  44. console.warn("Failed to add:", errs)
  45. this.state.error = "Failed to add: " + errs[0].message
  46. }).then(() => {
  47. this.state.loading = false
  48. })
  49. }
  50. }