koel/resources/assets/js/components/shared/user-item.vue

91 lines
2 KiB
Vue
Raw Normal View History

2016-03-20 13:42:33 +00:00
<template>
2016-11-30 09:23:11 +00:00
<article class="user-item" :class="{ me: isCurrentUser }">
<div class="info">
2016-10-31 04:28:12 +00:00
<img :src="user.avatar" width="128" height="128">
2016-06-25 16:05:24 +00:00
<div class="right">
<div>
<h1>{{ user.name }}
2016-10-31 04:28:12 +00:00
<i v-if="isCurrentUser" class="you fa fa-check-circle"/>
2016-06-25 16:05:24 +00:00
</h1>
<p>{{ user.email }}</p>
2016-03-20 13:42:33 +00:00
</div>
2016-06-25 16:05:24 +00:00
<div class="buttons">
2016-11-23 15:34:44 +00:00
<button class="btn btn-blue btn-edit" @click="edit">
2016-06-25 16:05:24 +00:00
{{ isCurrentUser ? 'Update Profile' : 'Edit' }}
</button>
2016-11-30 09:51:05 +00:00
<button v-if="!isCurrentUser" class="btn btn-red btn-delete" @click="del">Delete</button>
2016-06-25 16:05:24 +00:00
</div>
</div>
</div>
</article>
2016-03-20 13:42:33 +00:00
</template>
<script>
2016-11-26 03:25:35 +00:00
import swal from 'sweetalert'
2016-06-25 16:05:24 +00:00
2016-11-26 03:25:35 +00:00
import { userStore } from '../../stores'
import router from '../../router'
2016-06-25 16:05:24 +00:00
export default {
props: ['user'],
2016-11-26 03:25:35 +00:00
data () {
2016-06-25 16:05:24 +00:00
return {
2016-11-30 09:23:11 +00:00
confirmingDelete: false
2016-11-26 03:25:35 +00:00
}
2016-06-25 16:05:24 +00:00
},
computed: {
/**
* Determine if the current logged in user is the user bound to this component.
*
* @return {Boolean}
*/
2016-11-26 03:25:35 +00:00
isCurrentUser () {
return this.user.id === userStore.current.id
}
2016-06-25 16:05:24 +00:00
},
methods: {
/**
* Trigger editing a user.
* If the user is the current logged-in user, redirect to the profile screen instead.
*/
2016-11-26 03:25:35 +00:00
edit () {
2016-06-25 16:05:24 +00:00
if (this.isCurrentUser) {
2016-11-26 03:25:35 +00:00
router.go('profile')
2016-06-25 16:05:24 +00:00
2016-11-26 03:25:35 +00:00
return
2016-06-25 16:05:24 +00:00
}
2016-11-30 09:23:11 +00:00
this.$emit('editUser', this.user)
2016-06-25 16:05:24 +00:00
},
/**
* Kill off the freaking user.
*/
2016-11-26 03:25:35 +00:00
del () {
2016-08-11 02:55:54 +00:00
swal({
title: 'Hey…',
text: `Youre about to unperson ${this.user.name}. Are you sure?`,
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Certainly',
2016-11-26 03:25:35 +00:00
cancelButtonText: 'Oops'
2016-08-11 02:55:54 +00:00
}, () => {
userStore.destroy(this.user).then(() => {
2016-11-26 03:25:35 +00:00
this.$destroy(true)
})
})
}
}
}
2016-03-20 13:42:33 +00:00
</script>
<style lang="sass">
2016-06-25 16:05:24 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
2016-03-20 13:42:33 +00:00
</style>