﻿// JavaScript File
News = function(isBlueBox)
{
    this.isBluebox = isBlueBox;
    this.data = eval(AJAX.API.GetNewsCategories().value);
    this.dataStore = new Ext.data.SimpleStore({'id': 0,fields: ['value', 'text', 'class', 'type'],data : this.data}); 
    this.newsCategory = new Ext.form.ComboBox({
        typeAhead: false,
        transform: "newsCategory",
        store:this.dataStore,
        width:230,
        forceSelection:true,
        editable: false,    
        mode: 'local',
        valueField: 'value',
        displayField: 'text', 
        tpl: '<div class="x-combo-list-item"><div class="{class}">{text}</div></div>',
        allowBlank:false
    });
    this.newsCategory.on('select', this.onNewsCategorySelect, this);
    this.newsCategory.setValue('ALL');
    this.newsCategory.on('beforequery', this.onBeforeQuery, this);
    data = AJAX.API.GetNewsArticles('', this.isBluebox).value;
    var details = Ext.get("newsArticles");
    details.update(data);
}
Ext.extend(News, Ext.util.Observable, {
    
   onBeforeQuery: function(combo, e)
   {
    combo.forceAll = true;
    combo.query="";
   },   
   onNewsCategorySelect: function(combo, record, index) {
       var data ="";
       if ( record.data.value=='ALL')
       {
            data = AJAX.API.GetNewsArticles('',this.isBluebox).value;
       }
       else
       {
            data = AJAX.API.GetNewsArticles(record.data.value,this.isBluebox).value;
       }
       var details = Ext.get("newsArticles");
       
       details.update(data);
    }
});
