Building custom gadgets : Linking Google gadgets : Using a linked import gadget

Using a linked import gadget

Import gadgets can link to Actuate gadgets to receive user data selections. The Google gadget displayed in the import gadget can then process these data selections when the following conditions are met:

n  
n  
<Require feature="pubsub" />
n  
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);
n  
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 gadget with the response from the external web service.

For more information about linking gadgets, see About linking to gadgets.

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 playing 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 language="javascript" type="text/javascript">
      function onEventChange(sender, message) {
        var newtext = gadgets.util.escapeString(message);
        document.getElementById('changeme').innerHTML=newtext;
      }
      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/

(c) Copyright Actuate Corporation 2011