Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betobaz/719e42da1868e0f6d9e9 to your computer and use it in GitHub Desktop.
Save betobaz/719e42da1868e0f6d9e9 to your computer and use it in GitHub Desktop.
SugarCRM::Sidecar::Load Google Maps Api Async
({
plugins: ['Dashlet'],
initialize: function (options) {
var self = this;
this._super('initialize', [options]);
// Escuchador que se detona cuando se ha detectado que el api de
self.context.on('google:maps:api:load', _.bind(self._googleMapsApiLoadHandler, self));
// Se define la función callback que se va a ejecutar cuando google maps api ya esta disponible
window.mapsApiCallback = function(){
console.log('hola mundo, maps api cargado');
// Detona evento personalizado para que sea cachado por algun escuchador
self.context.trigger('google:maps:api:load');
}
// Se valida que google y google.maps no esten disponibles para cargar el script
if(_.isUndefined(window.google) || _.isUndefined(window.google.maps)){
this.loadStript();
}
else{
// Si esta disponible se dispara el evento personalizado
self.context.trigger('google:maps:api:load');
}
},
// funcion que se encarga de importar el script del api de google maps
loadStript: function() {
var script = document.createElement('script');
script.type = 'text/javascript';
// se indica la url mas el nombre de la funcion callback que se dispara cuando este listo
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' +
'&signed_in=true&callback=mapsApiCallback';
document.body.appendChild(script);
},
_googleMapsApiLoadHandler: function(){
console.log('cachandolo en el dashlet');
debugger;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment