123 lines
2.4 KiB
JavaScript
123 lines
2.4 KiB
JavaScript
import Vue from 'vue'
|
|
import VueResource from 'vue-resource'
|
|
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').content
|
|
|
|
Vue.use(VueResource)
|
|
|
|
Vue.component('Modal', {
|
|
template: '#modal-template',
|
|
props: ['show'],
|
|
methods: {
|
|
close: function () {
|
|
this.$emit('close')
|
|
}
|
|
},
|
|
mounted: function () {
|
|
document.addEventListener('keydown', (e) => {
|
|
if (this.show && e.keyCode === 27) {
|
|
this.close()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
Vue.component('BanModal', {
|
|
template: '#ban-modal-template',
|
|
props: ['show', 'id'],
|
|
data: function () {
|
|
return {
|
|
error: '',
|
|
reason: '',
|
|
expires_at: null
|
|
}
|
|
},
|
|
methods: {
|
|
close: function () {
|
|
this.$emit('close')
|
|
this.error = ''
|
|
this.reason = ''
|
|
this.expires_at = null
|
|
},
|
|
submit: function () {
|
|
this.$http.post('/admin/api/ban', {
|
|
user_id: this.id,
|
|
reason: this.reason,
|
|
expires_at: this.expires_at,
|
|
csrf: csrfToken
|
|
}).then(data => {
|
|
this.close()
|
|
banList.getBans(1)
|
|
}).catch(err => {
|
|
console.log(err)
|
|
if (err.body && err.body.error) this.error = err.body.error
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
const userList = new Vue({
|
|
el: '#userlist',
|
|
data: {
|
|
pagination: {
|
|
offset: 0,
|
|
page: 1,
|
|
pages: 1,
|
|
perPage: 6,
|
|
total: 0
|
|
},
|
|
users: [],
|
|
banning: 0
|
|
},
|
|
mounted: function () {
|
|
this.getUsers(1)
|
|
},
|
|
methods: {
|
|
getUsers: function (page) {
|
|
this.$http.get('/admin/api/users?page=' + page).then(data => {
|
|
if (data.body && data.body.error) return
|
|
this.pagination = data.body.page
|
|
this.users = data.body.users
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
const banList = new Vue({
|
|
el: '#banlist',
|
|
data: {
|
|
pagination: {
|
|
offset: 0,
|
|
page: 1,
|
|
pages: 1,
|
|
perPage: 6,
|
|
total: 0
|
|
},
|
|
error: '',
|
|
bans: []
|
|
},
|
|
mounted: function () {
|
|
this.getBans(1)
|
|
},
|
|
methods: {
|
|
getBans: function (page) {
|
|
this.error = ''
|
|
this.pagination.total = 0
|
|
this.$http.get('/admin/api/bans?page=' + page).then(data => {
|
|
if (data.body && data.body.error) {
|
|
this.error = data.body.error
|
|
return
|
|
}
|
|
|
|
this.pagination = data.body.page
|
|
this.bans = data.body.bans
|
|
})
|
|
},
|
|
pardon: function (id) {
|
|
this.$http.post('/admin/api/ban/pardon/' + id).then(data => {
|
|
this.getBans(1)
|
|
})
|
|
}
|
|
}
|
|
})
|