Last active
September 22, 2016 18:05
-
-
Save cAstraea/4505a23260491335f238 to your computer and use it in GitHub Desktop.
google autocomplete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
/* because accounts already has a record view, we need to extend it */ | |
extendsFrom: 'AccountsRecordView', | |
/* if you are running 7.2.0, you will need to use RecordView */ | |
//extendsFrom: 'RecordView', | |
initialize: function (options) { | |
this._super('initialize', [options]); | |
//extend the record view definition, so we include actions and the module specific fields. | |
this.meta = _.extend({}, app.metadata.getView(this.module, 'record'), this.meta); | |
//add validation tasks | |
app.error.errorName2Keys['field_error'] = 'Invalid email'; | |
this.model.addValidationTask('check_email', _.bind(this._doValidateEmail, this)); | |
this.events['change input[name=phone_office]'] = 'doUpperLasts'; | |
window.gMapsCallback = function(){ | |
$(window).trigger('gMapsLoaded'); | |
}, | |
$(document).ready((function(){ | |
//gmap initialize | |
function initialize(){ | |
var mapOptions = { | |
center: new google.maps.LatLng(41.877461, -87.638085), | |
zoom: 18, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
scrollwheel: false, | |
disableDefaultUI: true, | |
streetViewControl: false, | |
panControl: false | |
}; | |
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); | |
var componentForm = { | |
street_number: 'short_name', | |
route: 'long_name', | |
locality: 'long_name', | |
administrative_area_level_1: 'short_name', | |
country: 'long_name', | |
postal_code: 'short_name' | |
}; | |
var input = /** @type {HTMLInputElement} */ | |
( | |
document.getElementById('autocomplete')); | |
var autocomplete = new google.maps.places.Autocomplete(input,{types: ["geocode", "establishment"]}); | |
google.maps.event.addListener(autocomplete, 'place_changed', function() { | |
fillInAddress(autocomplete,componentForm); | |
}); | |
} | |
function fillInAddress(ac,cf) { | |
$('#map_canvas').removeClass('hiddenMap'); | |
componentForm = cf; | |
var place = ac.getPlace(); | |
for (var component in componentForm) { | |
document.getElementById(component).value = ''; | |
document.getElementById(component).disabled = false; | |
} | |
// Get each component of the address from the place details | |
// and fill the corresponding field on the form. | |
for (var i = 0; i < place.address_components.length; i++) { | |
var addressType = place.address_components[i].types[0]; | |
if (componentForm[addressType]) { | |
var val = place.address_components[i][componentForm[addressType]]; | |
document.getElementById(addressType).value = val; | |
// testchangeCity(val); | |
// document.getElementsByName(billing_adress_city).value = "test"; | |
} | |
} | |
} | |
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?libraries=places&callback=gMapsCallback"); | |
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); | |
} | |
$(window).bind('gMapsLoaded', initialize); | |
loadGoogleMaps(); | |
})()); | |
}, | |
_renderHtml: function(ctx, options){ | |
this._super('_renderHtml', [ctx, options]); | |
//this.$el.find('.record .record-cell').css('border','1px solid red'); | |
var myAddition = app.template.get("geocomplete.mine"); | |
this.$el.prepend(myAddition()); | |
}, | |
doUpperLasts: function(){ | |
//Get current value of last_name | |
var sLast = this.model.get('phone_office'); | |
//Convert last_name value to upper if not empty | |
if (!_.isEmpty(sLast)) | |
{ | |
this.model.set('name', sLast.toUpperCase()); | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello , sorry missed this message.
This was from 2015 but I forgot what was trying to do :( , it it's the last version I think.
I think had the map on a different tab and the name field of the client supported autocomplete from google places and would fill in the billing address info based on that.