Google Map API integration with Oracle Commerce Cloud - google-maps

I am trying to integrate Google Map API in the Oracle Commerce Cloud template file for a particular functionality. When I tried to use the below tag in my template file,
<script async defer src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&callback=initMap"></script>
I got an error message "Named entity expected. Got none." for the & symbol in the src.
I tried using & and %26 instead of &, there was no error, but I could not see the script tag in rendered HTML (Used Inspect option in the browser) and the map is also not rendering.
Is there a way to use google map api in occ template file?

Try making this call in your javascript. And then with Knockout you'll be able to manipulate where you want to display the map.
If you have multiple pages you can use global, otherwise you can use only the javascript of the widget you want.

Related

How to use AngularJS ng-include?

I want to use AngularJS to separate my jquery mobile HTML. But it seems ng-include can't include external HTML as the parent content, parent CSS and js are not applied to it. Below is an example. Would you like to let me know how to fix it?
Below is the example.
http://plnkr.co/edit/I91t9mjGJ58ZS4H2bymL?p=preview
It's obvious you cannot directly access external file from other site due to CORS policy.
If you do want to get the template from other site with different domain name, make sure that domain provides the API for you to $http.get the html template string, and then you can inject it into your Angular controller, where your view may access from.
The basic process may be as follow:
Check the API for the third party domain, where you can get the template string.
Use $http.get (or $resource, depends on your choice) to get the template.
Wrap the $http service and your parsing login into a new Angular service. (e.g. angular.module('yourApp', []).factory();
Inject this service into the Angular controller which you bind in your directives.
In your view file, use ng-include in that controller to access the template.

google site: pass parameters to embedded script

I am trying to pass parameters to an app script embedded in page on google sites. This page was created using a custom template that has the original script. Everything works on the template but on the page itself, i get an 'undefined' when I try to use the values.
I am using the usual e.parameter.name code in the doGet(e) to get the value for the parameter 'name'. I do not understand why it works for the template but not for the page with the same template.
You cant pass parameters to the script from the embedded script url. Gas only picks up parameters from sites if those are in the site url itself.
As a workarround you can embed the gas url (with params) using the iframe gadget instead of inserting the script the normal way.
Try using parameters:
function doGet(e) {
Logger.log(e.parameters.name[0]);
}
Make sure you use the right link as well. Especially in an iframe in Google Sites. This one works for me, which changes macro.google.com to sites.google.com and makes other changes as well:
https://sites.google.com/macros/s/~~script ID~~/exec?param1=~~passed value~~&param2~~passed~~

google closure library usage from google app scripts using HtmlService

Is it possible to access google closure library functions from google app scripts via HtmlService? The html files in the google scripts seems to be filtering out anything related to closure library.
project: I am exploring DOM manipulation utilities from Google Closure library from within the google app scripts using HtmlService. I intend to run this as a stand alone web app.
The closure functions work when directly loaded into the browser from its local client environment - but they dont work when injected from GAS app via the HtmlService utility.
Here is the code I am using in the GAS.
html file
<html>
<head>
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
<script>
goog.require('goog.dom');
function c_sayHi() {
var newHeader = goog.dom.createDom('h1', {'style': 'background-color:#EEE'},'Hello world!');
goog.dom.appendChild(document.body, newHeader);
}
</script>
</head>
<script>
function c_updateButton(date, button) {
button.value = "clicked at " + date;
}
</script>
<body onload="c_sayHi()">
<input type='button' value='Never Clicked'
onclick='google.script.run.withSuccessHandler(c_updateButton).withUserObject(this).s_getCurrentDate()'>
<input type='button' value='Never Clicked'
onclick='google.script.run.withSuccessHandler(c_updateButton).withUserObject(this).s_getCurrentDate()'>
</body>
</html>
Google Script file
function s_getCurrentDate() {
return new Date().toString();
}
function doGet(e) {
return HtmlService.createTemplateFromFile('hello').evaluate();
}
I have prefixed c_ to client side functions and s_ for server side fns. When running this as a web app,
Function c_sayHi has no effect - I am not sure if it is even invoked.
Functions s_getCurrentDate and c_updateButton work fine as described in google's documentation https://developers.google.com/apps-script/html_service.
Is there a way to get closure library working from the web apps as attempted above?
Couple of things here -
All .gs files is JavaScript that runs on the server side. So the DOM is not really relevant there.
You can run client side JavaScript by returning code in HtmlService. This is what I believe you want to do. However, jQuery is the best supported library on this approach. Closure might end up working but the team does not specifically test against that library.
The problem is that Closure's dependency structure is executing before the window load event, otherwise it will not work. So any require and provide statements are taken care of way before window load. When you inject them through the HTML Service, you are forcing their execution at a different stage then required, which causes everything to fail.
If you would be using a COMPILED Closure Library source, you will not have any problems with running Closure. Learn how to use the Compiler and Builder to make Closure Work properly. Also, you can use lazy loading to simulate your HTML Service.
With that, you can make javascript load dynamically onclick, onload or whatever the hell you want. This is called lazy-loading and it is used as a standard practice for all large web applications. Monitor the Network tab of Firebug when browsing through Gmail or Facebook.
Arun Nagarajan is right, jQuery is the easier solution but if you are doing something proper that requires breadth, scale and speed, jQuery is a toy for kids.

Html from Silverlight (not out of browser)

I am trying to open HTML file from the local URI which I use as XML Editor, to edit xml data that come from Silverlight application, then close browser window and return back edited xml data to the Silverlight application.
I tried to use HtmlPage.Window.Navigate but I don't quit like it.
I have tried using a method from: http://weblogs.asp.net/dwahlin/archive/2010/05/10/integrating-html-into-silverlight-applications.aspx
but instanly got an exception "failed to invoke ShowJobPlanIFrame"
Is there any way to handle this task?
"Out of browser" mode doesn't fit.
Thanks.
===========================================================================
Update:
It worked out using IFrame overlay.
Button click invokes the following code in C#:
var scriptObject = (ScriptObject)HtmlPage.Window.GetProperty("ShowJobPlanIFrame");
scriptObject.InvokeSelf(url);
Where "ShowJobPlanIFrame" is as defined at:
http://weblogs.asp.net/dwahlin/archive/2010/05/10/integrating-html-into-silverlight-applications.aspx
This allowed me to pass data into XML editor and then get it back.
An error with JavaScript function invocation I told above, was my fault in JavaScript code itself.
A very similar scenario: https://stackoverflow.com/a/7919065/384316
Try using an iframe overlay, then you can load any HTML-like content.
There is an excellent explanation of how to do this here:
http://www.wintellect.com/cs/blogs/jlikness/archive/2010/09/19/hosting-html-in-silverlight-not-out-of-browser.aspx
It worked out using IFrame overlay.
Button click invokes the following code in C#:
var scriptObject = (ScriptObject)HtmlPage.Window.GetProperty("ShowJobPlanIFrame");
scriptObject.InvokeSelf(url);
Where "ShowJobPlanIFrame" is as defined at:
http://weblogs.asp.net/dwahlin/archive/2010/05/10/integrating-html-into-silverlight-applications.aspx
This allowed me to pass data into XML editor and then get it back.
An error with JavaScript function invocation I told above, was my fault in JavaScript code itself.
Did you try NavigationFramework of Silverlight? It's capability may support your needs in a more simple way than using multiple browser pages.

Showing Google Maps in OpenERP

I wanted to include Google maps in a module of OpenERP. As far as I know until I use iframe tag of HTML I wont be able to show Google maps in OpenERP but in OpenERP I have only two kinds of file one is .xml and other is .py. Now how am I supposed to add iframe with only these two file in hand. Any ideas ?
Thank you
There is module called google_map in openerp addons. Install that module to get the google map inside openerp and if needed make the necessary changes by creating your own custom module
In the 2012 OpenERP Days one of the presentations demonstrated how to craete a custom Webclient widget. The example used was a geo widget that could display and address as a Google Map indide a froam view. The code is available here.
You can try out Camptocamp's geoengine addon. This addon is meant to display data from the OpenERP database in a custom view using a map. It does not use an iframe to embed a googlemap, afaik.
https://launchpad.net/geospatial-addons
This is an example for openning the map in a new link where the html file which contains the html and java script code for the google map located in
static/src/googlemaps/get_place_from_coords.html
and the following method will be called when clicking the open google map button in the openerp interface:
def button_open_google(self, cr, uid, ids, context=None):
for place in self.browse(cr, uid, ids):
url="/tms/static/src/googlemaps/get_place_from_coords.html?" + str(place.latitude) + ','+ str(place.longitude)
return { 'type': 'ir.actions.act_url', 'url': url, 'nodestroy': True, 'target': 'new' }