Library/frontend/src/components/AuthorOverview.vue

84 lines
2.0 KiB
Vue
Raw Normal View History

2017-11-21 12:32:34 +00:00
<template>
<div v-if="user.authenticated">
2017-11-29 15:15:29 +00:00
<h1>{{ author.forename }} {{ author.lastname }}</h1>
2017-11-21 12:32:34 +00:00
<div class="ui info message" v-if="loading">
<icon name="refresh" spin></icon>&nbsp;&nbsp;
2017-11-22 14:13:33 +00:00
<span v-lang.general.loading></span>
2017-11-21 12:32:34 +00:00
</div>
<div v-if="!loading">
2017-11-21 12:32:34 +00:00
<router-link :to="{ name: 'author-edit', params: { id: authorID} }" class="ui teal labeled icon button" style="float: right;">
<i class="edit icon"></i>
2017-11-22 14:13:33 +00:00
<span v-lang.general.edit></span>
2017-11-21 12:32:34 +00:00
</router-link>
2017-11-24 10:54:52 +00:00
<list :infos="authorList"/>
2017-11-21 12:32:34 +00:00
</div>
</div>
</template>
<script>
import auth from '../auth'
import {HTTP} from '../http-common'
export default {
name: 'Author',
data () {
return {
user: auth.user,
author: {},
2017-11-24 10:54:52 +00:00
authorID: this.$route.params.id,
authorList: []
2017-11-21 12:32:34 +00:00
}
},
created () {
this.loadAuthor()
},
watch: {
// call again the method if the route changes
'$route': 'loadAuthor'
},
methods: {
loadAuthor () {
this.loading = true
this.author = {}
HTTP.get(`authors/` + this.authorID)
.then(response => {
this.author = response.data
2017-11-24 10:54:52 +00:00
// Make a list
this.authorList = [
{
header: this.translate('authors').forename,
2017-11-29 15:15:29 +00:00
content: this.author.forename
2017-11-24 10:54:52 +00:00
},
{
header: this.translate('authors').lastname,
2017-11-29 15:15:29 +00:00
content: this.author.lastname
2017-11-24 10:54:52 +00:00
}
]
2017-11-21 12:32:34 +00:00
this.loading = false
})
.catch(e => {
this.loading = false
// Build the notification text from error response
let err = e.message
2017-11-23 14:28:38 +00:00
if (e.response.data.Message) {
err += '<br/>' + e.response.data.Message
}
// Fire a notification
this.$notify({
type: 'error',
title: this.langGeneral.error,
text: err
})
2017-11-21 12:32:34 +00:00
})
}
}
}
</script>