Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get xml model value from widget javascript?

By
Anna
on 9/21/14, 1:37 AM 2,247 views

Hey, i am creating a widget that'll show a google maps, but i need to get elements of the one2many field where i am using it, i am not sure how to do that. Here's how i call the widget:

<field name="destins" string="Destinos" widget="test" colspan="4" nolabel="1"  context="{'group_by':'fleet'}">
                                <tree>
                                    <field name="coord"/>
                                    <field name="fleet"/>
                                    <field name="order"/>
                                </tree>
                            </field>

And this is the widget template:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="test">
    <html>
      <head>
        <style>
          #map_canvas{
              width:500px;
              height:500px;
          }
        </style>
      </head>
        <body>
            <script>(function(d, s, id) {
              var map;

             
              function initialize(){
                var chicago = new google.maps.LatLng(-40.321, 175.54);
                  var myOptions = {
                      zoom: 6,
                      mapTypeId: google.maps.MapTypeId.ROADMAP,
                      center: chicago
                  }
                  map = new google.maps.Map(d.getElementById("map_canvas"), myOptions);
                  //calcRoute();
              }

              function prepGoogleMaps(){
                if(typeof google != 'undefined'){
                  initialize();
                }else{
                  setTimeout(prepGoogleMaps,1000);
                }
              }

              function loadGoogleMaps(){
                var script_tag = document.createElement('script');
                script_tag.setAttribute("type","text/javascript");
                script_tag.setAttribute("src","http://maps.google.com/maps/api/js?sensor=false&amp;callback=initialize");
                (d.getElementsByTagName("head")[0] || d.documentElement).appendChild(script_tag);
                prepGoogleMaps();
            }
            window.onload = loadGoogleMaps();
              
            }(document, 'script', 'map-root'));</script>
            <div id="map_canvas"></div>
        </body>
    </html>    
</t>
</templates>

Showsa google maps, but i need to use coord field of one2many, can anybody help me do this?

 

0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 9/21/14, 7:54 AM

Have you ever read web framework training [1]? I think that is a good reference to hacking odoo frontend. I see your problem can be solved via context helper or directly querying odoo model. Beside that, I wonder why you choose to make new html page for the widget?

 

[1] https://doc.odoo.com/trunk/training/web_framework/

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/21/14, 1:37 AM
Seen: 2247 times
Last updated: 3/16/15, 8:10 AM