-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hamza221 <[email protected]>
- Loading branch information
Showing
5 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<!-- | ||
- @copyright Copyright (c) 2022 Hamza Mahjoubi <hamzamahjoubi221@gmail.com> | ||
- | ||
- @author Hamza Mahjoubi <[email protected]> | ||
- | ||
- @license AGPL-3.0-or-later | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program is distributed in the hope that it will be useful, | ||
- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
- GNU Affero General Public License for more details. | ||
- | ||
- You should have received a copy of the GNU Affero General Public License | ||
- along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
- | ||
--> | ||
|
||
<template> | ||
<div> | ||
<NcButton @click="openModal"> | ||
{{ t('forms', 'Transfer ownership') }} | ||
</NcButton> | ||
<NcModal v-if="showModal" | ||
:title="'Transfer ' + form.title" | ||
:out-transition="true" | ||
@close="closeModal"> | ||
<div class="modal-content"> | ||
<h1 class="modal-content__section"> | ||
{{ t('forms', 'Transfer ') }} {{ form.title }} | ||
</h1> | ||
<div class="modal-content__section"> | ||
<p class="modal-content__text"> | ||
{{ t('forms', 'Account to transfer to') }} | ||
</p> | ||
<SharingSearchDiv :is-ownership-transfer="true" @add-share="setNewOwner" /> | ||
<div v-if="transferData.displayName.length > 0" class="modal-content__user"> | ||
<p>{{ transferData.displayName }}</p> | ||
<NcButton type="tertiary-no-background" @click="clearSelected"> | ||
X | ||
</NcButton> | ||
</div> | ||
</div> | ||
<div class="modal-content__section"> | ||
<p class="modal-content__text"> | ||
{{ t('forms', 'Type ') }} <strong> {{ confirmationString }} </strong>{{ t('forms', ' to confirm') }} | ||
</p> | ||
<NcTextField :value.sync="confirmationInput" | ||
:success="confirmationInput === confirmationString"/> | ||
</div> | ||
<NcButton :disabled="confirmationInput !== confirmationString" type="error" @click="onOwnershipTransfer"> | ||
{{ t('forms', 'I understand, transfer this form') }} | ||
</NcButton> | ||
</div> | ||
</NcModal> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { showSuccess } from '@nextcloud/dialogs' | ||
import { generateOcsUrl } from '@nextcloud/router' | ||
import axios from '@nextcloud/axios' | ||
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' | ||
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js' | ||
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js' | ||
|
||
import logger from '../../utils/Logger.js' | ||
import SharingSearchDiv from './SharingSearchDiv.vue' | ||
|
||
export default { | ||
components: { | ||
NcButton, | ||
NcModal, | ||
NcTextField, | ||
SharingSearchDiv, | ||
}, | ||
|
||
props: { | ||
form: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
|
||
data() { | ||
return { | ||
showModal: false, | ||
transferData: { formId: null, userId: null, displayName: '' }, | ||
confirmationInput: '', | ||
loading: false, | ||
} | ||
}, | ||
|
||
computed: { | ||
confirmationString() { | ||
return `${this.form.ownerId}/${this.form.title}` | ||
}, | ||
}, | ||
|
||
methods: { | ||
clearText() { | ||
this.confirmationInput = '' | ||
}, | ||
closeModal() { | ||
this.showModal = false | ||
}, | ||
setNewOwner(share) { | ||
this.transferData.userId = share.shareWith | ||
this.transferData.formId = this.form.id | ||
this.transferData.displayName = share.displayName | ||
|
||
}, | ||
openModal() { | ||
this.showModal = true | ||
}, | ||
async onOwnershipTransfer() { | ||
this.showModal = false | ||
if (this.transferData.formId && this.transferData.userId) { | ||
try { | ||
await axios.post(generateOcsUrl('apps/forms/api/v2/form/transfer'), { | ||
formId: this.transferData.formId, | ||
uid: this.transferData.userId, | ||
}) | ||
showSuccess(`${t('forms', 'This form is now owned by')} ${this.transferData.displayName}`) | ||
this.$router.push({ name: 'root' }) | ||
location.reload() | ||
|
||
} catch (error) { | ||
logger.error('Error while transfering form ownership', { error }) | ||
showError(t('forms', 'An error occurred while transfering ownership')) | ||
} | ||
|
||
} else { | ||
logger.error('Null parameters while transfering form ownership', { transferData: this.tranferData }) | ||
showError(t('forms', 'An error occurred while transfering ownership')) | ||
} | ||
}, | ||
clearSelected() { | ||
this.transferData = { formId: null, userId: null, displayName: '' } | ||
}, | ||
|
||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.modal-content { | ||
margin: 50px; | ||
|
||
&__text{ | ||
text-align: start; | ||
margin-bottom: 10px; | ||
} | ||
|
||
&__section{ | ||
text-align: start; | ||
margin-bottom: 10px; | ||
} | ||
|
||
&__user { | ||
display: flex; | ||
align-items: center; | ||
} | ||
} | ||
</style> |