Files
gzth/funenc_json_widget/static/src/json_widget.js
T
2024-10-20 10:36:26 +08:00

58 lines
1.4 KiB
JavaScript

/** @odoo-module **/
import { registry } from "@web/core/registry";
import { _t } from "@web/core/l10n/translation";
import { standardFieldProps } from "@web/views/fields/standard_field_props";
import { Component, xml } from "@odoo/owl";
export class JsonTemplateWidget extends Component {
static template = xml`
<div>
<t t-call="{{get_template_id()}}" />
</div>`
static props = {
...standardFieldProps,
};
setup() {
console.log(this)
}
get isReadonly() {
return true;
}
get_template_id() {
if (!this.template_id) {
try {
debugger
let name = this.props.name;
let data = this.props.record.data;
let value = data[name] || "{}"
this.value = JSON.parse(value);
if (!this.value || !this.value.template) {
this.template_id = xml`<t t-esc="value" />`;
} else {
this.template_id = this.value.template;
}
} catch (e) {
this.template_id = xml`${e.message}`;
}
}
return this.template_id;
}
}
export const JsonTemplateField = {
component: JsonTemplateWidget,
displayName: _t("Json Template"),
supportedTypes: ["char", "text"],
isEmpty: () => false
};
registry.category("fields").add("json_template", JsonTemplateField);