Fixes terms forms not being updated with list.

This commit is contained in:
Mateus Machado Luna 2019-03-14 14:29:41 -03:00
parent fd994eff47
commit 3503f70df5
4 changed files with 56 additions and 7 deletions

View File

@ -221,6 +221,7 @@
description: this.editForm.description, description: this.editForm.description,
parent: this.hasParent ? this.editForm.parent : 0, parent: this.hasParent ? this.editForm.parent : 0,
header_image_id: this.editForm.header_image_id, header_image_id: this.editForm.header_image_id,
header_image: this.editForm.header_image,
}; };
this.fillExtraFormData(data); this.fillExtraFormData(data);
this.sendChildTerm({ this.sendChildTerm({
@ -244,11 +245,12 @@
} else { } else {
let data = { let data = {
term_id: this.editForm.id, id: this.editForm.id,
name: this.editForm.name, name: this.editForm.name,
description: this.editForm.description, description: this.editForm.description,
parent: this.hasParent ? this.editForm.parent : 0, parent: this.hasParent ? this.editForm.parent : 0,
header_image_id: this.editForm.header_image_id, header_image_id: this.editForm.header_image_id,
header_image: this.editForm.header_image,
} }
this.fillExtraFormData(data); this.fillExtraFormData(data);
this.updateChildTerm({ this.updateChildTerm({

View File

@ -62,6 +62,7 @@
</a> </a>
</span> </span>
</div> </div>
<transition-group <transition-group
class="children-area" class="children-area"
name="filter-item"> name="filter-item">
@ -242,7 +243,27 @@ export default {
eventOnEditTerm() { eventOnEditTerm() {
this.isEditingTerm = true; this.isEditingTerm = true;
}, },
eventOnTermEditionSaved() { eventOnTermEditionSaved($event) {
if (this.term.id == $event.term.id) {
this.$set(this.term, 'description', $event.term.description);
this.$set(this.term, 'header_image', $event.term.header_image);
this.$set(this.term, 'header_image_id', $event.term.header_image_id);
this.$set(this.term, 'name', $event.term.name);
this.$set(this.term, 'parent', $event.term.parent);
this.$set(this.term, 'id', $event.term.id);
} else if (this.term.children != undefined) {
for (let i = 0; i < this.term.children.length; i++) {
if (this.term.children[i].id == $event.term.id) {
this.$set(this.term.children[i], 'description', $event.term.description);
this.$set(this.term.children[i], 'header_image', $event.term.header_image);
this.$set(this.term.children[i], 'header_image_id', $event.term.header_image_id);
this.$set(this.term.children[i], 'name', $event.term.name);
this.$set(this.term.children[i], 'parent', $event.term.parent);
this.$set(this.term.children[i], 'id', $event.term.id);
}
}
}
this.isEditingTerm = false; this.isEditingTerm = false;
this.term.opened = false; this.term.opened = false;
}, },

View File

@ -242,6 +242,29 @@ export default {
}, },
onTermEditionFinished($event) { onTermEditionFinished($event) {
this.$termsListBus.onTermEditionSaved($event); this.$termsListBus.onTermEditionSaved($event);
for (let i = 0; i < this.termsList.length; i++) {
if (this.termsList[i].id == $event.term.id) {
this.$set(this.termsList[i], 'description', $event.term.description);
this.$set(this.termsList[i], 'header_image', $event.term.header_image);
this.$set(this.termsList[i], 'header_image_id', $event.term.header_image_id);
this.$set(this.termsList[i], 'name', $event.term.name);
this.$set(this.termsList[i], 'parent', $event.term.parent);
this.$set(this.termsList[i], 'id', $event.term.id);
}
else if (this.termsList[i].children != undefined) {
for (let j = 0; j < this.termsList[i].children.length; j++) {
if (this.termsList[i].children[j].id == $event.term.id) {
this.$set(this.termsList[i].children[j], 'description', $event.term.description);
this.$set(this.termsList[i].children[j], 'header_image', $event.term.header_image);
this.$set(this.termsList[i].children[j], 'header_image_id', $event.term.header_image_id);
this.$set(this.termsList[i].children[j], 'name', $event.term.name);
this.$set(this.termsList[i].children[j], 'parent', $event.term.parent);
this.$set(this.termsList[i].children[j], 'id', $event.term.id);
}
}
}
}
}, },
onTermEditionCanceled($event) { onTermEditionCanceled($event) {

View File

@ -113,13 +113,14 @@ export const fetchTaxonomyName = ({ commit }, taxonomyId) => {
}; };
// TAXONOMY TERMS // TAXONOMY TERMS
export const sendTerm = ({commit}, { taxonomyId, name, description, parent, headerImageId }) => { export const sendTerm = ({commit}, { taxonomyId, name, description, parent, headerImageId, headerImage }) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.post('/taxonomy/' + taxonomyId + '/terms/', { axios.tainacan.post('/taxonomy/' + taxonomyId + '/terms/', {
name: name, name: name,
description: description, description: description,
parent: parent, parent: parent,
header_image_id: headerImageId, header_image_id: headerImageId,
header_image: headerImage
}) })
.then( res => { .then( res => {
let term = res.data; let term = res.data;
@ -146,13 +147,15 @@ export const deleteTerm = ({ commit }, { taxonomyId, termId }) => {
}); });
}; };
export const updateTerm = ({ commit }, { taxonomyId, termId, name, description, parent, headerImageId }) => { export const updateTerm = ({ commit }, { taxonomyId, id, name, description, parent, headerImageId, headerImage }) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${termId}`, { axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${id}`, {
name: name, name: name,
description: description, description: description,
parent: parent, parent: parent,
header_image_id: headerImageId, header_image_id: headerImageId,
header_image: headerImage,
}) })
.then( res => { .then( res => {
let term = res.data; let term = res.data;
@ -251,7 +254,7 @@ export const sendChildTerm = ({ commit }, { taxonomyId, term }) => {
export const updateChildTerm = ({ commit }, { taxonomyId, term }) => { export const updateChildTerm = ({ commit }, { taxonomyId, term }) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${term.term_id}`, term) axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${term.id}`, term)
.then( res => { .then( res => {
let updatedTerm = res.data; let updatedTerm = res.data;
commit('updateChildTerm', { term: updatedTerm, parent: updatedTerm.parent, oldParent: term.parent }); commit('updateChildTerm', { term: updatedTerm, parent: updatedTerm.parent, oldParent: term.parent });