|
| 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-settings" |
| 8 | + class="section"> |
| 9 | + <h2 class="inlineblock"> |
| 10 | + {{ t('settings', 'System Tags') }} |
| 11 | + </h2> |
| 12 | + |
| 13 | + <p class="settings-hint"> |
| 14 | + {{ t('settings', 'Enable or disable system tag creation for non-admin users.') }} |
| 15 | + </p> |
| 16 | + |
| 17 | + <NcCheckboxRadioSwitch type="switch" |
| 18 | + :checked.sync="initialSystemTagsEnabledByDefault" |
| 19 | + @update:checked="onSystemTagsDefaultChange"> |
| 20 | + {{ t('settings', 'Enable') }} |
| 21 | + </NcCheckboxRadioSwitch> |
| 22 | + </div> |
| 23 | +</template> |
| 24 | + |
| 25 | +<script> |
| 26 | +import { loadState } from '@nextcloud/initial-state' |
| 27 | +import { showError } from '@nextcloud/dialogs' |
| 28 | +
|
| 29 | +import { validateBoolean } from '../../utils/validate.js' |
| 30 | +import logger from '../../logger.ts' |
| 31 | +
|
| 32 | +import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' |
| 33 | +
|
| 34 | +const systemTagsEnabledByDefault = true //loadState('settings', 'systemTagsEnabledByDefault', true) |
| 35 | +
|
| 36 | +export default { |
| 37 | + name: 'SystemTagsSettings', |
| 38 | +
|
| 39 | + components: { |
| 40 | + NcCheckboxRadioSwitch, |
| 41 | + }, |
| 42 | +
|
| 43 | + data() { |
| 44 | + return { |
| 45 | + initialSystemTagsEnabledByDefault: systemTagsEnabledByDefault, |
| 46 | + } |
| 47 | + }, |
| 48 | +
|
| 49 | + methods: { |
| 50 | + async onSystemTagsDefaultChange(isEnabled) { |
| 51 | + if (validateBoolean(isEnabled)) { |
| 52 | + await this.updateSystemTagsDefault(isEnabled) |
| 53 | + } |
| 54 | + }, |
| 55 | +
|
| 56 | + async updateSystemTagsDefault(isEnabled) { |
| 57 | + try { |
| 58 | + const responseData = await saveSystemTagsDefault(isEnabled) |
| 59 | + this.handleResponse({ |
| 60 | + isEnabled, |
| 61 | + status: responseData.ocs?.meta?.status, |
| 62 | + }) |
| 63 | + } catch (e) { |
| 64 | + this.handleResponse({ |
| 65 | + errorMessage: t('settings', 'Unable to update systemTags default setting'), |
| 66 | + error: e, |
| 67 | + }) |
| 68 | + } |
| 69 | + }, |
| 70 | +
|
| 71 | + handleResponse({ isEnabled, status, errorMessage, error }) { |
| 72 | + if (status === 'ok') { |
| 73 | + this.initialSystemTagsEnabledByDefault = isEnabled |
| 74 | + } else { |
| 75 | + showError(errorMessage) |
| 76 | + logger.error(errorMessage, error) |
| 77 | + } |
| 78 | + }, |
| 79 | + }, |
| 80 | +} |
| 81 | +</script> |
0 commit comments