﻿// JavaScript File
TechPub = function(isBlueBox)
{
    this.IsBluebox = isBlueBox;
    this.data = eval(AJAX.API.GetTechPubCategories().value);
    this.dataStore = new Ext.data.SimpleStore({'id': 0,fields: ['value', 'text', 'class', 'type'],data : this.data}); 
    this.techpubCategory = new Ext.form.ComboBox({
        typeAhead: false,
        transform: "techpubCategory",
        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.techpubCategory .on('select', this.onTechPubCategorySelect, this);
    this.techpubCategory .setValue('ALL');
    this.techpubCategory .on('beforequery', this.onBeforeQuery, this);
    data = AJAX.API.GetTechPubArticles('', this.IsBluebox).value;
    var details = Ext.get("newsArticles");
    details.update(data);
}
Ext.extend(TechPub, Ext.util.Observable, {
    
   onBeforeQuery: function(combo, e)
   {
    combo.forceAll = true;
    combo.query="";
   },   
   onTechPubCategorySelect: function(combo, record, index) {
       var data ="";
 
       if ( record.data.value=='ALL')
       {
            data = AJAX.API.GetTechPubArticles('',this.IsBluebox).value;
       }
       else
       {
            data = AJAX.API.GetTechPubArticles(record.data.value, this.IsBluebox).value;
       }
       var details = Ext.get("newsArticles");
       details.update(data);
    }
});

