1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import { session } from 'app/session'
import actions from 'app/actions'
import { capitalize } from 'app/utils'
import { TextInput, LabelDescription, Select, TextArea, Checkbox, SubmitButton, Loader, FileInputField } from 'app/common'
export default class MediaFileForm extends Component {
state = {
img: null,
}
constructor(props) {
super(props)
this.handleSelect = this.handleSelect.bind(this)
this.handleChange = this.handleChange.bind(this)
this.handleSettingsChange = this.handleSettingsChange.bind(this)
this.handleUpload = this.handleUpload.bind(this)
}
handleChange(e) {
const { name, value } = e.target
this.handleSelect(name, value)
}
handleSelect(name, value) {
this.props.onSelect(name, value)
}
handleSettingsChange(name, value) {
this.props.onSettingsChange(name, value)
}
handleUpload(file) {
console.log('uploading file')
const uploadData = {
image: file,
tag: "file",
username: 'animism',
}
// uploadData['__image_filename'] = file.filename
return actions.upload.upload(uploadData).then(data => {
this.handleSettingsChange("file", data.res)
})
}
render() {
const { data } = this.props
console.log(data.settings)
return (
<div className='fileForm'>
<FileInputField
title="Upload file"
mime="*/*"
onChange={this.handleUpload}
/>
{data.settings.file &&
<LabelDescription>
{data.settings.file.url}
</LabelDescription>
}
</div>
)
}
}
|