Linking an import gadget
Import gadgets can link to Actuate gadgets to receive user data selections.
The import gadget must link to another gadget on the dashboard before the channel name can be used in the Google gadget. For more information about linking gadgets, see
About linking gadgets together.
The Google gadget displayed in the import gadget can then process the user selections when the following conditions are met:
An import gadget displays the Google gadget XML file on the dashboard.
The Google gadget XML file requests the publish subscribe framework API using the following code:
<Require feature="pubsub" />
The gadgets.pubsub.subscribe(channelName, callback) method is used in the Google gadget to receive the linked message and send it to a callback function, as shown in the following code:
gadgets.pubsub.subscribe("ON_SELECTOR_GADGET_CHANGED", callbackFunction);
A callback function exists in the Google gadget XML file that processes the received message. For example, a callback function can parse the incoming message and create a value, such as a customer’s address. The callback function then sends the value to an external web service such as Google maps, and updates the gadget with the response from the external web service.
Listing 8‑2 shows an example Google gadget that displays changes from linked data selection gadgets. After saving the Google gadget code as an XML file and placing it on a web server, load the file into an import gadget. Use the link options from the import gadget menu to link the new import gadget to a data selection gadget on the dashboard. Each time the linked data selection gadget is changed, the selected value displays in the Google gadget.
Listing 8‑2 Example Google gadget with linking enabled
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="linking example" height="500">
<Require feature="pubsub" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<script type="text/javascript">
function onEventChange(sender, message) {
document.getElementById('changeme').innerHTML=message;
}
gadgets.pubsub.subscribe("ON_SELECTOR_GADGET_CHANGED", onEventChange);
</script>
<div id="changeme">DEFAULT TEXT</div> <br />
<div>The above text changes according to the current selection of the gadgets it is linked to.</div>
]]>
</Content>
</Module>
For more information about Google gadgets, see the Google gadget specification at the following URL:
http://code.google.com/apis/gadgets/