Skip to content

Commit

Permalink
[FIX] web_widget_mpld3_chart: owl in java
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardCForgeFlow committed Oct 25, 2023
1 parent 6426fe1 commit 1a72412
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 24 deletions.
1 change: 1 addition & 0 deletions web_widget_mpld3_chart/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"assets": {
"web.assets_backend": [
"web_widget_mpld3_chart/static/src/js/web_widget_mpld3_chart.esm.js",
"web_widget_mpld3_chart/static/src/lib/xml/mpld3.xml",
],
},
}
93 changes: 69 additions & 24 deletions web_widget_mpld3_chart/static/src/js/web_widget_mpld3_chart.esm.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,76 @@
/** @odoo-module **/

import basicFields from "web.basic_fields";
import fieldRegistry from "web.field_registry";

const Mpld3ChartWidget = basicFields.FieldChar.extend({
jsLibs: [
"/web_widget_mpld3_chart/static/src/lib/d3/d3.v5.js",
"/web_widget_mpld3_chart/static/src/lib/mpld3/mpld3.v0.5.9.js",
],
_renderReadonly: function () {
import {CharField} from "@web/views/fields/char/char_field";
import {loadBundle} from "@web/core/assets";
import {registry} from "@web/core/registry";
const {onWillStart, markup} = owl;
class Mpld3ChartWidget extends CharField {
setup() {
super.setup();
try {
const val = JSON.parse(this.value);
const new_div = document.createElement("div");
new_div.setAttribute("id", val.div);
this.$el.html(new_div);
this.$el.ready(function () {
const script = document.createElement("script");
script.setAttribute("type", "text/javascript");
if ("textContent" in script) script.textContent = val.script;
else script.text = val.script;
$("head").append(script);
});
this.value = JSON.parse(this.props.value);
this.value.div = markup(this.value.div.trim());
} catch (error) {
return this._super(...arguments);
this.value = {div: "", script: ""};
}
},
});

fieldRegistry.add("mpld3_chart", Mpld3ChartWidget);
onWillStart(() =>
loadBundle({
jsLibs: [
"/web_widget_mpld3_chart/static/src/lib/d3/d3.v5.js",
"/web_widget_mpld3_chart/static/src/lib/mpld3/mpld3.v0.5.9.js",
],
})
);
}
}
Mpld3ChartWidget.template = "web_widget_mpld3_chart.Mpld3ChartField";
registry.category("fields").add("mpld3_chart", Mpld3ChartWidget);

export default Mpld3ChartWidget;














///** @odoo-module **/
//
//import basicFields from "web.basic_fields";
//import fieldRegistry from "web.field_registry";
//
//const Mpld3ChartWidget = basicFields.FieldChar.extend({
// jsLibs: [
// "/web_widget_mpld3_chart/static/src/lib/d3/d3.v5.js",
// "/web_widget_mpld3_chart/static/src/lib/mpld3/mpld3.v0.5.9.js",
// ],
// _renderReadonly: function () {
// try {
// const val = JSON.parse(this.value);
// const new_div = document.createElement("div");
// new_div.setAttribute("id", val.div);
// this.$el.html(new_div);
// this.$el.ready(function () {
// const script = document.createElement("script");
// script.setAttribute("type", "text/javascript");
// if ("textContent" in script) script.textContent = val.script;
// else script.text = val.script;
// $("head").append(script);
// });
// } catch (error) {
// return this._super(...arguments);
// }
// },
//});
//
//
//fieldRegistry.add("mpld3_chart", Mpld3ChartWidget);
//export default Mpld3ChartWidget;
7 changes: 7 additions & 0 deletions web_widget_mpld3_chart/static/src/lib/xml/mpld3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="web_widget_mpld3_chart.Mpld3ChartField" owl="1">
<t t-out="this.value.div" />
<script type="text/javascript" t-out="this.value.script" />
</t>
</templates>

0 comments on commit 1a72412

Please sign in to comment.