summaryrefslogtreecommitdiff
path: root/addons/google_map
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2012-06-01 13:36:25 +0200
committerThibault Delavallée <tde@openerp.com>2012-06-01 13:36:25 +0200
commitcd19f68eb9f145e9049949074e06196d540cf2c2 (patch)
tree6c050ac836af1e3226ce7b71726db7e40b32a126 /addons/google_map
parentc9ce120fcdda692dce255359654e9b393332197b (diff)
parentf9e6b60c9f48c48d7b0d2a9b67a3e2376e032fd2 (diff)
[MERGE] Merged with main addons.
bzr revid: tde@openerp.com-20120601113625-c9w0kmnw1dzvjswx
Diffstat (limited to 'addons/google_map')
-rw-r--r--addons/google_map/__openerp__.py1
-rw-r--r--addons/google_map/google_map_view.xml3
-rw-r--r--addons/google_map/static/src/js/google_map.js75
3 files changed, 77 insertions, 2 deletions
diff --git a/addons/google_map/__openerp__.py b/addons/google_map/__openerp__.py
index 8aa1b60ca88..a6e85c3cd66 100644
--- a/addons/google_map/__openerp__.py
+++ b/addons/google_map/__openerp__.py
@@ -38,6 +38,7 @@ Using this you can directly open Google Map from the URL widget.""",
'google_map_view.xml',
],
'demo_xml': [],
+ 'js': ['static/src/js/google_map.js'],
'installable': True,
'auto_install': False,
'certificate': '0029498930765',
diff --git a/addons/google_map/google_map_view.xml b/addons/google_map/google_map_view.xml
index 4cd7e4ad7c4..eda86a0662f 100644
--- a/addons/google_map/google_map_view.xml
+++ b/addons/google_map/google_map_view.xml
@@ -12,8 +12,7 @@
<label string="Street2 : " align="1.0"/>
<group colspan="1" col="2">
<field name="street2" nolabel="1"/>
- <button name="open_map"
- string="Map" type="object" icon="gtk-zoom-in"/>
+ <button name="open_map" string="Map" type="object" icon="gtk-zoom-in"/>
</group>
</field>
</field>
diff --git a/addons/google_map/static/src/js/google_map.js b/addons/google_map/static/src/js/google_map.js
new file mode 100644
index 00000000000..9aa693e53c6
--- /dev/null
+++ b/addons/google_map/static/src/js/google_map.js
@@ -0,0 +1,75 @@
+openerp.event = function(instance, mod) {
+ instance.web.form.widgets.add('many2one_address_google_map', 'instance.google_map.Many2OneAddress');
+
+ var googleMapsLoaded = null;
+
+ instance.google_map.GoogleMapConnector = instance.web.Class.extend({
+ map_load: function() {
+ var self = this;
+ if(googleMapsLoaded === null) {
+ googleMapsLoaded = $.Deferred();
+ // global
+ openerp_googleMapsCallback = googleMapsLoaded.resolve;
+ $.ajax({
+ url: "https://maps.googleapis.com/maps/api/js?v=3&callback=openerp_googleMapsCallback&sensor=false",
+ dataType: "script"
+ }).fail(googleMapsLoaded.reject);
+ }
+ return googleMapsLoaded;
+ },
+ render_map: function(address,element) {
+ this.map_load().then(function() {
+ var geocoder = new google.maps.Geocoder();
+ geocoder.geocode({'address': address}, function(results, status) {
+ if (status == google.maps.GeocoderStatus.OK) {
+ var lat = results[0].geometry.location.lat();
+ var lng = results[0].geometry.location.lng();
+ var myOptions = {
+ zoom: 17,
+ center: new google.maps.LatLng(lat,lng),
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ };
+ var map = new google.maps.Map(element,myOptions);
+ var position = new google.maps.LatLng(lat,lng);
+ var marker = new google.maps.Marker({ map: map, position: position });
+ return marker;
+ }
+ });
+ });
+ },
+ });
+
+ instance.google_map.Many2OneAddress = instance.web.form.FieldMany2One.extend({
+ init: function(field_manager, node){
+ this._super(field_manager, node);
+ this.map = new instance.google_map.GoogleMapConnector();
+ },
+ get_address:function(value){
+ var self = this;
+ if (!value || value.length == 0){
+ return $.Deferred().reject();
+ }
+ (value instanceof Array)?value = parseInt(value[0]):false;
+ var data = new instance.web.DataSet(this,this.field.relation, this.build_context());
+ data.read_ids(value,["street","city","zip","country_id"]).done(function(value){
+ var address;
+ if (value['country_id']) {
+ address = _.str.sprintf('%(street)s, %(zip)s %(city)s, %(country_id[1])s', value);
+ } else {
+ address = _.str.sprintf('%(street)s, %(zip)s %(city)s', value);
+ }
+ // TODO repalce by widget_option selector self.options.selector
+ var el = self.view.$element.find(".oe_form_google_map")[0];
+ self.map.render_map(address,el);
+ });
+ },
+ set_value:function(value){
+ this._super(value);
+ this.get_address(value);
+ },
+ render_value:function(no_recurse){
+ this.get_address(this.get("value"));
+ this._super(no_recurse);
+ }
+ });
+};