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

Admins.vue « src - github.com/nextcloud/privacy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 822fddb0480f7fa3647f09f4c10ce9660d681d21 (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
96
97
98
<template>
	<div class="who-has-access">
		<span :class="{hidden: !isLoading}" class="icon icon-loading" />
		<div v-for="admin in admins" :key="admin.id" class="admin-avatar-container">
			<avatar :user="admin.internal ? admin.id : null"
				:display-name="admin.displayname" :size="64" :is-no-user="!admin.internal"
			/>
			<span v-if="!admin.internal" class="icon icon-close"
				@click="deleteAdditionalAdmin(admin)"
			/>
		</div>

		<div v-if="isAdmin">
			<div v-if="!isAdding" class="addAdditionalAdmin"
				:title="additionalAdminPlaceholderLabel" @click="openNewAdmin"
			>
				+
			</div>
			<form v-if="isAdding" v-click-outside="closeNewAdmin" class="addAdditionalAdminFormContainer"
				@submit.prevent="addAdditionalAdmin"
			>
				<input v-model="newAdditionalAdminInputField" type="text" maxlength="64"
					autocomplete="new-password" autocorrect="off" autocapitalize="off"
					spellcheck="false" :placeholder="additionalAdminPlaceholderLabel"
				>
				<input type="submit" value="" class="icon-confirm">
				<!-- add icon-loading -->
			</form>
		</div>
	</div>
</template>

<script>
import { generateUrl } from 'nextcloud-server/dist/router'
import HttpClient from 'nextcloud-axios'
import Vue from 'vue'
import ClickOutside from 'vue-click-outside'

export default {
	name: 'Admins',
	directives: {
		ClickOutside
	},
	data: () => ({
		admins: [],
		newAdditionalAdminInputField: '',
		isAdmin: false,
		isLoading: true,
		isAdding: false,
		isSavingChanges: false
	}),
	computed: {
		additionalAdminPlaceholderLabel() {
			return t('privacy', 'Add external admin')
		}
	},
	mounted() {
		this.isAdmin = OC.isUserAdmin()

		const url = generateUrl('/apps/privacy/api/admins')
		HttpClient.get(url).then(resp => {
			Vue.set(this, 'admins', resp.data)
			this.isLoading = false
		})
	},
	methods: {
		openNewAdmin() {
			setTimeout(() => {
				this.isAdding = true
			}, 0)
		},
		closeNewAdmin() {
			this.isAdding = false
			this.newAdditionalAdminInputField = ''
		},
		addAdditionalAdmin() {
			console.warn(this.newAdditionalAdminInputField)
			const url = generateUrl('/apps/privacy/api/admins')
			this.isSavingChanges = true

			HttpClient.post(url, { name: this.newAdditionalAdminInputField }).then(resp => {
				this.admins.push(resp.data)

				this.isSavingChanges = false
				this.isAdding = false
				this.newAdditionalAdminInputField = ''
			})
		},
		deleteAdditionalAdmin(admin) {
			const url = generateUrl('/apps/privacy/api/admins/{id}', { id: admin.id })
			HttpClient.delete(url).then(resp => {
				const index = this.admins.indexOf(admin)
				this.admins.splice(index, 1)
			})
		}
	}
}
</script>