Home
Developers

Developers

  • Documentation
    • Developer Guide
    • API Reference
    • Style Guide
    • How-To
    • Troubleshooting
  • Submit a Flake
  • Support

Pageflakes How-To and Troubleshooting Guide

  • Manage Flake Instances
  • Server-Side Scripting
  • Auto-Save Settings
  • Storing an Array into a Profile
  • Using CSS
  • Access Web Services from Flakes
  • Flake Development Tools
  • Troubleshooting
Home » Documentation » How-To

Auto-Save Settings

This example demonstrates how to create a function that automatically saves the settings for a given flake. The function detects differences between the settings form and the profile data; if a difference is found, it calls the save() method.


function demoFlake(id) 
{ 
  var _self=this; 
  var _instance = null; 
  this.autoSave=function ()
  { 
    var savedDoAlert=false; 
    if( _instance.Profiles["DOALERT"] )
      savedDoAlert = _instance.Profiles["DOALERT"]; 
    var savedText=""; 
    if( _instance.Profiles["TEXT"] )
      savedText = _instance.Profiles["TEXT"]; 
    if(document.getElementById(_id+"doAlert").checked!=savedDoAlert  
       ||
  document.getElementById(_id+"text").value!=savedText)   
    _self.saveProfile(); 
    setTimeout(_self.autoSave, 8000); 
  } 
  this.load=function(instance)
  { 
    _instance = instance; 
    _self.autoSave(); 
  }
} 

This example:

  1. Saves a reference to this during initialization, called _self.
  2. Executes the _self.autoSave() function during load to start the auto-save process.
  3. Within the autoSave() function:
    • Creates a local copy of the variables stored in the profile.
    • Compares these to the data stored in the form.
    • If there's a difference calls _self.saveProfile()
    • Sets a new timeout to when the next auto-save check should occur.
‹ Server-Side ScriptingupStoring an Array into a Profile ›
»
  • Printer-friendly version