Commit 61b9641c authored by Micheal Mand's avatar Micheal Mand

Fix reactivity of the medias data

Every so often, selected files would fail to be sent to the server along with the form.
parent b729c09d
export default { export default {
methods: { methods: {
selectMultipleFile(event, model) { selectMultipleFile(event, model) {
if (!this[model].medias_multi) { if (typeof this[model].medias_multi === 'undefined') {
this[model].medias_multi = {}; this.$set(model, 'medias_multi', {});
} }
if (!this[model].medias_multi[event.zone]) {
this[model].medias_multi[event.zone] = { files: [] }; if (typeof this[model].medias_multi[event.zone] === 'undefined') {
this.$set(this[model].medias_multi, event.zone, { files: [], orders: '' });
}
if (event.id !== null && event.id !== undefined) {
const medias = new Set(this[model].medias_multi[event.zone].files);
medias.add(event.id);
this.$set(this[model].medias_multi[event.zone], 'files', [...medias]);
} }
this[model].medias_multi[event.zone].files.push(event.id);
}, },
unselectFile(event, model) { unselectFile(event, model) {
if (!this[model].medias_multi) { if (event.id !== null && event.id !== undefined) {
this[model].medias_multi = {}; const medias = new Set(this[model].medias_multi[event.zone].files);
medias.delete(event.id);
this.$set(this[model].medias_multi[event.zone], 'files', [...medias]);
} }
if (!this[model].medias_multi[event.zone]) {
this[model].medias_multi[event.zone] = { files: [] }; if (this[model].medias_multi[event.zone].files.length === 0) {
if (this.$refs['multiple-media'] !== undefined && this.$refs['multiple-media'].selectedMedia !== undefined && !_.isEmpty(this.$refs['multiple-media'].selectedMedia)) { this.$delete(this[model].medias_multi, event.zone);
_.forEach(this.$refs['multiple-media'].selectedMedia, (file, key) => {
this[model].medias_multi[event.zone].files.push(file.id);
});
}
} }
this[model].medias_multi[event.zone].files = _.reject(this[model].medias_multi[event.zone].files, media => media === event.id);
}, },
}, },
}; };
export default { export default {
methods: { methods: {
selectSingleFile(event, model) { selectSingleFile(event, model) {
this[model].medias_single = _.merge(this[model].medias_single, { if (typeof this[model].medias_single === 'undefined') {
[event.zone]: event.id, this.$set(this[model], 'medias_single', {});
}); }
if (typeof this[model].medias_single[event.zone] === 'undefined') {
this.$set(this[model].medias_single, event.zone, null);
}
if (event.id !== null && event.id !== undefined) {
this.$set(this[model].medias_single, event.zone, event.id);
} else {
this.$delete(this[model].medias_single, event.zone);
}
}, },
}, },
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment