[16.0][MIG] Migration to v16.0

This commit is contained in:
Roberto Fichera
2023-03-03 11:18:33 +01:00
parent 60428a2db1
commit ff575d4fd7
12 changed files with 89 additions and 122 deletions

View File

@@ -0,0 +1,42 @@
/** @odoo-module **/
import {loadJS} from "@web/core/assets";
import {registry} from "@web/core/registry";
import {Component, onPatched, onWillStart, useEffect, useRef} from "@odoo/owl";
export class PlotlyChartWidgetField extends Component {
setup() {
this.divRef = useRef("plotly");
onWillStart(async () => {
await loadJS(
"/web_widget_plotly_chart/static/src/lib/plotly/plotly-2.18.2.min.js"
);
this.updatePlotly(this.props.value);
});
onPatched(() => {
this.updatePlotly(this.props.value);
});
useEffect(() => {
this.updatePlotly(this.props.value);
});
}
updatePlotly(value) {
const value_html = $(value);
const div = value_html.find(".plotly-graph-div").get(0).outerHTML || "";
const script = value_html.find("script").get(0).textContent || "";
if (this.divRef.el) {
this.divRef.el.innerHTML = div;
new Function(script)();
}
}
}
PlotlyChartWidgetField.template = "web_widget_plotly_chart.PlotlyChartWidgetField";
PlotlyChartWidgetField.supportedTypes = ["char", "text"];
registry.category("fields").add("plotly_chart", PlotlyChartWidgetField);

View File

@@ -1,17 +0,0 @@
odoo.define("web_widget_plotly_chart", function (require) {
"use strict";
var fieldRegistry = require("web.field_registry");
var AbstractField = require("web.AbstractField");
var PlotlyChartWidget = AbstractField.extend({
_renderReadonly: function () {
var val = this.value;
this.$el.html(val);
},
});
fieldRegistry.add("plotly_chart", PlotlyChartWidget);
return {
PlotlyChartWidget: PlotlyChartWidget,
};
});

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="web_widget_plotly_chart.PlotlyChartWidgetField" owl="1">
<div t-ref="plotly" />
</t>
</templates>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long