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 ...@@ -10,5 +10,6 @@ yarn-error.log
.env .env
composer.lock composer.lock
package-lock.json package-lock.json
yarn.lock
.phpunit.result.cache .phpunit.result.cache
.php_cs.cache .php_cs.cache
import t from 'typy';
export default { export default {
methods: { methods: {
selectMultipleFile(event, model) { selectMultipleFile(event, model) {
if (typeof this[model].medias_multi === 'undefined') { const entity = t(this, model).safeObject;
this.$set(model, 'medias_multi', {});
if (typeof entity.medias_multi === 'undefined') {
this.$set(entity, 'medias_multi', {});
} }
if (typeof this[model].medias_multi[event.zone] === 'undefined') { if (typeof entity.medias_multi[event.zone] === 'undefined') {
this.$set(this[model].medias_multi, event.zone, { files: [], orders: '' }); this.$set(entity.medias_multi, event.zone, { files: [], orders: '' });
} }
if (event.id !== null && event.id !== undefined) { 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); 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) { unselectFile(event, model) {
const entity = t(this, model).safeObject;
if (event.id !== null && event.id !== undefined) { 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); 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) { if (entity.medias_multi[event.zone].files.length === 0) {
this.$delete(this[model].medias_multi, event.zone); this.$delete(entity.medias_multi, event.zone);
} }
}, },
}, },
......
import t from 'typy';
export default { export default {
methods: { methods: {
selectSingleFile(event, model) { selectSingleFile(event, model) {
if (typeof this[model].medias_single === 'undefined') { const entity = t(this, model).safeObject;
this.$set(this[model], 'medias_single', {});
if (typeof entity.medias_single === 'undefined') {
this.$set(entity, 'medias_single', {});
} }
if (typeof this[model].medias_single[event.zone] === 'undefined') { if (typeof entity.medias_single[event.zone] === 'undefined') {
this.$set(this[model].medias_single, event.zone, null); this.$set(entity.medias_single, event.zone, null);
} }
if (event.id !== null && event.id !== undefined) { 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 { } 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 source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"/js/app.js": "/js/app.js", "/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css" "/css/app.css": "/css/app.css"
} }
\ No newline at end of file
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