|
| 1 | +<!-- |
| 2 | + - @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com> |
| 3 | + - |
| 4 | + - @license GNU AGPL version 3 or any later version |
| 5 | + - |
| 6 | + - This program is free software: you can redistribute it and/or modify |
| 7 | + - it under the terms of the GNU Affero General Public License as |
| 8 | + - published by the Free Software Foundation, either version 3 of the |
| 9 | + - License, or (at your option) any later version. |
| 10 | + - |
| 11 | + - This program is distributed in the hope that it will be useful, |
| 12 | + - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + - GNU Affero General Public License for more details. |
| 15 | + - |
| 16 | + - You should have received a copy of the GNU Affero General Public License |
| 17 | + - along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + - |
| 19 | + --> |
| 20 | + |
| 21 | +<template> |
| 22 | + <NcSettingsSection :title="t('notifications', 'Notifications defaults')" |
| 23 | + :description="t('notifications', 'Configure the default notification settings for new users')"> |
| 24 | + <p> |
| 25 | + <label for="notify_setting_batchtime" class="notification-frequency__label"> |
| 26 | + {{ t('notifications', 'Send email reminders about unhandled notifications after:') }} |
| 27 | + </label> |
| 28 | + <select id="notify_setting_batchtime" |
| 29 | + v-model="config.setting_batchtime" |
| 30 | + class="notification-frequency__select" |
| 31 | + @change="updateSettings()"> |
| 32 | + <option v-for="option in batchtime_options" :key="option.value" :value="option.value"> |
| 33 | + {{ option.text }} |
| 34 | + </option> |
| 35 | + </select> |
| 36 | + </p> |
| 37 | + |
| 38 | + <NcCheckboxRadioSwitch :checked.sync="config.sound_notification" |
| 39 | + @update:checked="updateSettings"> |
| 40 | + {{ t('notifications', 'Play sound when a new notification arrives') }} |
| 41 | + </NcCheckboxRadioSwitch> |
| 42 | + <NcCheckboxRadioSwitch :checked.sync="config.sound_talk" |
| 43 | + @update:checked="updateSettings"> |
| 44 | + {{ t('notifications', 'Play sound when a call started (requires Nextcloud Talk)') }} |
| 45 | + </NcCheckboxRadioSwitch> |
| 46 | + </NcSettingsSection> |
| 47 | +</template> |
| 48 | + |
| 49 | +<script> |
| 50 | +import axios from '@nextcloud/axios' |
| 51 | +import { generateOcsUrl } from '@nextcloud/router' |
| 52 | +import { loadState } from '@nextcloud/initial-state' |
| 53 | +import { showSuccess, showError } from '@nextcloud/dialogs' |
| 54 | +import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' |
| 55 | +import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js' |
| 56 | + |
| 57 | +const EmailFrequency = { |
| 58 | + EMAIL_SEND_OFF: 0, |
| 59 | + EMAIL_SEND_HOURLY: 1, |
| 60 | + EMAIL_SEND_3HOURLY: 2, |
| 61 | + EMAIL_SEND_DAILY: 3, |
| 62 | + EMAIL_SEND_WEEKLY: 4, |
| 63 | +} |
| 64 | + |
| 65 | +export default { |
| 66 | + name: 'AdminSettings', |
| 67 | + components: { |
| 68 | + NcCheckboxRadioSwitch, |
| 69 | + NcSettingsSection, |
| 70 | + }, |
| 71 | + |
| 72 | + data() { |
| 73 | + return { |
| 74 | + batchtime_options: [ |
| 75 | + { text: t('notifications', 'Never'), value: EmailFrequency.EMAIL_SEND_OFF }, |
| 76 | + { text: t('notifications', '1 hour'), value: EmailFrequency.EMAIL_SEND_HOURLY }, |
| 77 | + { text: t('notifications', '3 hours'), value: EmailFrequency.EMAIL_SEND_3HOURLY }, |
| 78 | + { text: t('notifications', '1 day'), value: EmailFrequency.EMAIL_SEND_DAILY }, |
| 79 | + { text: t('notifications', '1 week'), value: EmailFrequency.EMAIL_SEND_WEEKLY }, |
| 80 | + ], |
| 81 | + config: loadState('notifications', 'config'), |
| 82 | + } |
| 83 | + }, |
| 84 | + |
| 85 | + methods: { |
| 86 | + async updateSettings() { |
| 87 | + try { |
| 88 | + const form = new FormData() |
| 89 | + form.append('batchSetting', this.config.setting_batchtime) |
| 90 | + form.append('soundNotification', this.config.sound_notification ? 'yes' : 'no') |
| 91 | + form.append('soundTalk', this.config.sound_talk ? 'yes' : 'no') |
| 92 | + await axios.post(generateOcsUrl('apps/notifications/api/v2/settings/admin'), form) |
| 93 | + showSuccess(t('notifications', 'Your settings have been updated.')) |
| 94 | + } catch (error) { |
| 95 | + showError(t('notifications', 'An error occurred while updating your settings.')) |
| 96 | + console.error(error) |
| 97 | + } |
| 98 | + }, |
| 99 | + }, |
| 100 | +} |
| 101 | + |
| 102 | +</script> |
0 commit comments