|
116 | 116 | </NcButton> |
117 | 117 | </div> |
118 | 118 | <div class="button-group"> |
| 119 | + <NcButton v-if="isEnvelope && canAddFilesToEnvelope" |
| 120 | + wide |
| 121 | + variant="secondary" |
| 122 | + @click="addFileToEnvelope"> |
| 123 | + <template #icon> |
| 124 | + <FilePlus :size="20" /> |
| 125 | + </template> |
| 126 | + {{ t('libresign', 'Add file to envelope') }} |
| 127 | + </NcButton> |
119 | 128 | <NcButton v-if="filesStore.canValidate()" |
120 | 129 | wide |
121 | 130 | variant="secondary" |
@@ -236,6 +245,7 @@ import ChartGantt from 'vue-material-design-icons/ChartGantt.vue' |
236 | 245 | import Delete from 'vue-material-design-icons/Delete.vue' |
237 | 246 | import Draw from 'vue-material-design-icons/Draw.vue' |
238 | 247 | import FileDocument from 'vue-material-design-icons/FileDocument.vue' |
| 248 | +import FilePlus from 'vue-material-design-icons/FilePlus.vue' |
239 | 249 | import Information from 'vue-material-design-icons/Information.vue' |
240 | 250 | import MessageText from 'vue-material-design-icons/MessageText.vue' |
241 | 251 | import OrderNumericAscending from 'vue-material-design-icons/OrderNumericAscending.vue' |
@@ -297,6 +307,7 @@ export default { |
297 | 307 | Delete, |
298 | 308 | Draw, |
299 | 309 | FileDocument, |
| 310 | + FilePlus, |
300 | 311 | IdentifySigner, |
301 | 312 | Information, |
302 | 313 | MessageText, |
@@ -519,6 +530,17 @@ export default { |
519 | 530 | fileName() { |
520 | 531 | return this.filesStore.getFile()?.name ?? '' |
521 | 532 | }, |
| 533 | + isEnvelope() { |
| 534 | + return this.filesStore.getFile()?.nodeType === 'envelope' |
| 535 | + }, |
| 536 | + canAddFilesToEnvelope() { |
| 537 | + const file = this.filesStore.getFile() |
| 538 | + if (!file || file.status !== SIGN_STATUS.DRAFT) { |
| 539 | + return false |
| 540 | + } |
| 541 | + const capabilities = getCapabilities() |
| 542 | + return capabilities?.libresign?.config?.envelope?.['is-available'] === true |
| 543 | + }, |
522 | 544 | size() { |
523 | 545 | return window.matchMedia('(max-width: 512px)').matches ? 'full' : 'normal' |
524 | 546 | }, |
@@ -873,6 +895,48 @@ export default { |
873 | 895 | this.signStore.setDocumentToSign(this.filesStore.getFile()) |
874 | 896 | this.$router.push({ name: 'SignPDF', params: { uuid } }) |
875 | 897 | }, |
| 898 | + addFileToEnvelope() { |
| 899 | + const input = document.createElement('input') |
| 900 | + input.type = 'file' |
| 901 | + input.accept = '.pdf' |
| 902 | + input.multiple = true |
| 903 | + input.onchange = (e) => { |
| 904 | + const files = e.target.files |
| 905 | + if (!files || files.length === 0) return |
| 906 | +
|
| 907 | + this.hasLoading = true |
| 908 | + const envelope = this.filesStore.getFile() |
| 909 | + const formData = new FormData() |
| 910 | +
|
| 911 | + for (const file of files) { |
| 912 | + formData.append('files[]', file) |
| 913 | + } |
| 914 | +
|
| 915 | + axios.post( |
| 916 | + generateOcsUrl('/apps/libresign/api/v1/file/{uuid}/add-file', { uuid: envelope.uuid }), |
| 917 | + formData, |
| 918 | + { |
| 919 | + headers: { |
| 920 | + 'Content-Type': 'multipart/form-data', |
| 921 | + }, |
| 922 | + } |
| 923 | + ) |
| 924 | + .then(({ data }) => { |
| 925 | + showSuccess(data.ocs.data.message) |
| 926 | + }) |
| 927 | + .catch((error) => { |
| 928 | + if (error.response?.data?.ocs?.data?.message) { |
| 929 | + showError(error.response.data.ocs.data.message) |
| 930 | + } else { |
| 931 | + showError(t('libresign', 'Failed to add files to envelope')) |
| 932 | + } |
| 933 | + }) |
| 934 | + .finally(() => { |
| 935 | + this.hasLoading = false |
| 936 | + }) |
| 937 | + } |
| 938 | + input.click() |
| 939 | + }, |
876 | 940 | async save() { |
877 | 941 | this.hasLoading = true |
878 | 942 | try { |
|
0 commit comments