Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • a290c4b1a2e035f3ccacee25e20029948ab418aa
  • 16.0 par défaut protégée
  • 14.0
  • 18.0
4 résultats

jsonviewer_widget.esm.js

Blame
  • jsonviewer_widget.esm.js 1,19 Kio
    /** @odoo-module **/
    
    import {registry} from "@web/core/registry";
    import {loadJS} from "@web/core/assets";
    import {Component, onWillStart, useEffect, useRef} from "@odoo/owl";
    import { standardFieldProps } from '@web/views/fields/standard_field_props';
    
    class JsonWidget extends Component {
        static template = "api_connector.JsonWidgetField";
        static props = { ...standardFieldProps };
        setup() {
            this.json_tree = null;
            this.divRef = useRef("json_response");
    
            onWillStart(() =>
                loadJS("/api_connector/static/src/lib/jsonview/jsonview.min.js")
            );
    
            useEffect(() => {
                this.updateJson();
                return () => {
                    if (this.json_tree) {
                        this.json_tree.destroy();
                    }
                };
            });
        }
        updateJson() {
            if (this.json_tree) {
                this.json_tree.destroy();
            }
            const tree = jsonview.create(this.props.record.data[this.props.name]);
            this.json_tree = jsonview.render(tree, this.divRef.el);
            jsonview.expand(tree);
        }
    }
    
    export const jsonWidget = {
        component: JsonWidget,
    };
    
    registry.category("fields").add("json_viewer", jsonWidget);