2021-02-14 20:18:51 +01:00
|
|
|
<template>
|
|
|
|
<x-button
|
|
|
|
type="secondary"
|
|
|
|
:icon="icon"
|
|
|
|
v-tooltip="tooltipText"
|
|
|
|
@click="changeSubscription"
|
|
|
|
:disabled="disabled"
|
|
|
|
v-if="isButton"
|
|
|
|
>
|
|
|
|
{{ buttonText }}
|
|
|
|
</x-button>
|
|
|
|
<a
|
|
|
|
v-tooltip="tooltipText"
|
|
|
|
@click="changeSubscription"
|
|
|
|
:class="{'is-disabled': disabled}"
|
|
|
|
v-else
|
|
|
|
>
|
|
|
|
<span class="icon">
|
|
|
|
<icon :icon="icon"/>
|
|
|
|
</span>
|
|
|
|
{{ buttonText }}
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import SubscriptionService from '@/services/subscription'
|
|
|
|
import SubscriptionModel from '@/models/subscription'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'task-subscription',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
subscriptionService: SubscriptionService,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
entity: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
subscription: {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
entityId: {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isButton: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.subscriptionService = new SubscriptionService()
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
tooltipText() {
|
2021-06-24 01:24:57 +02:00
|
|
|
if (this.disabled) {
|
|
|
|
return this.$t('task.subscription.subscribedThroughParent', {
|
|
|
|
entity: this.entity,
|
2021-07-17 23:21:46 +02:00
|
|
|
parent: this.subscription.entity,
|
2021-06-24 01:24:57 +02:00
|
|
|
})
|
2021-02-14 20:18:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.subscription !== null ?
|
2021-06-24 01:24:57 +02:00
|
|
|
this.$t('task.subscription.subscribed', {entity: this.entity}) :
|
|
|
|
this.$t('task.subscription.notSubscribed', {entity: this.entity})
|
2021-02-14 20:18:51 +01:00
|
|
|
},
|
|
|
|
buttonText() {
|
2021-06-24 01:24:57 +02:00
|
|
|
return this.subscription !== null ? this.$t('task.subscription.unsubscribe') : this.$t('task.subscription.subscribe')
|
2021-02-14 20:18:51 +01:00
|
|
|
},
|
|
|
|
icon() {
|
|
|
|
return this.subscription !== null ? ['far', 'bell-slash'] : 'bell'
|
|
|
|
},
|
|
|
|
disabled() {
|
|
|
|
if (this.subscription === null) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.subscription.entity !== this.entity
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
changeSubscription() {
|
2021-06-24 01:24:57 +02:00
|
|
|
if (this.disabled) {
|
2021-02-14 20:18:51 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.subscription === null) {
|
|
|
|
this.subscribe()
|
|
|
|
} else {
|
|
|
|
this.unsubscribe()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
subscribe() {
|
|
|
|
const subscription = new SubscriptionModel({
|
|
|
|
entity: this.entity,
|
|
|
|
entityId: this.entityId,
|
|
|
|
})
|
|
|
|
this.subscriptionService.create(subscription)
|
|
|
|
.then(() => {
|
|
|
|
this.$emit('change', subscription)
|
2021-06-24 01:24:57 +02:00
|
|
|
this.success({message: this.$t('task.subscription.subscribeSuccess', {entity: this.entity})})
|
2021-02-14 20:18:51 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2021-06-22 22:07:57 +02:00
|
|
|
this.error(e)
|
2021-02-14 20:18:51 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
unsubscribe() {
|
|
|
|
const subscription = new SubscriptionModel({
|
|
|
|
entity: this.entity,
|
|
|
|
entityId: this.entityId,
|
|
|
|
})
|
|
|
|
this.subscriptionService.delete(subscription)
|
|
|
|
.then(() => {
|
|
|
|
this.$emit('change', null)
|
2021-06-24 01:24:57 +02:00
|
|
|
this.success({message: this.$t('task.subscription.unsubscribeSuccess', {entity: this.entity})})
|
2021-02-14 20:18:51 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2021-06-22 22:07:57 +02:00
|
|
|
this.error(e)
|
2021-02-14 20:18:51 +01:00
|
|
|
})
|
2021-07-17 23:21:46 +02:00
|
|
|
},
|
2021-02-14 20:18:51 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|