wikijs-fork/client/js/modals/admin-users-create.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-02-10 06:43:26 +00:00
/* global $, Vue, alerts */
2017-01-04 05:07:15 +00:00
// Vue Create User instance
let vueCreateUser = new Vue({
2017-02-09 01:52:37 +00:00
el: '#modal-admin-users-create',
data: {
email: '',
provider: 'local',
password: '',
2017-02-10 06:43:26 +00:00
name: '',
loading: false
2017-02-09 01:52:37 +00:00
},
methods: {
open: (ev) => {
$('#modal-admin-users-create').addClass('is-active')
$('#modal-admin-users-create input').first().focus()
},
cancel: (ev) => {
$('#modal-admin-users-create').removeClass('is-active')
vueCreateUser.email = ''
vueCreateUser.provider = 'local'
},
create: (ev) => {
2017-02-10 06:43:26 +00:00
vueCreateUser.loading = true
$.ajax('/admin/users/create', {
data: {
email: vueCreateUser.email,
provider: vueCreateUser.provider,
password: vueCreateUser.password,
name: vueCreateUser.name
},
dataType: 'json',
method: 'POST'
}).then((rData, rStatus, rXHR) => {
vueCreateUser.loading = false
if (rData.ok) {
vueCreateUser.cancel()
window.location.reload(true)
} else {
alerts.pushError('Something went wrong', rData.msg)
}
}, (rXHR, rStatus, err) => {
vueCreateUser.loading = false
alerts.pushError('Error', rXHR.responseJSON.msg)
})
2017-02-09 01:52:37 +00:00
}
}
})
2017-01-04 05:07:15 +00:00
2017-02-09 01:52:37 +00:00
$('.btn-create-prompt').on('click', vueCreateUser.open)