VMware {code} Community
HaroldLin
Contributor
Contributor

vSphere web client HTML Bridge: Global refresh button does not invoke the function assigned to WEB_PLATFORM.onGlobalRefreshRequest


I am unable to get the global refresh handler in my HTML Bridge plugin to be invoked when clicking on the vSphere web client global refresh button.


On my setup, I verified the JS files are loaded, WEB_PLATFORM is an actual object with the HTML Bridge APIs, and the jQuery document.ready function is being invoked with the resulting initial refreshData() call. However, clicking on the vSphere web client global refresh button does not invoke the refreshData() function in my HTML Bridge plugin that is loaded in the HTML Bridge IFrame window on top of the Flex vSphere client.


This is a snippet showing the relevant code modified from the chassisA HTML Bridge sample app:


...
<script src="/vsphere-client/chassis-test/assets/jquery-1.10.2.min.js"></script>
<script src="/vsphere-client/chassis-test/resources/js/web-platform.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function refreshData() {
console.log("refreshData() called");
}
// Do the actual call now and save as GlobalRefresh handler
refreshData();
WEB_PLATFORM.onGlobalRefreshRequest = refreshData;
});
</script>
....




Questions:


1) Does this require vSphere web client version 5.5.1 or later? Although the web SDK docs specify the minimum client version is 5.5.1, I am currently running on vSphere client version 5.5.0 and making calls using the WEB_PLATFORM.getObjectId() and other APIs without any problems. This is the only web platform API that I am aware of that is not functioning as expected in my environment. Is this problem actually due to something missing in client version 5.5.0?


2) Does the WEB_PLATFORM.onGlobalRefreshRequest API require any Java services to be present in my plugin, or should the snippet above work as-is with just the client code above? I assume internally an ExternalInterface call is being made from the vSphere client Flex code when the user clicks on the web client global refresh button, and thus its functionality should only depend on WEB_PLATFORM.onGlobalRefreshRequest being assigned a valid JavaScript function.


Thanks.

5 Replies
laurentsd
VMware Employee
VMware Employee

> 1) Does this require vSphere web client version 5.5.1 or later?

Nothing would work in your HTML plugin if you were not using Web Client version >= 5.5.1 🙂   so you must be looking at the wrong place for your version number.  See the About vSphere Client box in the Help menu.  (the only exception I can think of is if you were still using the HTML bridge beta version in conjunction with 5.5.0, which I hope you are not!)

> 2) Does the WEB_PLATFORM.onGlobalRefreshRequest API require any Java services to be present in my plugin.

No, this is pure UI logic. If this works for the chassis-ui sample but not for your plugin then there must be something else affecting your code. I would need to see a working example to help you out.  Also note that this refresh mechanism only works for the currently opened HTML view.  Your javascript function cannot be called if the view is not active.

0 Kudos
nklein1
Contributor
Contributor


I'm also experiencing issues getting +WEB_PLATFORM.onGlobalRefreshRequest +to trigger. At first I thought it might be an issue with how I was referencing web-platform.js in my own project, but I was able to successfully test redirection using WEB_PLATFORM.sendNavigationRequest in the same function.

I also tried to test +WEB_PLATFORM.onGlobalRefreshRequest +in the "ChassisB" sample html-bridge project and it didn't appear to work there either. I added the following console.log() statements to chassis-summary.js, and while they are all printed when the view is initially loaded, when I click the global refresh button nothing is printed in the developer tools console.


function refreshData() {
+ console.log('refreshData() triggered.');
$.getJSON(dataUrl, function(data) {
var items = [];
$.each(data, function(key, val) {
...
}
// Do the actual call now and save as GlobalRefresh handler
refreshData();
+ console.log(WEB_PLATFORM);
+ console.log(WEB_PLATFORM.onGlobalRefreshRequest);
WEB_PLATFORM.onGlobalRefreshRequest = refreshData;


0 Kudos
laurentsd
VMware Employee
VMware Employee

Thanks for pursuing this issue.  There is indeed a problem with the current implementation and I was wrong saying that the refreshData function gets called correctly in the chassis sample!

Luckily there is an easy fix 🙂   In web-platform.js add the line in blue below, this will declare WEB_PLATFORM in the top window.

      if (!WEB_PLATFORM) {

         WEB_PLATFORM = self.top.document.getElementById("container_app");

         self.top.WEB_PLATFORM = WEB_PLATFORM;

    ...

nklein1
Contributor
Contributor

That fixed it, thanks!

0 Kudos
laurentsd
VMware Employee
VMware Employee

FYI, we discovered that the fix I suggested is not entirely correct.  It should be moved at the top of web-platform.js under line 11, like this:

var WEB_PLATFORM = self.parent.WEB_PLATFORM;

if (!WEB_PLATFORM) {

    WEB_PLATFORM = self.parent.document.getElementById("container_app");

  self.parent.WEB_PLATFORM = WEB_PLATFORM;

}

and the definition of WEB_PLATFORM APIs starting at line 62 are no longer inside the if(!WEB_PLATFORM) statement

// Get the current context object id or return null if none is defined

WEB_PLATFORM.getObjectId = function() {

   return getURLParameter("objectId");

};

etc.

0 Kudos