ConfigList.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react'
  2. class ConfigList extends React.Component {
  3. constructor() {
  4. super()
  5. this.handleChange = this.handleChange.bind(this)
  6. }
  7. componentDidMount () {
  8. console.log('ConfigList did mount', this)
  9. const { configGetRequest } = this.props.configActions
  10. configGetRequest()
  11. }
  12. handleChange (event) {
  13. event.preventDefault()
  14. const { configChangeForm } = this.props.configActions
  15. const nextConfig = {
  16. _id: this.configid ? this.configid.value : null,
  17. key: this.key.value,
  18. description: this.description.value,
  19. value: this.value.value
  20. }
  21. configChangeForm(nextConfig)
  22. }
  23. render () {
  24. const state = this.props.config
  25. const actions = this.props.configActions
  26. const config = state.configForm
  27. return (
  28. <div>
  29. <form>
  30. <h2>{(config._id) ? "Konfiguration editieren" : "Neue Konfiguration"}</h2>
  31. {config._id ? <input type="hidden" key="configid" value={config._id} ref={(input) => {this.configid = input}} id="configid"/> : null}
  32. <label htmlFor="key">Schluessel</label>
  33. <input type="input" ref={(input) => {this.key = input}} id="key" value={config.key} placeholder="Schluessel" onChange={this.handleChange} readOnly={!!config._id}></input>
  34. <label htmlFor="description">Beschreibung</label>
  35. <input type="input" ref={(input) => {this.description = input}} id="description" value={config.description} placeholder="Beschreibung" onChange={this.handleChange}></input>
  36. <label htmlFor="value">Wert</label>
  37. <input type="input" ref={(input) => {this.value = input}} id="value" value={config.value} placeholder="Wert" onChange={this.handleChange}></input>
  38. <input type="submit" value={config._id ? "Aenderungen speichern" : "Konfiguration anlegen"} onClick={(event) => {
  39. event.preventDefault()
  40. if (config._id) {
  41. actions.configEditRequest(config)
  42. } else {
  43. actions.configAddRequest(config)
  44. }
  45. }} />
  46. <input type="reset" value={config._id ? "Abbrechen" : "Loeschen"} onClick={(event) => {
  47. event.preventDefault()
  48. actions.configClearForm(event)
  49. }} />
  50. </form>
  51. <table className='table table-bordered table-striped'>
  52. <thead>
  53. <tr>
  54. <th>Schluessel</th><th>Beschreibung</th><th>Wert</th><th>Wert</th>
  55. </tr>
  56. </thead>
  57. <tbody>
  58. {state.configs ? state.configs.map((configData, key) =>
  59. <tr key={key}>
  60. <td>{configData.key}</td>
  61. <td>{configData.description}</td>
  62. <td>{configData.value}</td>
  63. <td>
  64. <a onClick={(event) => actions.configLoadForm(key)}>editieren</a>
  65. <a onClick={(event) => actions.configDeleteRequest(key)}>loeschen</a>
  66. </td>
  67. </tr>
  68. ) : ""}
  69. </tbody>
  70. </table>
  71. </div>
  72. )
  73. }
  74. }
  75. export default ConfigList