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.
61 lines
1.2 KiB
61 lines
1.2 KiB
const moment = require("moment")
|
|
|
|
const {fileApi} = require("../../../../../rpdata/api/File")
|
|
|
|
module.exports = class {
|
|
onCreate(input) {
|
|
this.state = {
|
|
error: null,
|
|
loading: false,
|
|
values: {
|
|
file: null,
|
|
name: "",
|
|
public: false,
|
|
|
|
realFile: null,
|
|
}
|
|
}
|
|
}
|
|
|
|
change(key, ev) {
|
|
if (key === "file") {
|
|
this.state.values = Object.assign({}, this.state.values, {
|
|
[key]: ev.target.value,
|
|
realFile: ev.target.files[0],
|
|
name: ev.target.files[0].name,
|
|
})
|
|
} else {
|
|
this.state.values = Object.assign({}, this.state.values, {[key]: ev.target.value})
|
|
}
|
|
}
|
|
|
|
open() {
|
|
|
|
}
|
|
|
|
close() {
|
|
this.emit("close")
|
|
}
|
|
|
|
save() {
|
|
if (this.state.loading) {
|
|
return
|
|
}
|
|
|
|
const input = Object.assign({}, this.state.values)
|
|
input.file = input.realFile
|
|
delete input.realFile
|
|
|
|
this.state.loading = true
|
|
fileApi.uploadFile(input).then((res) => {
|
|
this.emit("added", res)
|
|
this.emit("close")
|
|
}).catch(errs => {
|
|
console.warn("Failed to add:", errs)
|
|
|
|
this.state.error = "Failed to add: " + JSON.stringify(errs)
|
|
}).then(() => {
|
|
this.state.loading = false
|
|
})
|
|
}
|
|
}
|