|
| 1 | +<!-- |
| 2 | + - @copyright 2021 Christopher Ng <chrng8@gmail.com> |
| 3 | + - |
| 4 | + - @author 2021 Christopher Ng <chrng8@gmail.com> |
| 5 | + - |
| 6 | + - @license GNU AGPL version 3 or any later version |
| 7 | + - |
| 8 | + - This program is free software: you can redistribute it and/or modify |
| 9 | + - it under the terms of the GNU Affero General Public License as |
| 10 | + - published by the Free Software Foundation, either version 3 of the |
| 11 | + - License, or (at your option) any later version. |
| 12 | + - |
| 13 | + - This program is distributed in the hope that it will be useful, |
| 14 | + - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + - GNU Affero General Public License for more details. |
| 17 | + - |
| 18 | + - You should have received a copy of the GNU Affero General Public License |
| 19 | + - along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + --> |
| 21 | + |
| 22 | +<template> |
| 23 | + <form id="emailform" class="section"> |
| 24 | + <h3> |
| 25 | + <label for="email">{{ t('settings', 'Emails') }}</label> |
| 26 | + <a href="#" class="federation-menu" :aria-label="t('settings', 'Change privacy level of email')"> |
| 27 | + <span class="icon-federation-menu icon-password"> |
| 28 | + <span class="icon-triangle-s"></span> |
| 29 | + </span> |
| 30 | + </a> |
| 31 | + <Actions> |
| 32 | + <ActionButton icon="icon-add" @click.stop.prevent="addEmails(email, additionalEmails)"> |
| 33 | + {{ t('settings', 'Add email address') }} |
| 34 | + </ActionButton> |
| 35 | + </Actions> |
| 36 | + </h3> |
| 37 | + <input |
| 38 | + type="email" |
| 39 | + name="email" |
| 40 | + id="email" |
| 41 | + v-model="email" |
| 42 | + :placeholder="t('settings', 'Your email address')" /> |
| 43 | + <input |
| 44 | + v-for="(email, index) in additionalEmails" |
| 45 | + type="email" |
| 46 | + name="additionalEmail[]" |
| 47 | + :id="`additionalEmail-${index}`" |
| 48 | + v-model="email.value" |
| 49 | + :placeholder="t('settings', `Additional email address ${index+1}`)" |
| 50 | + :key="index" /> |
| 51 | + <input type="hidden" id="emailscope" value="emailScope"> |
| 52 | + </form> |
| 53 | +</template> |
| 54 | + |
| 55 | +<script> |
| 56 | +import { Actions, ActionButton } from '@nextcloud/vue' |
| 57 | +import axios from '@nextcloud/axios' |
| 58 | +import * as auth from '@nextcloud/auth' |
| 59 | +import * as router from '@nextcloud/router' |
| 60 | +
|
| 61 | +export default { |
| 62 | + name: 'EmailSection', |
| 63 | + components: { |
| 64 | + Actions, |
| 65 | + ActionButton, |
| 66 | + }, |
| 67 | + props: { |
| 68 | + initialEmails: { |
| 69 | + type: Array, |
| 70 | + required: true, |
| 71 | + }, |
| 72 | + }, |
| 73 | + data() { |
| 74 | + /* eslint-disable */ |
| 75 | + console.log(this.initialEmails) |
| 76 | + return { |
| 77 | + email: this.initialEmails[0], |
| 78 | + additionalEmails: this.initialEmails.slice(1).map(email => ({ value: email })), |
| 79 | + } |
| 80 | + }, |
| 81 | + methods: { |
| 82 | + async addEmails(email, additionalEmails) { |
| 83 | + const userId = auth.getCurrentUser().uid |
| 84 | + // TODO upgrade @nextcloud/router to v2.0 so we can remove the .slice() trailing slash hack |
| 85 | + const url = router.generateOcsUrl(`cloud/users/${userId}`, 2).slice(0, -1) |
| 86 | +
|
| 87 | + // Set the primary email |
| 88 | + const res = await axios.put(url, { |
| 89 | + key: 'email', |
| 90 | + value: email, |
| 91 | + }) |
| 92 | + // console.log(res.data) |
| 93 | +
|
| 94 | + // Set additional emails |
| 95 | + const resp = await axios.put(url, { |
| 96 | + key: 'additional_mail', |
| 97 | + value: additionalEmails.map(({ value }) => value), |
| 98 | + }) |
| 99 | + // console.log(res.data) |
| 100 | +
|
| 101 | + additionalEmails.push({ value: '' }) |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | +</script> |
| 106 | + |
| 107 | +<style scoped> |
| 108 | +</style> |
0 commit comments