2016-03-20 13:42:33 +00:00
|
|
|
|
<template>
|
2016-11-23 15:34:44 +00:00
|
|
|
|
<article class="user-item" :class="{ editing: editing, me: isCurrentUser }">
|
2016-06-25 16:05:24 +00:00
|
|
|
|
<div class="info" v-if="!editing">
|
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-23 15:34:44 +00:00
|
|
|
|
<button class="btn btn-red btn-delete" @click="del">Delete</button>
|
2016-06-25 16:05:24 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-11-23 15:34:44 +00:00
|
|
|
|
<form class="user-edit" @submit.prevent="update" v-else>
|
2016-06-25 16:05:24 +00:00
|
|
|
|
<div class="input-row">
|
|
|
|
|
<label>Name</label>
|
2016-11-23 15:34:44 +00:00
|
|
|
|
<input type="text" name="name" v-model="user.name" required v-koel-focus>
|
2016-06-25 16:05:24 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div class="input-row">
|
|
|
|
|
<label>Email</label>
|
2016-11-23 15:34:44 +00:00
|
|
|
|
<input type="email" name="email" v-model="user.email" required>
|
2016-06-25 16:05:24 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div class="input-row">
|
|
|
|
|
<label>Password</label>
|
2016-11-23 15:34:44 +00:00
|
|
|
|
<input type="password" name="password" v-model="user.password" placeholder="Leave blank for no changes">
|
2016-06-25 16:05:24 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div class="input-row">
|
|
|
|
|
<label></label>
|
2016-11-23 15:34:44 +00:00
|
|
|
|
<button class="btn btn-green btn-update">Update</button>
|
|
|
|
|
<button class="btn btn-red btn-cancel" @click.prevent="cancelEdit">Cancel</button>
|
2016-06-25 16:05:24 +00:00
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</article>
|
2016-03-20 13:42:33 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2016-11-26 03:25:35 +00:00
|
|
|
|
import { clone, assign } from 'lodash'
|
|
|
|
|
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 {
|
|
|
|
|
editing: false,
|
|
|
|
|
confirmingDelete: false,
|
2016-11-26 03:25:35 +00:00
|
|
|
|
cached: {}
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keep a cached version of the user for rolling back.
|
2016-11-26 03:25:35 +00:00
|
|
|
|
this.cached = clone(this.user)
|
|
|
|
|
this.editing = true
|
2016-06-25 16:05:24 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cancel editing a user.
|
|
|
|
|
*/
|
2016-11-26 03:25:35 +00:00
|
|
|
|
cancelEdit () {
|
2016-06-25 16:05:24 +00:00
|
|
|
|
// Restore the original user's properties
|
2016-11-26 03:25:35 +00:00
|
|
|
|
assign(this.user, this.cached)
|
|
|
|
|
this.editing = false
|
2016-06-25 16:05:24 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the edited user.
|
|
|
|
|
*/
|
2016-11-26 03:25:35 +00:00
|
|
|
|
update () {
|
|
|
|
|
userStore.update(this.user, this.user.name, this.user.email, this.user.password).then(u => {
|
|
|
|
|
this.editing = false
|
|
|
|
|
})
|
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: `You’re 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>
|