<klip>
   <identity>
      <title>
         API: Engines.Data
      </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>
   <style>
      alert {
         type: item;
      }

      sender {
         itemcol: 2;
         noterow: 1;

         label: 'Sender';

         emphasis: strong;
      }


      summary {
         itemcol: 3;
         noterow: 4;

         wrap: false;

         notelabel: false;
      }

      date {
         itemcol: 4;
         noterow: 2;

         label: 'Date';
      }

      category {
         noterow: 3;

         label: 'Category';
      }


      level {
         itemcol: 1;
         noterow: 5;
         notelabel: false;
         
         type: image;
      }

      url {
         type: link;
      }
            
      id {
         key: override;
      }

   </style>
   <klipscript>
   <![CDATA[


function onRefresh()
{

   // Define XML Parser callbacks
   Engines.Data.onCreate = myCreate;
   Engines.Data.onUpdate = myUpdate;

   _t( "onRefresh () -- " + Prefs.contentsource );
   var result = Engines.Data.process ( Prefs.contentsource );

   show_state();
   
   return result;
}


//
// Support functions -----------------------------------------------
//

function myCreate( new_item )
{
   _t( "myCreate() --- Got an XML Callback for new item" );
   return modify (new_item);
}

function myUpdate( current_item, properties )
{
   _t( "myUpdate() --- Got an XML Callback for updated item" );
   return modify (properties);
}

function modify( pending )
{
   // Place your code here to modify incoming/updating items

   _t( "    sender: " + pending.getData( "sender" ));
   _t( "    summary: " + pending.getData( "summary" ));
   _t( "    date: " + pending.getData( "date" ));
   _t( "    level: " + pending.getData( "level" ));
   _t( "    category: " + pending.getData( "category" ));
   _t( "    id: " + pending.getData( "id" ));

   _t( " " );
   return true;
}

//
// Useful Debug Code -----------------------------------------------
//

function show_state() 
{
   show_items ();
}

function show_items() 
{
   if (Items.length == 0) 
   {
      trace ("There are no items in the Items[] array\r\n");
      return;
   }

   for( i = 0; i < Items.length; i++ ) 
   {
      trace ("Items[" + i + "]: \r\n");       
      queryItem (Items[i]);
   }
}

function queryItem( item ) 
{
    trace( "-----------------\r\n" );
    trace( "    .text         = \"" + item.text + "\"  (string)\r\n" );
    trace( "    .url          = \"" + item.url + "\"  (string)\r\n" );
    trace( "    .note         = \"" + item.note + "\"  (string)\r\n" );
    trace( "    .iid          = \"" + item.iid + "\"  (string)\r\n" );
    trace( "    .extra        = \"" + item.extra + "\"  (string)\r\n" );
    trace( "    .hidden       = " + item.hidden + " (boolean)\r\n" );
    trace( "    .visited      = " + item.visited + " (boolean)\r\n" );
    trace( "    .canpurge     = " + item.canpurge + "  (boolean)\r\n" );
    trace( "    .alerting     = " + item.alerting + " (boolean)\r\n" );
    trace( "    .creation     = " + item.creation + " (double)\r\n" );
    trace( "    .pubdate      = " + item.pubdate + "  (double)\r\n" );
    trace( "    .lastmodified = " + item.lastmodified + "  (double)\r\n" );

    // Output the current value of each defined element in an item

       trace( "      .getData( \"sender\" ) = \"" + item.getData( "sender" ) + "\" (string)\r\n" );
       trace( "      .getData( \"summary\" ) = \"" + item.getData( "summary" ) + "\" (string)\r\n" );
       trace( "      .getData( \"date\" ) = \"" + item.getData( "date" ) + "\" (string)\r\n" );
       trace( "      .getData( \"url\" ) = \"" + item.getData( "url" ) + "\" (string)\r\n" );
       trace( "      .getData( \"level\" ) = \"" + item.getData( "level" ) + "\" (string)\r\n" );
       trace( "      .getData( \"category\" ) = \"" + item.getData( "category" ) + "\" (string)\r\n" );
       trace( "      .getData( \"id\" ) = \"" + item.getData( "id" ) + "\" (string)\r\n" );
    
    trace( "\r\n" );
}


var gTrace = true;
function _t( s ) 
{
   if ( gTrace ) {
      trace( s + "\r\n" );
   }
}
   ]]>
   </klipscript>
</klip>

