From caa6736330312aa56df00d0ecfa2dbf666c300cb Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 15 May 2019 15:14:32 +0200 Subject: [PATCH] Handle document upload in image form --- .../content-block-form/ContentsForm.vue | 13 ++- .../components/content-forms/DocumentForm.vue | 19 ++++- .../components/content-forms/ImageForm.vue | 84 ++++++++++++++----- client/src/components/modules/Module.vue | 1 - 4 files changed, 90 insertions(+), 27 deletions(-) diff --git a/client/src/components/content-block-form/ContentsForm.vue b/client/src/components/content-block-form/ContentsForm.vue index c646c33e..4df224d3 100644 --- a/client/src/components/content-block-form/ContentsForm.vue +++ b/client/src/components/content-block-form/ContentsForm.vue @@ -39,6 +39,8 @@ v-on:video-change-url="changeVideoUrl" + @switch-to-document="switchToDocument" + v-on:assignment-change-title="changeAssignmentTitle" v-on:assignment-change-assignment="changeAssignmentAssignment" > @@ -200,10 +202,10 @@ this.localContentBlock.title = title; this.error = false; }, - changeType(index, type) { + changeType(index, type, value) { let el = { type: type, - value: {} + value: Object.assign({}, value) }; switch (type) { case 'text_block': @@ -234,9 +236,9 @@ case 'document_block': el = { ...el, - value: { + value: Object.assign({ url: '' - } + }, value) }; break; case 'image_url_block': @@ -262,6 +264,9 @@ }, setContentBlockType(checked, localContentBlock) { this.localContentBlock.isAssignment = checked; + }, + switchToDocument(index, value) { + this.changeType(index, 'document_block', value) } } } diff --git a/client/src/components/content-forms/DocumentForm.vue b/client/src/components/content-forms/DocumentForm.vue index a1d9629d..bc6fe4da 100644 --- a/client/src/components/content-forms/DocumentForm.vue +++ b/client/src/components/content-forms/DocumentForm.vue @@ -2,7 +2,7 @@
- {{previewUrl}} + {{previewLink}}
@@ -18,12 +18,20 @@ this.$emit('link-change-url', url, this.index) }); }, + computed: { - previewUrl: function () { + previewUrl() { if (this.value && this.value.url) { return this.value.url; } return null; + }, + previewLink() { + if (this.value && this.value.url) { + const parts = this.value.url.split('/'); + return parts[parts.length - 1] + } + return ''; } } } @@ -32,7 +40,12 @@