|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<template> |
| 7 | + <div v-if="displayCloudIdExchangeButton(propName)"> |
| 8 | + <Actions class="property__actions exchange-cloud-id"> |
| 9 | + <ActionButton @click="openExchangeInviteModal"> |
| 10 | + <template #icon> |
| 11 | + <IconAccountSwitchOutline :size="20" /> |
| 12 | + </template> |
| 13 | + Invite remote user to exchange cloud IDs. This will add the remote user to your contacts list. |
| 14 | + </ActionButton> |
| 15 | + </Actions> |
| 16 | + |
| 17 | + <Modal v-if="showInviteModal" |
| 18 | + id="invitation-modal" |
| 19 | + size="small" |
| 20 | + :clear-view-delay="-1" |
| 21 | + :close-button-contained="false" |
| 22 | + @close="closeExchangeInviteModal" |
| 23 | + class="modal-cloud-id-exchange"> |
| 24 | + |
| 25 | + <InvitationDetails :local-contact="localContact"> |
| 26 | + <template #name> |
| 27 | + <NcTextField type="text" :placeholder="t('contacts', 'name')" :value="displayName" |
| 28 | + @input="setDisplayName" /> |
| 29 | + </template> |
| 30 | + <template #email> |
| 31 | + <NcTextField type="text" :placeholder="t('contacts', 'email')" :value="email" @input="setEmail" /> |
| 32 | + </template> |
| 33 | + <template #personal-message> |
| 34 | + <NcTextArea id="personal-message" ref="textarea" :placeholder="t('contacts', 'personal message')" |
| 35 | + :value="message" :inputmode="inputmode" @input="setMessage" /> |
| 36 | + </template> |
| 37 | + <template #invitation-actions> |
| 38 | + <NcButton @click="sendInvitation"> |
| 39 | + <template #icon> |
| 40 | + <IconLoading v-if="loadingUpdate" :size="20" /> |
| 41 | + <IconCheck v-else :size="20" /> |
| 42 | + </template> |
| 43 | + {{ t('contacts', 'Send') }} |
| 44 | + </NcButton> |
| 45 | + </template> |
| 46 | + </InvitationDetails> |
| 47 | + </Modal> |
| 48 | + |
| 49 | + </div> |
| 50 | + |
| 51 | +</template> |
| 52 | + |
| 53 | +<script> |
| 54 | +import { |
| 55 | + NcActionButton as ActionButton, |
| 56 | + NcActions as Actions, |
| 57 | + NcButton, |
| 58 | + NcLoadingIcon as IconLoading, |
| 59 | + NcModal as Modal, |
| 60 | + NcTextArea, |
| 61 | + NcTextField, |
| 62 | +} from '@nextcloud/vue' |
| 63 | +import Contact from '../models/contact.js' |
| 64 | +import IconAccountSwitchOutline from 'vue-material-design-icons/AccountSwitchOutline.vue' |
| 65 | +import IconCheck from 'vue-material-design-icons/Check.vue' |
| 66 | +import InvitationDetails from './CloudIdExchangeInviteDetails.vue' |
| 67 | +import PropertyMixin from '../mixins/PropertyMixin.js' |
| 68 | +
|
| 69 | +export default { |
| 70 | + name: 'PropertyText', |
| 71 | +
|
| 72 | + components: { |
| 73 | + ActionButton, |
| 74 | + Actions, |
| 75 | + Contact, |
| 76 | + IconAccountSwitchOutline, |
| 77 | + IconCheck, |
| 78 | + IconLoading, |
| 79 | + InvitationDetails, |
| 80 | + Modal, |
| 81 | + NcButton, |
| 82 | + NcTextArea, |
| 83 | + NcTextField, |
| 84 | + }, |
| 85 | + mixins: [PropertyMixin], |
| 86 | + props: { |
| 87 | + localContact: { |
| 88 | + type: Contact, |
| 89 | + default: null, |
| 90 | + }, |
| 91 | + propName: { |
| 92 | + type: String, |
| 93 | + default: 'text', |
| 94 | + required: true, |
| 95 | + }, |
| 96 | + value: { |
| 97 | + type: String, |
| 98 | + default: '', |
| 99 | + required: true, |
| 100 | + }, |
| 101 | + contactFormEditMode: { |
| 102 | + type: Boolean, |
| 103 | + default: false |
| 104 | + } |
| 105 | + }, |
| 106 | + computed: { |
| 107 | + displayName() { |
| 108 | + return this.localContact.displayName |
| 109 | + }, |
| 110 | + email() { |
| 111 | + return this.localContact.email |
| 112 | + } |
| 113 | + }, |
| 114 | + emits: [ |
| 115 | + 'setContactFormEditModeEvent:value' |
| 116 | + ], |
| 117 | + methods: { |
| 118 | + displayCloudIdExchangeButton(propName) { |
| 119 | + // TODO add check for: |
| 120 | + // 1. cloud ID exchange invitation capability present ? |
| 121 | + // 2. is it active ? |
| 122 | + if (propName === 'cloud' && this.localContact && !(typeof this.value === 'string' || this.value instanceof String)) { |
| 123 | + console.log(`displayCloudIdExchangeButton(${propName}): true`) |
| 124 | + this.isNewContact = false |
| 125 | + return true |
| 126 | + } |
| 127 | + return false |
| 128 | + }, |
| 129 | + closeExchangeInviteModal() { |
| 130 | + this.showInviteModal = false |
| 131 | + }, |
| 132 | + openExchangeInviteModal() { |
| 133 | + this.showInviteModal = true |
| 134 | + }, |
| 135 | + sendInvitation() { |
| 136 | + console.log('contactFormEditMode: ' + this.contactFormEditMode) |
| 137 | + this.localContact.properties.find(p => p.name === 'fn').setValue(this.localDisplayName) |
| 138 | + this.localContact.properties.find(p => p.name === 'email').setValue(this.localEmail) |
| 139 | + this.updateContact() |
| 140 | + // TODO on close: |
| 141 | + // - display saved contact; like when save button is pressed |
| 142 | + // - the cloud ID prop should be displayed saying '... awaiting cloud ID exchange invite response' |
| 143 | + this.$emit('setContactFormEditModeEvent:value', false) |
| 144 | + this.showInviteModal = false |
| 145 | + }, |
| 146 | + setDisplayName(e) { |
| 147 | + this.localDisplayName = e.target.value |
| 148 | + }, |
| 149 | + setEmail(e) { |
| 150 | + this.localEmail = e.target.value |
| 151 | + }, |
| 152 | + setMessage(e) { |
| 153 | + this.localMessage = e.target.value |
| 154 | + }, |
| 155 | + updateContact() { |
| 156 | + this.fixed = false |
| 157 | + this.loadingUpdate = true |
| 158 | + try { |
| 159 | + this.$store.dispatch('updateContact', this.localContact) |
| 160 | + } finally { |
| 161 | + this.loadingUpdate = false |
| 162 | + } |
| 163 | + }, |
| 164 | + }, |
| 165 | + data() { |
| 166 | + return { |
| 167 | + showInviteModal: false, |
| 168 | + isNewContact: false, |
| 169 | + localDisplayName: '', |
| 170 | + localEmail: '', |
| 171 | + localMessage: '', |
| 172 | + loadingUpdate: false, |
| 173 | + } |
| 174 | + } |
| 175 | +} |
| 176 | +</script> |
| 177 | + |
| 178 | +<style lang="scss"> |
| 179 | +div.property.property-cloud { |
| 180 | + position: relative; |
| 181 | +} |
| 182 | +</style> |
| 183 | + |
| 184 | +<style lang="scss" scoped> |
| 185 | +#invitation-modal { |
| 186 | + background-color: rgba(0, 0, 0, .5); |
| 187 | + div.modal-container__content { |
| 188 | + margin: 0 1em 1em; |
| 189 | + } |
| 190 | +} |
| 191 | +
|
| 192 | +div.property.property-cloud { |
| 193 | + button.exchange-cloud-id { |
| 194 | + position: absolute; |
| 195 | + top: 0; |
| 196 | + right: 4em; |
| 197 | + } |
| 198 | +} |
| 199 | +
|
| 200 | +</style> |
0 commit comments