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.

127 lines
4.0 KiB

  1. <app-users-form>
  2. <div class="sidebar sidebar--open">
  3. <div class="sidebar__inner">
  4. <div class="bar">
  5. <div class="bar__main">
  6. Create User
  7. </div>
  8. <div class="bar__end">
  9. <button class="button button--transparent" type="button" onclick={ (event) => { handleClose(event) } }>
  10. <svg class="icon fill-text-contrast" aria-hidden="true">
  11. <use xlink:href="/symbol-defs.svg#icon-close"></use>
  12. </svg>
  13. </button>
  14. </div>
  15. </div>
  16. <div class="sidebar__body">
  17. <form id="app-users-form">
  18. <div class="field-group">
  19. <label class="field-label">
  20. E-Mail
  21. <input name="email" type="text" class="field-text" />
  22. </label>
  23. <field-error name="email"></field-error>
  24. </div>
  25. <div class="field-group">
  26. <label class="field-label">
  27. Password
  28. <input name="password" type="password" class="field-text" />
  29. </label>
  30. <field-error name="password"></field-error>
  31. </div>
  32. </form>
  33. </div>
  34. <div class="sidebar__footer">
  35. <button class="button m-bottom-0" type="submit" form="app-users-form">
  36. Save
  37. <svg class="icon fill-success p-left-3" aria-hidden="true">
  38. <use xlink:href="/symbol-defs.svg#icon-check"></use>
  39. </svg>
  40. </button>
  41. <button class="button m-bottom-0" type="submit" form="app-users-form">
  42. Save and Close
  43. <svg class="icon fill-success p-left-3" aria-hidden="true">
  44. <use xlink:href="/symbol-defs.svg#icon-arrow-right"></use>
  45. </svg>
  46. </button>
  47. </div>
  48. </div>
  49. </div>
  50. <script>
  51. import axios from 'axios'
  52. import * as riot from 'riot'
  53. import FormValidator from './../../FormValidator'
  54. import FieldError from './../field-error.riot'
  55. riot.register('field-error', FieldError)
  56. riot.mount('field-error')
  57. export default {
  58. state: {
  59. user: { }
  60. },
  61. /**
  62. *
  63. *
  64. */
  65. onMounted(props, state) {
  66. // create form validation
  67. const formValidation = new FormValidator('app-users-form', {
  68. 'email': {
  69. 'length': {
  70. 'maximum': 255
  71. },
  72. 'email': true,
  73. 'presence': true
  74. },
  75. 'password': {
  76. 'length': {
  77. 'maximum': 64
  78. },
  79. 'presence': true
  80. }
  81. }, (event, data) => {
  82. this.handleSubmit(event, data)
  83. })
  84. },
  85. handleClose(event)
  86. {
  87. event.preventDefault()
  88. this.$('.sidebar').classList.remove('sidebar--open')
  89. },
  90. /**
  91. *
  92. *
  93. */
  94. handleSubmit(event, data) {
  95. let method = 'post'
  96. if (this.state.user && this.state.user._id) {
  97. method = 'put'
  98. }
  99. axios({
  100. method: method,
  101. url: '/api/users',
  102. data: data
  103. }).then((response) => {
  104. this.state.user = response.data.data
  105. this.update()
  106. })
  107. }
  108. }
  109. </script>
  110. </app-users-form>