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.

56 lines
1.5 KiB

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