Ext.namespace('cmv.news');

cmv.news.RawPanel = Ext.extend(Ext.Panel,{
  record: undefined,
  constructor: function(config){
    config = Ext.apply({
      header: true,   
      frame: true,
      anchor:'90%',
      collapsible: false,
      bbar:{
        hidden:true
      }
    }, config);
    cmv.news.RawPanel.superclass.constructor.call(this, config);
    function createLink(column,rec){
      return {
        xtype: 'tbtext',
        html:'<a href="'+rec.get(column)+'" target="_blank">'+rec.get(column+'_tekst')+'</a>'
      }
    }
    this.setTitle((this.record.get('dato').format('Y')!='2038'?Ext.util.Format.capitalize(this.record.get('dato').format(Date.patterns.LongDate))+': ':'')+this.record.get('overskrift'));
    var link = new Array;
    var i = 0;
    if(this.record.get('link1')!='')
      link[i++]=createLink('link1',this.record);
    if(this.record.get('link2')!='')
    {
      if(i==1)
        link[i++]={
          xtype:'tbseparator'
        };
      link[i]=createLink('link2',this.record);
    }
    if(i!=0)
    {
      var tb=this.getBottomToolbar();
      tb.addItem(link);
      tb.setVisible(true);
    }
  }
});

Ext.reg('cmvnewsrawpanel', cmv.news.RawPanel);

cmv.news.Panel = Ext.extend(cmv.news.RawPanel,{
  constructor: function(config){
    cmv.news.Panel.superclass.constructor.call(this, config);
    this.add(new Ext.Panel({
      html:(this.record.get('imagetype')!=''?'<div class="pic-wrap"><img src="php/newsgraphic.php?idx='+this.record.get('idx')+'"/></div>':'')+this.record.get('artikel')
    }));
  }
});

Ext.reg('cmvnewspanel', cmv.news.Panel);
