const moment = require("moment") const {fileApi} = require("../../../../../rpdata/api/File") module.exports = class { onCreate(input) { this.state = { error: null, loading: false, values: { id: "", name: "", public: false, } } } onInput(input) { this.state.values = { id: input.file.id, name: input.file.name, public: input.file.public, } } change(key, ev) { 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.editFile(input).then((res) => { this.emit("edited", 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 }) } }