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.

138 lines
4.6 KiB

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