Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Action.vue « Components « src - github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8e514609c9ea1c1db8c9f138227b52b75e3d05d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
	<button class="action-button pull-right"
		:class="{ primary: primary }"
		:data-type="type"
		:data-href="link"
		@click="onClickActionButton">
		{{ label }}
	</button>
</template>

<script>
import axios from '@nextcloud/axios'
export default {
	name: 'Action',

	props: {
		label: {
			type: String,
			default: '',
			required: true,
		},
		link: {
			type: String,
			default: '',
			required: true,
		},
		type: {
			type: String,
			default: '',
			required: true,
		},
		primary: {
			type: Boolean,
			default: false,
			required: true,
		},
	},

	methods: {
		async onClickActionButton() {
			const type = this.type || 'GET'
			if (type === 'WEB') {
				OC.redirect(this.link)
				return
			}

			try {
				// execute action
				await axios({
					method: type,
					url: this.link,
				})

				// emit event to current app
				this.$parent._$el.fadeOut(OC.menuSpeed)
				this.$parent.$emit('remove')
				try {
					$('body').trigger(new $.Event('OCA.Notification.Action', {
						notification: this.$parent,
						action: {
							url: this.link,
							type: type,
						},
					}))
				// do not do anything but log, the action went fine
				// only the event bus listener failed, this is not our problem
				} catch (error) {
					console.error(error)
				}
			} catch (error) {
				console.error('Failed to perform action', error)
				OC.Notification.showTemporary(t('notifications', 'Failed to perform action'))
			}
		},
	},
}
</script>