Skip to Content
Menu
This question has been flagged
3086 Views

Hello

i am working on a costume widget that will allow me to display a Google maps snippet withing my forms.

when i try to call the widget it doesn't show anything except the value of the field i used

_googlemaps.js

openerp.ressource = function (openerp) {
    openerp.web.form.widgets.add('googlemaps', 'openerp.ressource.googlemaps');
    openerp.ressource.googlemaps = openerp.web.form.FieldChar.extend(
        {
            template: "googlemaps",
            init: function (view, code) {
                this._super(view, code);
                console.log('Loading ...');
//Google Map and marker
                function initMap() {
                    var myLatLng = {lat: -25.363, lng: 131.044};
                    // Create a map object and specify the DOM element for display.
                    var map = new google.maps.Map(document.getElementById('map'), {
                        zoom: 8,
                        center: myLatLng
                    });
                    // Create a marker and set its position.
                    var marker = new google.maps.Marker({
                        map: map,
                        position: myLatLng,
                        title: 'Hello World!'
                    });
                }
                function loadScript() {
                    var script = document.createElement("script");
                    script.type = "text/javascript";
                    script.src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyDb5EetAkCD_W80-mhlYunEr8R81z3cBqI&callback=initMap";
                    document.body.appendChild(script);
                }
                window.onload = loadScript;
        }
    });
}

resource.xml

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="googlemaps">
    <xpath expr="." position="inside">
        <html>
            <body>
                <div id="map" style="width:600px;height:400px;"></div>
            </body>
        </html>
    </xpath>
</t>
</templates>

and of course the __openerp__.py file

# -*- coding: utf-8 -*-
{
    'name': "googlemapswidget",
    'summary': """
        Short (1 phrase/line) summary of the module's purpose, used as
        subtitle on modules listing or apps.openerp.com""",
    'description': """
        Long description of module's purpose
    """,
    'author': "Your Company",
    'website': "http://www.yourcompany.com",
    # Categories can be used to filter modules in modules listing
    # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
    # for the full list
    'category': 'Uncategorized',
    'version': '0.1',
    # any module necessary for this one to work correctly
    'depends': ['base'],
    # always loaded
    'data': [
        # 'security/ir.model.access.csv',
        'templates.xml',
    ],
    # only loaded in demonstration mode
    'demo': [
        'demo.xml',
    ],
    'qweb' : ['static/xml/resource.xml',],
    'js': ['static/js/_googlemaps.js',],
    'css': ['static/js/style.css',],
}

what am i doing wrong here ?

any suggestions will be appreciated.

good day

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 24
407
1
Jul 23
3223
0
Mar 24
1986
1
Sep 22
4953
1
Mar 22
3830