9696 :form =" selectedForm"
9797 :opened.sync =" sidebarOpened"
9898 :active.sync =" sidebarActive"
99- name =" sidebar" />
99+ name =" sidebar"
100+ @transfer:ownership =" openModal" />
100101 </template >
102+ <NcModal v-if =" modal"
103+ ref =" modal"
104+ size =" normal"
105+ :title =" 'Transfer '+selectedForm.title"
106+ name =" NcModal"
107+ :outTransition =" true"
108+ @close =" closeModal" >
109+ <div class =" modal__content" >
110+ <h1 class =" modal_section" >{{ t('forms', 'Transfer ') }} {{ selectedForm.title}}</h1 >
111+ <div class =" modal_section" >
112+ <p class =" modal_text" >{{ t('forms', 'Account to transfer to') }}</p >
113+ <SharingSearchDiv :isOwnershipTransfer =" true" @add-share =" setNewOwner" />
114+ <div class =" selected_user" v-if =" transferData.displayName.length>0" >
115+ <p >{{transferData.displayName}}</p >
116+ <NcButton type =" tertiary-no-background" @click =" clearSelected" >
117+ X
118+ </NcButton >
119+ </div >
120+ </div >
121+ <div class =" modal_section" >
122+ <p class =" modal_text" >{{ t('forms', 'Type ') }} {{confirmationString}} {{ t('forms', ' to confirm') }}</p >
123+ <NcTextField :value.sync =" confirmation" :success =" confirmation===confirmationString" :show-trailing-button =" confirmation !== ''"
124+ @trailing-button-click =" clearText" >
125+ </NcTextField >
126+ </div >
127+ <NcButton :disabled =" confirmation!=confirmationString" type =" error" @click =" onOwnershipTransfer" >
128+ {{ t('forms', 'I understand, transfer this form') }}
129+ </NcButton >
130+ </div >
131+ </NcModal >
101132 </NcContent >
102133</template >
103134
104135<script >
105136import { emit } from ' @nextcloud/event-bus'
106137import { generateOcsUrl } from ' @nextcloud/router'
107138import { loadState } from ' @nextcloud/initial-state'
108- import { showError } from ' @nextcloud/dialogs'
139+ import { showError , showSuccess } from ' @nextcloud/dialogs'
109140import axios from ' @nextcloud/axios'
110141
111142import NcAppContent from ' @nextcloud/vue/dist/Components/NcAppContent.js'
112143import NcAppNavigation from ' @nextcloud/vue/dist/Components/NcAppNavigation.js'
113144import NcAppNavigationCaption from ' @nextcloud/vue/dist/Components/NcAppNavigationCaption.js'
114145import NcAppNavigationNew from ' @nextcloud/vue/dist/Components/NcAppNavigationNew.js'
115146import NcButton from ' @nextcloud/vue/dist/Components/NcButton.js'
147+ import NcTextField from ' @nextcloud/vue/dist/Components/NcTextField.js'
116148import NcContent from ' @nextcloud/vue/dist/Components/NcContent.js'
117149import NcEmptyContent from ' @nextcloud/vue/dist/Components/NcEmptyContent.js'
118150import NcLoadingIcon from ' @nextcloud/vue/dist/Components/NcLoadingIcon.js'
119151import isMobile from ' @nextcloud/vue/dist/Mixins/isMobile.js'
152+ import NcModal from ' @nextcloud/vue/dist/Components/NcModal.js'
153+ import SharingSearchDiv from ' ./components/SidebarTabs/SharingSearchDiv.vue'
154+
120155
121156import IconPlus from ' vue-material-design-icons/Plus.vue'
122157
@@ -141,23 +176,34 @@ export default {
141176 NcContent,
142177 NcEmptyContent,
143178 NcLoadingIcon,
179+ NcModal,
180+ SharingSearchDiv,
181+ NcTextField,
144182 },
145183
146184 mixins: [isMobile, PermissionTypes],
147185
148186 data () {
149187 return {
150188 loading: true ,
189+ modal: false ,
151190 sidebarOpened: false ,
152191 sidebarActive: ' forms-sharing' ,
153192 forms: [],
154193 sharedForms: [],
155-
194+ transferData: { formId: null , userId: null ,displayName: ' ' },
195+ confirmation: ' ' ,
156196 canCreateForms: loadState (appName, ' appConfig' ).canCreateForms ,
157197 }
158198 },
159199
160200 computed: {
201+ canEdit () {
202+ return this .selectedForm .permissions .includes (this .PERMISSION_TYPES .PERMISSION_EDIT )
203+ },
204+ confirmationString (){
205+ return ` ${ this .selectedForm .ownerId } /${ this .selectedForm .title } `
206+ },
161207 hasForms () {
162208 return ! this .noOwnedForms || ! this .noSharedForms
163209 },
@@ -215,12 +261,54 @@ export default {
215261 },
216262 },
217263 },
264+
218265
219266 beforeMount () {
220267 this .loadForms ()
221268 },
222269
223270 methods: {
271+ clearSelected (){
272+ this .transferData = { formId: null , userId: null ,displayName: ' ' }
273+ },
274+ clearText () {
275+ this .confirmation = ' '
276+ },
277+ setNewOwner (share ){
278+ console .log (share)
279+ this .transferData .userId = share .shareWith
280+ this .transferData .formId = this .selectedForm .id
281+ this .transferData .displayName = share .displayName
282+
283+ },
284+ closeModal () {
285+ this .modal = false
286+ showError (t (' forms' , ' Ownership transfer was Cancelled' ))
287+ },
288+ openModal () {
289+ this .modal = true
290+ },
291+ async onOwnershipTransfer () {
292+ this .modal = false
293+ if (this .transferData .formId && this .transferData .userId ) {
294+ try {
295+ await axios .post (generateOcsUrl (' apps/forms/api/v2/form/transfer' ), {
296+ formId: this .transferData .formId ,
297+ uid: this .transferData .userId ,
298+ })
299+ showSuccess (` ${ t (' forms' , ' This form is now owned by' )} ${ this .transferData .displayName } ` )
300+ this .$router .push ({ name: ' root' })
301+
302+ } catch (error) {
303+ logger .error (' Error while transfering form ownership' , { error })
304+ showError (t (' forms' , ' An error occurred while transfering ownership' ))
305+ }
306+
307+ } else {
308+ logger .error (' Null parameters while transfering form ownership' , { transferData: this .tranferData })
309+ showError (t (' forms' , ' An error occurred while transfering ownership' ))
310+ }
311+ },
224312 /**
225313 * Closes the App-Navigation on mobile-devices
226314 */
@@ -348,3 +436,21 @@ export default {
348436 },
349437}
350438< / script>
439+ < style scoped>
440+ .modal__content {
441+ margin: 50px ;
442+ }
443+ .modal_text {
444+ text- align: start;
445+ margin- bottom: 10px ;
446+ }
447+ .modal_section {
448+ margin- bottom: 20px ;
449+ }
450+
451+ .selected_user {
452+ display: flex;
453+ align- items: center;
454+ }
455+
456+ < / style>
0 commit comments