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.

152 lines
5.3 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. 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. Display Name
  28. <input name="display_name" type="text" class="field-text" />
  29. </label>
  30. <field-error name="display_name"></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. <div class="field-group">
  40. <label class="field-label">
  41. <input name="roles[]" type="checkbox" class="field-choice" value="admin" />
  42. <svg class="icon field-choice__unchecked" aria-hidden="true">
  43. <use xlink:href="/symbol-defs.svg#icon-checkbox"></use>
  44. </svg>
  45. <svg class="icon field-choice__checked" aria-hidden="true">
  46. <use xlink:href="/symbol-defs.svg#icon-checkbox-checked"></use>
  47. </svg>
  48. Admin
  49. </label>
  50. <field-error name="roles"></field-error>
  51. </div>
  52. </form>
  53. </div>
  54. <div class="sidebar__footer">
  55. <button class="button m-bottom-0" type="submit" form="app-users-form">
  56. Save
  57. <svg class="icon fill-success p-left-3" aria-hidden="true">
  58. <use xlink:href="/symbol-defs.svg#icon-check"></use>
  59. </svg>
  60. </button>
  61. <button class="button m-bottom-0" type="submit" form="app-users-form">
  62. Save and Close
  63. <svg class="icon fill-success p-left-3" aria-hidden="true">
  64. <use xlink:href="/symbol-defs.svg#icon-arrow-right"></use>
  65. </svg>
  66. </button>
  67. </div>
  68. </div>
  69. </div>
  70. <script>
  71. import axios from 'axios'
  72. import * as riot from 'riot'
  73. import FormValidator from './../../FormValidator'
  74. import FieldError from './../field-error.riot'
  75. riot.register('field-error', FieldError)
  76. riot.mount('field-error')
  77. export default {
  78. state: {
  79. user: { }
  80. },
  81. /**
  82. *
  83. *
  84. */
  85. onMounted(props, state) {
  86. this.root.addEventListener('app-users-form-open', (event) => {
  87. this.$('.sidebar').classList.add('sidebar--open')
  88. })
  89. // create form validation
  90. const formValidation = new FormValidator('#app-users-form', {
  91. 'email': {
  92. 'length': {
  93. 'maximum': 255
  94. },
  95. 'email': true,
  96. 'presence': true
  97. },
  98. 'password': {
  99. 'length': {
  100. 'maximum': 64
  101. },
  102. 'presence': true
  103. }
  104. }, (event, data) => {
  105. this.handleSubmit(event, data)
  106. })
  107. },
  108. handleClose(event)
  109. {
  110. event.preventDefault()
  111. this.$('.sidebar').classList.remove('sidebar--open')
  112. },
  113. /**
  114. *
  115. *
  116. */
  117. handleSubmit(event, data) {
  118. let method = 'post'
  119. if (this.state.user && this.state.user._id) {
  120. method = 'put'
  121. }
  122. axios({
  123. method: method,
  124. url: '/api/users',
  125. data: data
  126. }).then((response) => {
  127. this.state.user = response.data.data
  128. this.update()
  129. })
  130. }
  131. }
  132. </script>
  133. </app-users-form>