add ReadOnlyField to display config readonly values

This commit is contained in:
axolotle 2022-03-02 19:42:01 +01:00
parent 97bd1564c4
commit 9d02438348
2 changed files with 68 additions and 1 deletions

View file

@ -0,0 +1,65 @@
<template>
<b-row no-gutters class="description-row">
<b-col v-bind="cols_" class="font-weight-bold">
{{ label }}
</b-col>
<!-- FIXME not sure about rendering html -->
<b-col v-html="text" />
</b-row>
</template>
<script>
export default {
name: 'ReadOnlyField',
inheritAttrs: false,
props: {
label: { type: String, required: true },
component: { type: String, default: 'InputItem' },
value: { type: null, default: null },
cols: { type: Object, default: () => ({ md: 4, lg: 3 }) }
},
computed: {
cols_ () {
return Object.assign({ md: 4, lg: 3 }, this.cols)
},
text () {
return this.parseValue(this.value)
}
},
methods: {
parseValue (value) {
const item = this.component
if (item === 'FileItem') value = value.file ? value.file.name : null
if (item === 'CheckboxItem') value = this.$i18n.t(value ? 'yes' : 'no')
if (item === 'TextAreaItem') value = value.replaceAll('\n', '<br>')
if (Array.isArray(value)) {
value = value.length ? value.join(this.$i18n.t('words.separator')) : null
}
if ([null, undefined, ''].includes(this.value)) value = this.$i18n.t('words.none')
return value
}
}
}
</script>
<style lang="scss" scoped>
.description-row {
@include media-breakpoint-up(md) {
margin: 1rem 0;
}
@include media-breakpoint-down(sm) {
flex-direction: column;
&:not(:last-of-type) {
margin-bottom: 0.5rem;
padding-bottom: 0.5rem;
border-bottom: $border-width solid $card-border-color;
}
}
}
</style>

View file

@ -544,7 +544,9 @@
"words": {
"browse": "Browse",
"collapse": "Collapse",
"default": "Default"
"default": "Default",
"none": "None",
"separator": ", "
},
"wrong_password": "Wrong password",
"yes": "Yes",