summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/media/components/media.formGalleryImage.js
blob: 1dbf1f2b230c2a41a32e1630369b12456c019f50 (plain)
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
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)
  }
  componentDidMount() {
    console.log(this.props)
    this.setState({
      loaded: true,
      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,
      }
    })
  }
  handleSave() {
    this.props.onSave(this.props.id, this.state.data)
  }
  render() {
    const { thumbnail } = this.props
    const { loaded, data } = this.state
    if (!loaded) return <div />
    console.log(data)
    return (
      <div className='modal visible'>
        <div className='row'>
          <div>
            <img src={thumbnail.url} />
          </div>
          <div>
            <TextInput
              title="Author"
              name="author"
              required
              data={data}
              onChange={this.handleChange}
              autoComplete="off"
            />
            <TextInput
              title="Title"
              name="title"
              required
              data={data}
              onChange={this.handleChange}
              autoComplete="off"
            />
            <TextInput
              title="Date"
              name="date"
              required
              data={data}
              onChange={this.handleChange}
              autoComplete="off"
            />
            <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}
            />
            <SubmitButton
              title={"Save"}
              onClick={this.handleSubmit}
            />
          </div>
        </div>
      </div>
    )
  }
}