Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Typically a widget will save any options that it wants on reloading during a onSaveWidgetOptions call.  Any json object passed to the widget framework on that call will be returned when the widget is loaded via onLoadWidgetOptions in a WidgetSaveObject.  The WidgetSaveObject has 2 interesting fields, userSave and communitySave.  The userSave object is the standard object that was saved during a onSaveWidgetOptions call and should be used for any save options that are unique to an individual user; for example their current zoom level and centerpoint on map widget or the graph type on a statistics widget. 

Code Block
titleWidget Saving Example
//Here is an example of creating an anonymous object (tempWidgetOptions)
//and setting some fields to save the zoom and centerpoint of a map widget 
//This method will be polled every few minutes
public function onSaveWidgetOptions():Object
{
      var tempWidgetOptions:Object = new Object();
      tempWidgetOptions[ "centerLat" ] = _map.center.lat;
      tempWidgetOptions[ "centerLng" ] = _map.center.lng;
      tempWidgetOptions[ "zoomLevel" ] = _map.zoom;
      return tempWidgetOptions;
}

//The next time a widget is opened it will be sent the anonymous object
//that was last saved from onSaveWidgetOptions
//that object can be used to restore previous states
public function onLoadWidgetOptions( widgetOptions:WidgetSaveObject ):void
{               
    if ( widgetOptions != null )
    {
        //this holds a users last map 
        if ( widgetOptions.userSave != null )
        {
              this.widgetOptions = widgetOptions.userSave;
              //widgetOptions contains fields centerLat,centerLng,zoomLevel from our last save
        }
	}
}



The communitySave object is used for giving a widget specific saved data for a given community, for example giving an intelligence community KML specific to a region of interest for a map widget or using a certain color scheme specific to business operations for a statistics widget.  The communitySave objects can only be set external to a widget in http://infinite.ikanow.com/fileUploader.jsp  To make a communitySave in the fileUploader just upload a json file with a community selected, any json available to a user when a widgetLoads will be passed into the WidgetSaveObject.communitySave when onLoadWidgetOptions is called from then on.