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

LinkShareSettings.vue « ConversationSettings « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 50107662fb55ed4c34cb0c9d05cbad042dbc01cc (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!--
  - @copyright Copyright (c) 2020 Vincent Petry <vincent@nextcloud.com>
  -
  - @author Vincent Petry <vincent@nextcloud.com>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<template>
	<div>
		<div class="app-settings-subsection">
			<div id="link_share_settings_hint" class="app-settings-section__hint">
				{{ t('spreed', 'Allow guests to use a public link to join this conversation.') }}
			</div>
			<div>
				<input id="link_share_settings_toggle_guests"
					ref="toggleGuests"
					aria-describedby="link_share_settings_hint"
					type="checkbox"
					class="checkbox"
					name="link_share_settings_toggle_guests"
					:checked="isSharedPublicly"
					:disabled="isSaving"
					@change="toggleGuests">
				<label for="link_share_settings_toggle_guests">{{ t('spreed', 'Allow guests') }}</label>
			</div>
		</div>
		<div v-show="isSharedPublicly" class="app-settings-subsection">
			<div id="link_share_settings_password_hint" class="app-settings-section__hint">
				{{ t('spreed', 'Set a password to restrict who can use the public link.') }}
			</div>
			<div>
				<input id="link_share_settings_toggle_password"
					ref="togglePassword"
					aria-describedby="link_share_settings_password_hint"
					type="checkbox"
					class="checkbox"
					:checked="conversation.hasPassword"
					name="link_share_settings_toggle_password"
					:disabled="isSaving"
					@change="togglePassword">
				<label for="link_share_settings_toggle_password">{{ t('spreed', 'Password protection') }}</label>
			</div>
		</div>
		<div class="app-settings-subsection">
			<div v-show="showPasswordField">
				<form
					:disabled="isSaving"
					@submit.prevent="handleSetNewPassword">
					<span class="icon-password" />
					<input
						id="link_share_settings_link_password"
						ref="passwordField"
						v-model="password"
						aria-describedby="link_share_settings_password_hint"
						type="password"
						class="checkbox"
						autocomplete="new-password"
						name="link_share_settings_link_password"
						:placeholder="t('spreed', 'Enter a password')"
						:disabled="isSaving">
					<button
						id="link_share_settings_link_password_submit"
						:aria-label="t('spreed', 'Save password')"
						:disabled="isSaving"
						type="submit"
						class="icon icon-confirm-fade" />
				</form>
			</div>
		</div>
		<div class="app-settings-subsection">
			<button
				ref="copyLinkButton"
				@click.prevent="handleCopyLink">
				<span class="icon icon-clippy" />{{ t('spreed', 'Copy conversation link') }}
			</button>
		</div>
		<div v-if="isSharedPublicly" class="app-settings-subsection">
			<button
				:disabled="isSendingInvitations"
				@click.prevent="handleResendInvitations">
				<span class="icon icon-mail" />{{ t('spreed', 'Resend invitations') }}
			</button>
			<span v-if="isSendingInvitations" class="icon-loading-small spinner" />
		</div>
	</div>
</template>

<script>
import { showError, showSuccess } from '@nextcloud/dialogs'
import { CONVERSATION } from '../../constants'
import {
	setConversationPassword,
} from '../../services/conversationsService'
import { generateUrl } from '@nextcloud/router'

export default {
	name: 'LinkShareSettings',

	data() {
		return {
			// The conversation's password
			password: '',
			// Switch for the password-editing operation
			showPasswordField: false,
			isSaving: false,
			isSendingInvitations: false,
		}
	},

	computed: {
		isSharedPublicly() {
			return this.conversation.type === CONVERSATION.TYPE.PUBLIC
		},

		token() {
			return this.$store.getters.getToken()
		},

		conversation() {
			return this.$store.getters.conversation(this.token) || this.$store.getters.dummyConversation
		},

		linkToConversation() {
			return window.location.protocol + '//' + window.location.host + generateUrl('/call/' + this.token)
		},
	},

	methods: {
		focus() {
			this.$nextTick(() => {
				this.$refs.toggleGuests.focus()
			})
		},

		async setConversationPassword(newPassword) {
			this.isSaving = true
			try {
				await setConversationPassword(this.token, newPassword)
				if (newPassword !== '') {
					showSuccess(t('spreed', 'Conversation password has been saved'))
				} else {
					showSuccess(t('spreed', 'Conversation password has been removed'))
				}
			} catch (e) {
				console.error('Error saving conversation password', e)
				showError(t('spreed', 'Error occurred while saving conversation password'))
			}
			this.isSaving = false
		},

		async toggleGuests() {
			const enabled = this.conversation.type !== CONVERSATION.TYPE.PUBLIC
			this.isSaving = true
			try {
				await this.$store.dispatch('toggleGuests', {
					token: this.token,
					allowGuests: enabled,
				})

				if (enabled) {
					showSuccess(t('spreed', 'You allowed guests'))
				} else {
					showSuccess(t('spreed', 'You disallowed guests'))
				}
			} catch (e) {
				if (enabled) {
					showError(t('spreed', 'Error occurred while allowing guests'))
				} else {
					showError(t('spreed', 'Error occurred while disallowing guests'))
				}
				console.error('Error toggling guest mode', e)
			}
			this.isSaving = false
		},

		async togglePassword() {
			if (this.$refs.togglePassword.checked) {
				this.showPasswordField = true
				this.$refs.passwordField.focus()
				await this.handlePasswordEnable()
			} else {
				this.showPasswordField = false
				await this.handlePasswordDisable()
			}
		},

		async handlePasswordDisable() {
			// disable the password protection for the current conversation
			if (this.conversation.hasPassword) {
				await this.setConversationPassword('')
			}
			this.password = ''
			this.showPasswordField = false
		},

		async handlePasswordEnable() {
			this.showPasswordField = true
		},

		async handleSetNewPassword() {
			await this.setConversationPassword(this.password)
			this.password = ''
			this.showPasswordField = false
		},

		async handleCopyLink() {
			try {
				await this.$copyText(this.linkToConversation)
				showSuccess(t('spreed', 'Conversation link copied to clipboard.'))
			} catch (error) {
				showError(t('spreed', 'The link could not be copied.'))
			}
			// workaround for https://github.com/Inndy/vue-clipboard2/issues/105
			this.$refs.copyLinkButton.focus()
		},

		async handleResendInvitations() {
			this.isSendingInvitations = true
			try {
				await this.$store.dispatch('resendInvitations', { token: this.token })
				showSuccess(t('spreed', 'Invitations sent'))
			} catch (e) {
				showError(t('spreed', 'Error occurred when sending invitations'))
			}
			this.isSendingInvitations = false
		},
	},
}
</script>

<style lang="scss" scoped>
.icon {
	margin-right: 10px;
}

.spinner {
	margin-left: 24px;
}

input[type=password] {
	width: 200px;
}
</style>