/**
 * ext_lamppost_feed.js
 *
 * @copyright Aaron Baker &copy; 2008
 */
var obj_lp_grid = null;

Ext.onReady(function() {     
   /**
    * LAMPpost feed grid
    */
   obj_lp_grid = new Ext.grid.GridPanel({
      title: 'LAMPpost - Latest Entries',
      renderTo: 'lamppost_feed',
      width: 700,
      height: 300,
      autoScroll: true,
      loadMask: true,
      store: new Ext.data.Store({
         url: 'feed_retriever.php',
         baseParams: {
            url: 'http://thelampposts.blogspot.com/feeds/posts/default'
         },
         autoLoad: true,
         sortInfo: {
            field: 'published',
            direction: 'DESC'
         },
         reader: new Ext.data.XmlReader({
            record: 'entry'
         }, ['published', 'title', 'content', 'url'])
      }),
      columns: [{
         header: 'Date', dataIndex: 'published', sortable: true,
         renderer: function(str_date) {
            str_date = str_date.substring(0, 10);
            var arr_parts = str_date.split('-');
            str_date = arr_parts[2]+'/'+arr_parts[1]+'/'+arr_parts[0];
            return str_date;
         }
      }, {
         header: 'Title', dataIndex: 'title', sortable: true, width: 500,
         renderer: function(str_title) {
            return '<b>'+str_title+'</b>';
         }
      }],
      viewConfig: {
         forceFit: true,
         enableRowBody: true,
         /**
          * Add the Content data under the Date and Title per row
          */
         getRowClass: function(obj_record, int_index, obj_row, obj_store) {
            obj_row.body = '<i>'+Ext.util.Format.ellipsis(obj_record.data.content, 200)+'</i>';
         }
      },
      selModel: new Ext.grid.RowSelectionModel({
         singleSelect: true,
         listeners: {
            'rowselect': function() {
               if (obj_lp_grid.buttons[0].disabled) {
                  obj_lp_grid.buttons[0].enable();
               }
            }
         }
      }),
      buttons: [{
         text: 'View entry',
         disabled: true,
         handler: function() {
            window.open(obj_lp_grid.getSelectionModel().getSelected().data.url);
         }
      }],
      buttonAlign: 'center'
   });
   
});
