summaryrefslogtreecommitdiff
path: root/src/client/app/common/views/components/note-menu.vue
blob: c9912fb1e2f4ee0e7d3b00e0e2fa4518687d762f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<div style="position:initial">
	<mk-menu :source="source" :compact="compact" :items="items" @closed="closed"/>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import { url } from '../../../config';
import copyToClipboard from '../../../common/scripts/copy-to-clipboard';

export default Vue.extend({
	props: ['note', 'source', 'compact'],
	computed: {
		items() {
			const items = [{
				icon: '%fa:info-circle%',
				text: '%i18n:@detail%',
				action: this.detail
			}, {
				icon: '%fa:link%',
				text: '%i18n:@copy-link%',
				action: this.copyLink
			}, null, {
				icon: '%fa:star%',
				text: '%i18n:@favorite%',
				action: this.favorite
			}];

			if (this.note.userId == this.$store.state.i.id) {
				items.push({
					icon: '%fa:thumbtack%',
					text: '%i18n:@pin%',
					action: this.pin
				});
				items.push({
					icon: '%fa:trash-alt R%',
					text: '%i18n:@delete%',
					action: this.del
				});
			}
			if (this.note.uri) {
				items.push({
					icon: '%fa:external-link-square-alt%',
					text: '%i18n:@remote%',
					action: () => {
						window.open(this.note.uri, '_blank');
					}
				});
			}
			return items;
		}
	},
	methods: {
		detail() {
			this.$router.push(`/notes/${ this.note.id }`);
		},

		copyLink() {
			copyToClipboard(`${url}/notes/${ this.note.id }`);
		},

		pin() {
			(this as any).api('i/pin', {
				noteId: this.note.id
			}).then(() => {
				this.destroyDom();
			});
		},

		del() {
			if (!window.confirm('%i18n:@delete-confirm%')) return;
			(this as any).api('notes/delete', {
				noteId: this.note.id
			}).then(() => {
				this.destroyDom();
			});
		},

		favorite() {
			(this as any).api('notes/favorites/create', {
				noteId: this.note.id
			}).then(() => {
				this.destroyDom();
			});
		},

		closed() {
			this.$nextTick(() => {
				this.destroyDom();
			});
		}
	}
});
</script>