<klip>
   <identity>
      <title>
         API: Prefs
      </title>
   </identity>
   <locations>
      <contentsource>
         http://support.klipfolio.com/files/demo/demo.xml
      </contentsource>
      <icon>
         http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
      </icon>
      <banner>
         http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png   
      </banner>
   </locations>
   <klipscript>
   <![CDATA[

 function onLoad() {
 
    //
    // Set three preferences
    //
    Prefs.setPref( "pref_A", "23" );
    Prefs.setPref( "pref_B", "true" );
    Prefs.setPref( "pref_C", "http://www.klipfolio.com" );
    
    //
    // Dump Prefs (method #1)
    //
    trace( "Value of pref_A: '" + Prefs.getPref( "pref_A" ) + "'\r\n" );
    trace( "Value of pref_B: '" + Prefs.getPref( "pref_B" ) + "'\r\n" );
    trace( "Value of pref_C: '" + Prefs.getPref( "pref_C" ) + "'\r\n" );  
    
    //
    // Update the preferences
    //
    trace( "\r\n" );
    trace( "Setting pref_A, pref_B, and pref_C.\r\n" );
    Prefs.setPref( "pref_A", "1000" );
    Prefs.setPref( "pref_B", "false" );
    Prefs.setPref( "pref_D", "A New Pref" );
    
    //
    // Dump all Prefs (method #2) 
    //
    trace( "\r\n" );
    show_all_prefs();
    
    //
    // Check the value of pref_B
    //
    trace( "\r\n" );
    trace( "First Check: " );
    if( Prefs.getPref( "pref_B" ) == "true" ) {
        trace( "Pref_B is true\r\m" );
    } else {
        trace( "Pref_B is false\r\n" );
    }
    
    //
    // This is a common idom to convert a pref's value (which is string) into a boolean
    // true or false.
    //
    var check_B = (Prefs.getPref( "pref_B" ) == "true" ? true : false );
    
    //
    // Check the value of pref_B again using check_B as a boolean
    //
    trace( "\r\n" );
    trace( "Second Check: " );
    if( check_B ) {
        trace( "Pref_B is true\r\n" );
    } else {
        trace( "Pref_B is false\r\n" );
    }
 
    //
    // When you query an non-existent preference, Klipfolio Dashboard returns 
    // the empty string.
    //
    trace( "\r\n" );
    trace( "Querying values of pref_a and pref_X\r\n" );
    trace( "Value of pref_a: '" + Prefs.getPref( "pref_a" ) + "'\r\n" );
    trace( "Value of pref_X: '" + Prefs.getPref( "pref_X" ) + "'\r\n" );
    
    
    //
    // This is another common idom: check for a preference to see if this is the
    // first time this Klip is loaded.
    //
    trace( "\r\n" );
    if (Prefs.getPref ("preconfigured") != "true")
    {
        // ... setup your prefs, default values for UI components, etc.
 
         //
         // Don't do KlipSetup next time this Klip Loads
         //
        Prefs.setPref ("preconfigured", "true");
    }
 
 }
 
 function onRefresh()
 {
    var xml = "<xml><item><link></link><description>" +
          "(See Debug Window for output)" +
          "</description></item></xml>";
             
     return Engines.Data.process( xml );
 }
 
 //
 // Iterate through your Klip's prefs by accessing Prefs[] as an array
 //
 function show_all_prefs() {
    var i;
    for (i = 0; i < Prefs.length; i++) { 
       trace("Prefs["+i+"] '"+Prefs[i].name+"' == '"+Prefs[i].value+"'\r\n"); 
    }
}


   ]]>
   </klipscript>
</klip>

