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.

51 lines
1.3 KiB

  1. /* global $, Vue, alerts */
  2. // Vue Create User instance
  3. let vueCreateUser = new Vue({
  4. el: '#modal-admin-users-create',
  5. data: {
  6. email: '',
  7. provider: 'local',
  8. password: '',
  9. name: '',
  10. loading: false
  11. },
  12. methods: {
  13. open: (ev) => {
  14. $('#modal-admin-users-create').addClass('is-active')
  15. $('#modal-admin-users-create input').first().focus()
  16. },
  17. cancel: (ev) => {
  18. $('#modal-admin-users-create').removeClass('is-active')
  19. vueCreateUser.email = ''
  20. vueCreateUser.provider = 'local'
  21. },
  22. create: (ev) => {
  23. vueCreateUser.loading = true
  24. $.ajax('/admin/users/create', {
  25. data: {
  26. email: vueCreateUser.email,
  27. provider: vueCreateUser.provider,
  28. password: vueCreateUser.password,
  29. name: vueCreateUser.name
  30. },
  31. dataType: 'json',
  32. method: 'POST'
  33. }).then((rData, rStatus, rXHR) => {
  34. vueCreateUser.loading = false
  35. if (rData.ok) {
  36. vueCreateUser.cancel()
  37. window.location.reload(true)
  38. } else {
  39. alerts.pushError('Something went wrong', rData.msg)
  40. }
  41. }, (rXHR, rStatus, err) => {
  42. vueCreateUser.loading = false
  43. alerts.pushError('Error', rXHR.responseJSON.msg)
  44. })
  45. }
  46. }
  47. })
  48. $('.btn-create-prompt').on('click', vueCreateUser.open)