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