-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] web_widget_mpld3_chart: owl in java
- Loading branch information
1 parent
6426fe1
commit 1a72412
Showing
3 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 69 additions & 24 deletions
93
web_widget_mpld3_chart/static/src/js/web_widget_mpld3_chart.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |