You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.3 KiB

3 years ago
  1. <app-note-form>
  2. <div class="note-form">
  3. <div class="panel">
  4. <div class="panel__body">
  5. <form id="form" novalidate>
  6. <input type="hidden" if={ state.note && state.note._id } name="_id" value="{ state.note._id }" />
  7. <div class="field-group">
  8. <label class="field-label">
  9. title
  10. <input type="text" class="field-text" name="title" />
  11. </label>
  12. </div>
  13. <div class="field-group">
  14. <label class="field-label">
  15. content
  16. <textarea name="content" class="field-text"></textarea>
  17. </label>
  18. </div>
  19. <div class="">
  20. <div class="tabs">
  21. </div>
  22. </div>
  23. <div>
  24. <button class="button" if={ !state.note || (state.note && !state.note._id) }>
  25. Create
  26. </button>
  27. <button class="button" type="submit" if={ state.note && state.note._id }>
  28. Save
  29. </button>
  30. </div>
  31. </form>
  32. </div>
  33. </div>
  34. </div>
  35. <script>
  36. import axios from 'axios'
  37. import * as riot from 'riot'
  38. import FormValidator from './../FormValidator'
  39. import FieldError from './field-error.riot'
  40. riot.register('field-error', FieldError)
  41. riot.mount('field-error')
  42. /**
  43. *
  44. *
  45. *
  46. * @author Björn Hase
  47. *
  48. */
  49. export default {
  50. state: {
  51. note: undefined
  52. },
  53. onBeforeMount() {
  54. // show error if props is missing
  55. if (!this.props.bucketId) {
  56. console.error('ID of Bucket is Missing!')
  57. }
  58. },
  59. /**
  60. *
  61. *
  62. */
  63. onMounted(props, state) {
  64. // create form validation
  65. const formValidation = new FormValidator('form', {
  66. 'title': {
  67. 'length': {
  68. 'maximum': 255
  69. }
  70. },
  71. 'content': {
  72. 'length': {
  73. 'maximum': 10922
  74. }
  75. }
  76. }, (event, data) => {
  77. this.handleSubmit(event, data)
  78. })
  79. },
  80. /**
  81. *
  82. *
  83. */
  84. handleSubmit(event, data) {
  85. let method = 'post'
  86. if (this.state.note && this.state.note._id) {
  87. method = 'put'
  88. }
  89. axios({
  90. method: method,
  91. url: '/api/note/' + this.props.bucketId,
  92. data: data
  93. }).then((response) => {
  94. this.state.note = response.data.data
  95. this.update()
  96. })
  97. }
  98. }
  99. </script>
  100. </app-note-form>