|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<template> |
| 7 | + <div id="system-tags-creation-control"> |
| 8 | + <h4 class="inlineblock"> |
| 9 | + {{ t('settings', 'System tag creation') }} |
| 10 | + </h4> |
| 11 | + |
| 12 | + <p class="settings-hint"> |
| 13 | + {{ t('settings', 'Allow only admins to create tags (enable or disable).') }} |
| 14 | + </p> |
| 15 | + |
| 16 | + <NcCheckboxRadioSwitch type="switch" |
| 17 | + :checked.sync="onlyAdminsCanCreateEnabled" |
| 18 | + @update:checked="updateSystemTagsDefault"> |
| 19 | + {{ t('settings', 'Enable') }} |
| 20 | + </NcCheckboxRadioSwitch> |
| 21 | + </div> |
| 22 | +</template> |
| 23 | + |
| 24 | +<script lang="ts"> |
| 25 | +import { loadState } from '@nextcloud/initial-state' |
| 26 | +import { showError, showSuccess } from '@nextcloud/dialogs' |
| 27 | +import { t } from '@nextcloud/l10n' |
| 28 | +import logger from '../logger.ts' |
| 29 | +import { updateOnlyAdminsCanCreateSystemTags } from '../services/api.js' |
| 30 | +
|
| 31 | +import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' |
| 32 | +
|
| 33 | +export default { |
| 34 | + name: 'SystemTagsCreationControl', |
| 35 | +
|
| 36 | + components: { |
| 37 | + NcCheckboxRadioSwitch, |
| 38 | + }, |
| 39 | +
|
| 40 | + data() { |
| 41 | + return { |
| 42 | + onlyAdminsCanCreateEnabled: loadState('settings', 'onlyAdminsCanCreateSystemTags', '1') === '1', |
| 43 | + } |
| 44 | + }, |
| 45 | + methods: { |
| 46 | + t, |
| 47 | + async updateSystemTagsDefault(isEnabled: boolean) { |
| 48 | + try { |
| 49 | + const responseData = await updateOnlyAdminsCanCreateSystemTags(isEnabled) |
| 50 | + console.debug('updateSystemTagsDefault', responseData) |
| 51 | + this.handleResponse({ |
| 52 | + isEnabled, |
| 53 | + status: responseData.ocs?.meta?.status, |
| 54 | + }) |
| 55 | + } catch (e) { |
| 56 | + this.handleResponse({ |
| 57 | + errorMessage: t('settings', 'Unable to update setting'), |
| 58 | + error: e, |
| 59 | + }) |
| 60 | + } |
| 61 | + }, |
| 62 | +
|
| 63 | + handleResponse({ isEnabled, status, errorMessage, error }) { |
| 64 | + if (status === 'ok') { |
| 65 | + this.onlyAdminsCanCreateEnabled = isEnabled |
| 66 | + showSuccess(t('settings', `System tag creation is now ${isEnabled ? 'enabled' : 'disabled'} for non-admin users`)) |
| 67 | + return |
| 68 | + } |
| 69 | +
|
| 70 | + if (errorMessage) { |
| 71 | + showError(errorMessage) |
| 72 | + logger.error(errorMessage, error) |
| 73 | + } |
| 74 | + }, |
| 75 | + }, |
| 76 | +} |
| 77 | +</script> |
0 commit comments