Allow deeply nested objects to have media

Without this change, we can’t pass something like `product.attributes.color` as the “model”.

This allows us to do some really weird things, like allow only the first child of some object to have media (e.x.: `model === ‘parent.children[0]’`).

This does NOT prevent problems where the model doesn’t exist (you’ll get an error: `TypeError: Cannot read property 'medias_single' of undefined`), but that’s something that the developer should check (make sure you have the right path).

The Typy package has some other neat things it can do, if you’re interested: https://github.com/flexdinesh/typySigned-off-by: 's avatarMicheal Mand <micheal@kmdwebdesigns.com>
parent a475153c
......@@ -10,5 +10,6 @@ yarn-error.log
.env
composer.lock
package-lock.json
yarn.lock
.phpunit.result.cache
.php_cs.cache
import t from 'typy';
export default {
methods: {
selectMultipleFile(event, model) {
if (typeof this[model].medias_multi === 'undefined') {
this.$set(model, 'medias_multi', {});
const entity = t(this, model).safeObject;
if (typeof entity.medias_multi === 'undefined') {
this.$set(entity, 'medias_multi', {});
}
if (typeof this[model].medias_multi[event.zone] === 'undefined') {
this.$set(this[model].medias_multi, event.zone, { files: [], orders: '' });
if (typeof entity.medias_multi[event.zone] === 'undefined') {
this.$set(entity.medias_multi, event.zone, { files: [], orders: '' });
}
if (event.id !== null && event.id !== undefined) {
const medias = new Set(this[model].medias_multi[event.zone].files);
const medias = new Set(entity.medias_multi[event.zone].files);
medias.add(event.id);
this.$set(this[model].medias_multi[event.zone], 'files', [...medias]);
this.$set(entity.medias_multi[event.zone], 'files', [...medias]);
}
},
unselectFile(event, model) {
const entity = t(this, model).safeObject;
if (event.id !== null && event.id !== undefined) {
const medias = new Set(this[model].medias_multi[event.zone].files);
const medias = new Set(entity.medias_multi[event.zone].files);
medias.delete(event.id);
this.$set(this[model].medias_multi[event.zone], 'files', [...medias]);
this.$set(entity.medias_multi[event.zone], 'files', [...medias]);
}
if (this[model].medias_multi[event.zone].files.length === 0) {
this.$delete(this[model].medias_multi, event.zone);
if (entity.medias_multi[event.zone].files.length === 0) {
this.$delete(entity.medias_multi, event.zone);
}
},
},
......
import t from 'typy';
export default {
methods: {
selectSingleFile(event, model) {
if (typeof this[model].medias_single === 'undefined') {
this.$set(this[model], 'medias_single', {});
const entity = t(this, model).safeObject;
if (typeof entity.medias_single === 'undefined') {
this.$set(entity, 'medias_single', {});
}
if (typeof this[model].medias_single[event.zone] === 'undefined') {
this.$set(this[model].medias_single, event.zone, null);
if (typeof entity.medias_single[event.zone] === 'undefined') {
this.$set(entity.medias_single, event.zone, null);
}
if (event.id !== null && event.id !== undefined) {
this.$set(this[model].medias_single, event.zone, event.id);
this.$set(entity.medias_single, event.zone, event.id);
} else {
this.$delete(this[model].medias_single, event.zone);
this.$delete(entity.medias_single, event.zone);
}
},
},
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
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