+
@@ -49,9 +50,9 @@
import TextForm from '@/components/content-forms/TextForm';
import TrashIcon from '@/components/icons/TrashIcon';
- import NEW_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/addContentBlock.gql';
-
export default {
+ props: ['content-block'],
+
components: {
Modal,
ContentBlockElementChooserWidget,
@@ -66,6 +67,13 @@
TrashIcon
},
+ data() {
+ return {
+ error: false,
+ localContentBlock: Object.assign({}, this.contentBlock)
+ }
+ },
+
methods: {
type(element) {
switch (element.type) {
@@ -85,8 +93,8 @@
return 'content-block-element-chooser-widget'
},
_updateProperty(value, index, key) {
- this.elements.splice(index, 1, {
- ...this.elements[index],
+ this.localContentBlock.elements.splice(index, 1, {
+ ...this.localContentBlock.elements[index],
[key]: value
});
},
@@ -94,6 +102,7 @@
this._updateProperty(value, index, 'url')
},
changeLinkText(value, index) {
+ // debugger;
this._updateProperty(value, index, 'text')
},
changeVideoUrl(value, index) {
@@ -106,13 +115,13 @@
this._updateProperty(value, index, 'text')
},
removeElement(index) {
- this.elements.splice(index, 1);
+ this.localContentBlock.elements.splice(index, 1);
},
addElement(index) {
- this.elements.splice(index + 1, 0, {})
+ this.localContentBlock.elements.splice(index + 1, 0, {})
},
updateTitle(title) {
- this.title = title;
+ this.localContentBlock.title = title;
this.error = false;
},
changeType(index, type) {
@@ -147,55 +156,14 @@
break;
}
- this.elements.splice(index, 1, el);
+ this.localContentBlock.elements.splice(index, 1, el);
},
- hideModal() {
- this.$store.dispatch('resetContentBlock');
- this.$store.dispatch('hideModal');
- },
- saveContentBlock() {
- if (!this.title) {
+ save() {
+ if (!this.localContentBlock.title) {
this.error = true;
return false;
}
- this.$apollo.mutate({
- mutation: NEW_CONTENT_BLOCK_MUTATION,
- variables: {
- input: {
- contentBlock: {
- title: this.title,
- contents: this.elements.filter(value => Object.keys(value).length > 0)
- },
- after: this.$store.state.contentBlockPosition.after,
- parent: this.$store.state.contentBlockPosition.parent
- }
- },
- update: () => {
- this.$store.dispatch('updateContentBlocks');
- this.hideModal();
- }
- });
- }
- },
-
- data() {
- return {
- title: '',
- elements: [
- {}
- // {
- // type: 'image'
- // },
- // {
- // type: 'video',
- // url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
- // },
- // {
- // type: 'video',
- // url: 'https://vimeo.com/267384185'
- // }
- ],
- error: false
+ this.$emit('save', this.localContentBlock);
}
}
}
@@ -204,7 +172,7 @@