Skip to content

Commit adb928f

Browse files
authored
Merge pull request #6300 from LibreSign/backport/6299/stable31
[stable31] refactor: make possible to use spawnDialog
2 parents 728ddb9 + f2d32ff commit adb928f

File tree

2 files changed

+56
-82
lines changed

2 files changed

+56
-82
lines changed

src/Components/Common/EditNameDialog.vue

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
- SPDX-License-Identifier: AGPL-3.0-or-later
44
-->
55
<template>
6-
<NcDialog v-if="open"
6+
<NcDialog
77
:name="title"
8-
:buttons="dialogButtons"
9-
@closing="$emit('close')">
8+
:buttons="dialogButtons">
109
<NcNoteCard v-if="localSuccessMessage" type="success">
1110
{{ localSuccessMessage }}
1211
</NcNoteCard>
@@ -42,10 +41,6 @@ export default {
4241
NcNoteCard,
4342
},
4443
props: {
45-
open: {
46-
type: Boolean,
47-
required: true,
48-
},
4944
name: {
5045
type: String,
5146
default: '',
@@ -62,15 +57,11 @@ export default {
6257
type: String,
6358
default: 'Enter name',
6459
},
65-
loading: {
66-
type: Boolean,
67-
default: false,
68-
},
6960
},
70-
emits: ['close', 'save'],
61+
emits: ['close'],
7162
data() {
7263
return {
73-
localName: '',
64+
localName: this.name || '',
7465
localSuccessMessage: '',
7566
localErrorMessage: '',
7667
inputId: `edit-name-${Math.random().toString(36).substr(2, 9)}`,
@@ -86,13 +77,13 @@ export default {
8677
{
8778
label: this.t('libresign', 'Cancel'),
8879
callback: () => {
89-
this.$emit('close')
80+
this.handleClose()
9081
},
9182
},
9283
{
9384
label: this.t('libresign', 'Save'),
9485
type: 'primary',
95-
disabled: !this.isNameValid || this.loading,
86+
disabled: !this.isNameValid,
9687
callback: () => {
9788
this.handleSave()
9889
},
@@ -101,16 +92,8 @@ export default {
10192
},
10293
},
10394
watch: {
104-
open(newVal) {
105-
if (newVal) {
106-
this.localName = this.name || ''
107-
this.clearMessages()
108-
}
109-
},
11095
name(newVal) {
111-
if (this.open) {
112-
this.localName = newVal || ''
113-
}
96+
this.localName = newVal || ''
11497
},
11598
},
11699
methods: {
@@ -129,8 +112,11 @@ export default {
129112
this.clearMessages()
130113
this.localErrorMessage = message
131114
},
115+
handleClose() {
116+
this.$emit('close', null)
117+
},
132118
handleSave() {
133-
if (!this.isNameValid || this.loading) {
119+
if (!this.isNameValid) {
134120
return
135121
}
136122
@@ -151,12 +137,7 @@ export default {
151137
return
152138
}
153139
154-
if (trimmedName === this.name) {
155-
this.$emit('close')
156-
return
157-
}
158-
159-
this.$emit('save', trimmedName)
140+
this.$emit('close', trimmedName)
160141
},
161142
},
162143
}

src/Components/Request/RequestPicker.vue

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@
7575
</NcButton>
7676
</template>
7777
</NcDialog>
78-
<EditNameDialog v-if="showEnvelopeNameModal"
79-
:open="showEnvelopeNameModal"
80-
:name="envelopeName"
81-
:title="t('libresign', 'Envelope name')"
82-
:label="t('libresign', 'Enter a name for the envelope')"
83-
:placeholder="t('libresign', 'Envelope name')"
84-
:loading="loading"
85-
@save="confirmEnvelopeName"
86-
@close="cancelEnvelopeName" />
8778
</div>
8879
</template>
8980
<script>
@@ -97,6 +88,7 @@ import { getCapabilities } from '@nextcloud/capabilities'
9788
import { showError } from '@nextcloud/dialogs'
9889
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
9990
import { loadState } from '@nextcloud/initial-state'
91+
import { spawnDialog } from '@nextcloud/vue/functions/dialog'
10092
10193
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
10294
import NcActions from '@nextcloud/vue/components/NcActions'
@@ -116,7 +108,6 @@ export default {
116108
name: 'RequestPicker',
117109
components: {
118110
CloudUploadIcon,
119-
EditNameDialog,
120111
FilePicker,
121112
FolderIcon,
122113
LinkIcon,
@@ -160,8 +151,6 @@ export default {
160151
uploadedBytes: 0,
161152
totalBytes: 0,
162153
uploadStartTime: null,
163-
showEnvelopeNameModal: false,
164-
envelopeName: '',
165154
pendingPaths: [],
166155
pendingFiles: [],
167156
}
@@ -290,9 +279,20 @@ export default {
290279
291280
if (files.length > 1 && this.envelopeEnabled) {
292281
this.pendingFiles = files
293-
this.envelopeName = ''
294-
this.showEnvelopeNameModal = true
282+
const [envelopeName] = await spawnDialog(
283+
EditNameDialog,
284+
{
285+
title: this.t('libresign', 'Envelope name'),
286+
label: this.t('libresign', 'Enter a name for the envelope'),
287+
placeholder: this.t('libresign', 'Envelope name'),
288+
},
289+
)
295290
input.remove()
291+
292+
if (envelopeName) {
293+
await this.upload(files, envelopeName)
294+
}
295+
this.pendingFiles = []
296296
return
297297
}
298298
@@ -329,8 +329,36 @@ export default {
329329
330330
if (this.envelopeEnabled && paths.length > 1) {
331331
this.pendingPaths = paths
332-
this.envelopeName = ''
333-
this.showEnvelopeNameModal = true
332+
const [envelopeName] = await spawnDialog(
333+
EditNameDialog,
334+
{
335+
title: this.t('libresign', 'Envelope name'),
336+
label: this.t('libresign', 'Enter a name for the envelope'),
337+
placeholder: this.t('libresign', 'Envelope name'),
338+
},
339+
)
340+
341+
if (envelopeName) {
342+
const filesPayload = paths.map((path) => ({
343+
file: { path },
344+
name: (path.match(/([^/]*?)(?:\.[^.]*)?$/)[1] ?? ''),
345+
}))
346+
await this.filesStore.upload({
347+
files: filesPayload,
348+
name: envelopeName.trim(),
349+
})
350+
.then((fileId) => {
351+
this.filesStore.selectFile(fileId)
352+
})
353+
.catch(({ response }) => {
354+
showError(response?.data?.ocs?.data?.message || this.t('libresign', 'Upload failed'))
355+
})
356+
.finally(() => {
357+
this.pendingPaths = []
358+
})
359+
} else {
360+
this.pendingPaths = []
361+
}
334362
return
335363
}
336364
@@ -348,41 +376,6 @@ export default {
348376
showError(response.data.ocs.data.message)
349377
})
350378
},
351-
confirmEnvelopeName(newName) {
352-
this.envelopeName = newName
353-
this.showEnvelopeNameModal = false
354-
355-
if (this.pendingPaths.length > 0) {
356-
const filesPayload = this.pendingPaths.map((path) => ({
357-
file: { path },
358-
name: (path.match(/([^/]*?)(?:\.[^.]*)?$/)[1] ?? ''),
359-
}))
360-
this.filesStore.upload({
361-
files: filesPayload,
362-
name: this.envelopeName.trim(),
363-
})
364-
.then((fileId) => {
365-
this.filesStore.selectFile(fileId)
366-
})
367-
.catch(({ response }) => {
368-
showError(response?.data?.ocs?.data?.message || t('libresign', 'Upload failed'))
369-
})
370-
.finally(() => {
371-
this.pendingPaths = []
372-
this.envelopeName = ''
373-
})
374-
return
375-
}
376-
377-
const files = this.pendingFiles
378-
this.upload(files)
379-
},
380-
cancelEnvelopeName() {
381-
this.pendingFiles = []
382-
this.pendingPaths = []
383-
this.envelopeName = ''
384-
this.showEnvelopeNameModal = false
385-
},
386379
},
387380
}
388381
</script>

0 commit comments

Comments
 (0)