2021-12-19 01:16:02 +01:00
|
|
|
-<template>
|
2021-12-21 13:58:48 +01:00
|
|
|
<ui-property v-if="loaded && !field.hidden(value)"
|
|
|
|
|
:field="field.path"
|
|
|
|
|
:hide-label="field.hideLabel"
|
|
|
|
|
:label="field.label"
|
|
|
|
|
:description="description"
|
|
|
|
|
:required="!field.optional(value)"
|
2021-12-09 10:51:10 +01:00
|
|
|
:disabled="isDisabled"
|
2021-12-21 13:58:48 +01:00
|
|
|
:vertical="!field.horizontal"
|
2021-12-22 10:55:40 +01:00
|
|
|
:class="{'is-disabled': isDisabled }"
|
|
|
|
|
:locked="isLocked"
|
|
|
|
|
:can-unlock="canUnlock || false"
|
|
|
|
|
@unlock="unlock"
|
|
|
|
|
@lock="lock"
|
2021-12-21 13:58:48 +01:00
|
|
|
>
|
2021-12-21 14:41:50 +01:00
|
|
|
<component :is="field.component" v-bind="field.options"
|
|
|
|
|
:value="model"
|
|
|
|
|
:config="config"
|
|
|
|
|
@input="onChange" />
|
2021-12-21 13:58:48 +01:00
|
|
|
<p v-if="field.helpText" class="ui-property-help" v-localize="field.helpText"></p>
|
|
|
|
|
</ui-property>
|
2021-12-09 10:51:10 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-12-22 15:41:11 +01:00
|
|
|
import { selectorToArray, setObjectValue } from '../utils';
|
|
|
|
|
import { localize } from '../services/localization';
|
2021-12-21 13:58:48 +01:00
|
|
|
import { defineComponent } from 'vue';
|
2021-12-09 10:51:10 +01:00
|
|
|
//import Overlay from 'zero/helpers/overlay.js';
|
|
|
|
|
|
2021-12-21 13:58:48 +01:00
|
|
|
export default defineComponent({
|
2021-12-09 10:51:10 +01:00
|
|
|
name: 'uiEditorComponent',
|
|
|
|
|
|
|
|
|
|
inject: [ 'meta' ],
|
|
|
|
|
|
|
|
|
|
props: {
|
2021-12-21 13:58:48 +01:00
|
|
|
field: {
|
2021-12-09 10:51:10 +01:00
|
|
|
type: Object,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
2021-12-14 14:21:48 +01:00
|
|
|
value: {
|
2021-12-09 10:51:10 +01:00
|
|
|
type: Object,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
disabled: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
2021-12-21 14:41:50 +01:00
|
|
|
system: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2022-01-13 14:41:44 +01:00
|
|
|
}
|
2021-12-09 10:51:10 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
watch: {
|
2021-12-14 14:21:48 +01:00
|
|
|
value: {
|
2021-12-09 10:51:10 +01:00
|
|
|
deep: true,
|
|
|
|
|
handler: function ()
|
|
|
|
|
{
|
|
|
|
|
this.rebuildModel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
data: () => ({
|
|
|
|
|
model: null,
|
2021-12-21 14:41:50 +01:00
|
|
|
config: {},
|
2021-12-09 10:51:10 +01:00
|
|
|
loaded: false,
|
|
|
|
|
manualDisabled: false,
|
|
|
|
|
selector: null
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
mounted()
|
|
|
|
|
{
|
|
|
|
|
this.rebuildModel();
|
|
|
|
|
this.loaded = true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
computed: {
|
2021-12-21 13:58:48 +01:00
|
|
|
description()
|
2021-12-09 10:51:10 +01:00
|
|
|
{
|
2021-12-21 13:58:48 +01:00
|
|
|
return localize(this.field.description, { hideEmpty: true });
|
2021-12-09 10:51:10 +01:00
|
|
|
},
|
|
|
|
|
isDisabled()
|
|
|
|
|
{
|
2021-12-21 13:58:48 +01:00
|
|
|
return this.manualDisabled || this.disabled || this.field.readonly(this.model);
|
2021-12-22 10:55:40 +01:00
|
|
|
},
|
|
|
|
|
isLocked()
|
|
|
|
|
{
|
|
|
|
|
return false; //this.editor.blueprint && !this.editor.blueprint.unlocked(this.value, this.field);
|
|
|
|
|
},
|
|
|
|
|
canUnlock()
|
|
|
|
|
{
|
|
|
|
|
return false; // this.editor.blueprint && this.editor.blueprint.canUnlock(this.value, this.field);
|
2021-12-09 10:51:10 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
rebuildModel()
|
|
|
|
|
{
|
2021-12-21 14:41:50 +01:00
|
|
|
this.config = {
|
|
|
|
|
model: this.value,
|
|
|
|
|
field: this.field,
|
|
|
|
|
meta: this.meta,
|
|
|
|
|
disabled: this.isDisabled,
|
|
|
|
|
system: this.system
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-21 13:58:48 +01:00
|
|
|
this.selector = selectorToArray(this.field.path);
|
2021-12-14 14:21:48 +01:00
|
|
|
let currentValue = this.value;
|
2021-12-09 10:51:10 +01:00
|
|
|
let found = false;
|
|
|
|
|
|
|
|
|
|
if (!this.selector || !this.selector.length || !currentValue)
|
|
|
|
|
{
|
|
|
|
|
found = true;
|
|
|
|
|
this.model = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (var key of this.selector)
|
|
|
|
|
{
|
2021-12-19 01:16:02 +01:00
|
|
|
if (currentValue && key in currentValue)
|
2021-12-09 10:51:10 +01:00
|
|
|
{
|
|
|
|
|
found = true;
|
|
|
|
|
currentValue = currentValue[key];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.model = found ? currentValue : null;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onChange(value)
|
|
|
|
|
{
|
|
|
|
|
let oldValue = JSON.parse(JSON.stringify(this.model));
|
|
|
|
|
|
|
|
|
|
if (typeof value === 'function')
|
|
|
|
|
{
|
2021-12-14 14:21:48 +01:00
|
|
|
value(this.value);
|
2021-12-09 10:51:10 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-14 14:21:48 +01:00
|
|
|
setObjectValue(this.value, this.selector, value);
|
2021-12-09 10:51:10 +01:00
|
|
|
}
|
2021-12-21 13:58:48 +01:00
|
|
|
|
2021-12-14 14:21:48 +01:00
|
|
|
this.$emit('input', this.value);
|
2021-12-09 10:51:10 +01:00
|
|
|
|
2022-01-10 16:13:59 +01:00
|
|
|
this.field.onChange({
|
|
|
|
|
value: value,
|
|
|
|
|
model: this.value,
|
|
|
|
|
oldValue,
|
|
|
|
|
component: this
|
|
|
|
|
})
|
2021-12-09 10:51:10 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setDisabled(disabled)
|
|
|
|
|
{
|
|
|
|
|
this.manualDisabled = disabled;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async unlock()
|
|
|
|
|
{
|
|
|
|
|
//Overlay.confirm({
|
|
|
|
|
// title: 'Unlock property',
|
|
|
|
|
// text: 'Unlock this property to override the value passed by the blueprint',
|
|
|
|
|
// confirmLabel: 'Confirm',
|
|
|
|
|
// closeLabel: 'Cancel'
|
|
|
|
|
//}).then(
|
2021-12-21 13:58:48 +01:00
|
|
|
// async () => await this.editor.blueprint.unlock(this.value, this.field),
|
2021-12-09 10:51:10 +01:00
|
|
|
// () => {}
|
|
|
|
|
//);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async lock()
|
|
|
|
|
{
|
2021-12-21 13:58:48 +01:00
|
|
|
//let originalValue = await this.editor.blueprint.lock(this.value, this.field);
|
|
|
|
|
//this.onChange(originalValue);
|
2021-12-09 10:51:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-21 13:58:48 +01:00
|
|
|
})
|
2021-12-09 10:51:10 +01:00
|
|
|
</script>
|