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.

58 lines
1.1 KiB

  1. const moment = require("moment")
  2. const {fileApi} = require("../../../../../rpdata/api/File")
  3. module.exports = class {
  4. onCreate(input) {
  5. this.state = {
  6. error: null,
  7. loading: false,
  8. values: {
  9. id: "",
  10. name: "",
  11. public: false,
  12. }
  13. }
  14. }
  15. onInput(input) {
  16. this.state.values = {
  17. id: input.file.id,
  18. name: input.file.name,
  19. public: input.file.public,
  20. }
  21. }
  22. change(key, ev) {
  23. this.state.values = Object.assign({}, this.state.values, {[key]: ev.target.value})
  24. }
  25. open() {
  26. }
  27. close() {
  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.file = input.realFile
  36. delete input.realFile
  37. this.state.loading = true
  38. fileApi.editFile(input).then((res) => {
  39. this.emit("edited", res)
  40. this.emit("close")
  41. }).catch(errs => {
  42. console.warn("Failed to add:", errs)
  43. this.state.error = "Failed to add: " + JSON.stringify(errs)
  44. }).then(() => {
  45. this.state.loading = false
  46. })
  47. }
  48. }