summaryrefslogtreecommitdiff
path: root/addons/event/static/src/js/google_map.js
diff options
context:
space:
mode:
authorAtul Patel (OpenERP) <atp@tinyerp.com>2012-05-21 18:54:58 +0530
committerAtul Patel (OpenERP) <atp@tinyerp.com>2012-05-21 18:54:58 +0530
commit4a02e98d42678b9becec3bacf4d65906596bfdf7 (patch)
treebc45461229b9aa7353fac620c6364f24d3923d42 /addons/event/static/src/js/google_map.js
parent96fde61acf012673b4f0a197b7a9b62d10ee9b5e (diff)
[FIX]: Add osv memory wizard for event preview.Refactor code as per new specification.
bzr revid: atp@tinyerp.com-20120521132458-xozrh3vcz4wbo6t5
Diffstat (limited to 'addons/event/static/src/js/google_map.js')
-rw-r--r--addons/event/static/src/js/google_map.js87
1 files changed, 43 insertions, 44 deletions
diff --git a/addons/event/static/src/js/google_map.js b/addons/event/static/src/js/google_map.js
index 2209001f29d..7d2681a7369 100644
--- a/addons/event/static/src/js/google_map.js
+++ b/addons/event/static/src/js/google_map.js
@@ -1,11 +1,24 @@
openerp.event = function(instance){
- instance.web.form.widgets.add('geo_address', 'instance.event.GeoAddress');
- instance.event.GoogleMapConnecter = instance.web.Class.extend({
- init : function(){
-// call ajex to render map load
-
- },
- render_map: function(address){
+ instance.web.form.widgets.add('many2one_Geo_address', 'instance.event.Many2OneAddress');
+
+ instance.web.GoogleMapConnector = instance.web.Class.extend({
+ init: function(){
+ this.googleMapsLoaded = $.Deferred();
+ this.map_load();
+ },
+ map_load: function() {
+ var self = this;
+ if(this.googleMapsLoaded.state() != "pending"){return this.googleMapsLoaded.promise();}
+ googleMapsCallback = function () {
+ self.googleMapsLoaded.resolve();
+ };
+ $.ajax({
+ url: "https://maps.googleapis.com/maps/api/js?v=3&callback=googleMapsCallback&sensor=false",
+ dataType: "script"
+ }).fail(self.googleMapsLoaded.reject);
+ return this.googleMapsLoaded.promise();
+ },
+ render_map: function(address,$element){
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status){
if (status == google.maps.GeocoderStatus.OK){
@@ -16,54 +29,40 @@ openerp.event = function(instance){
mapTypeId: google.maps.MapTypeId.ROADMAP
}
return new google.maps.Marker({
- map : new google.maps.Map(document.getElementById("oe_mapbox"),myOptions),
+ map : new google.maps.Map($element,myOptions),
position: new google.maps.LatLng(lat,lng)
});
}
});
- map_load: function() {
- var self = this;
- if(this.googleMapsLoaded.state() != "pending"){return this.googleMapsLoaded.promise();}
- googleMapsCallback = function () {
- self.googleMapsLoaded.resolve();
- };
- $.ajax({
- url: "https://maps.googleapis.com/maps/api/js?v=3&callback=googleMapsCallback&sensor=false",
- dataType: "script"
- }).fail(self.googleMapsLoaded.reject);
- return this.googleMapsLoaded.promise();
- },
-
- }),
-
- instance.event.GeoAddress = instance.web.form.Many2OneField.extend(_.extend({}, {
- init : function(){
- this._super();
- this.googleMapsLoaded = $.Deferred();
},
-
-
- set_value:function(value){
- var self = this;
- this.get_address(value).done(function(value){
- if(!self.__parentedParent.$element.find("#address_text").length)self.__parentedParent.$element.find(".oe_td_border").after(instance.web.qweb.render("address",{'record': value}));
- var address = _.str.sprintf(' %(street)s, %(city)s, %(country_id[1])s', value);
- var defer = self.map_load();
- defer.done(function(){
- return self.render_map(address);
- });
- });
+ });
+ instance.event.Many2OneAddress = instance.web.form.FieldMany2One.extend({
+ init: function(field_manager, node){
+ this._super(field_manager, node);
+ this.map = new instance.web.GoogleMapConnector();
},
get_address:function(value){
+ var self = this;
if (!value || value.length == 0){
return $.Deferred().reject();
}
- return new instance.web.DataSet (this,this.field.relation, this.build_context()).read_ids(value[0],["street","city","country_id"]);
+ (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","country_id"]).done(function(value){
+ var address = _.str.sprintf(' %(street)s, %(city)s, %(country_id[1])s', value);
+ self.map.googleMapsLoaded.done(function(){
+ self.map.render_map(address,document.getElementById("oe_mapbox"));
+ })
+ });
},
-
+ set_value:function(value){
+ this._super(value);
+ this.get_address(value);
},
- get_value:function(){
- }
- }));
+ render_value:function(no_recurse){
+ this.get_address(this.get("value"));
+ this._super(no_recurse);
+ }
+ });
}; \ No newline at end of file