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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
import React, { Component } from 'react'
import { TextInput, LabelDescription, FileInputField, Select, TextArea, Checkbox, SubmitButton, Loader } from 'app/common'
export default class GalleryImageForm extends Component {
state = {
loaded: false,
data: {},
}
constructor(props){
super(props)
this.handleChange = this.handleChange.bind(this)
this.handleSelect = this.handleSelect.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
this.handleSubmitAndEditNext = this.handleSubmitAndEditNext.bind(this)
this.handleCancel = this.handleCancel.bind(this)
}
componentDidMount() {
this.setState({
loaded: true,
data: { ...this.props.initialData },
})
}
componentDidUpdate(prevProps) {
if (this.props.id !== prevProps.id) {
this.setState({
data: { ...this.props.initialData },
})
}
}
handleChange(e) {
const { name, value } = e.target
this.handleSelect(name, value)
}
handleSelect(name, value) {
this.setState({
data: {
...this.state.data,
[name]: value,
}
})
}
handleSubmit(e) {
e.preventDefault()
e.stopPropagation()
this.props.onSave(this.props.id, this.state.data)
}
handleSubmitAndEditNext(e) {
e.preventDefault()
e.stopPropagation()
this.props.onSave(this.props.id, this.state.data, true)
}
handleCancel(e) {
e.preventDefault()
e.stopPropagation()
this.props.onSave(null)
}
render() {
const { thumbnail } = this.props
const { loaded, data } = this.state
if (!loaded) return <div />
return (
<div className='modal visible'>
<div className='row'>
<div>
<img src={thumbnail.url} />
</div>
<div>
<TextInput
title="Author"
name="author"
data={data}
onChange={this.handleChange}
autoComplete="off"
/>
<TextInput
title="Title"
name="title"
data={data}
onChange={this.handleChange}
autoComplete="off"
/>
<TextInput
title="Date"
name="date"
data={data}
onChange={this.handleChange}
autoComplete="off"
/>
<TextInput
title="Medium"
name="medium"
data={data}
onChange={this.handleChange}
autoComplete="off"
/>
<Checkbox
label="Include in checklist"
name="in_checklist"
checked={data.in_checklist}
onChange={this.handleSelect}
/>
<TextArea
title="Short caption"
name="caption"
placeholder="Used on inline galleries"
data={data}
onChange={this.handleChange}
/>
<TextArea
title="Long caption"
name="long_caption"
placeholder="Used on detail views of the item, suitable for longer texts"
data={data}
onChange={this.handleChange}
/>
<div className='label'>
<span></span>
<div className='buttons'>
<button onClick={this.handleSubmit}>Save and close</button>
<button onClick={this.handleSubmitAndEditNext}>Save and edit next</button>
</div>
</div>
</div>
</div>
</div>
)
}
}
|