﻿


Entegris.ProductCatalog.CategoryLanding = function(IsBlueBox, DivisionItemName, CategoryItemName, data, dropdownID){
    this.IsBlueBox = IsBlueBox;
    this.DivisionItemName = DivisionItemName;
    this.CategoryItemName = CategoryItemName;

    this.store = new Ext.data.SimpleStore({
        'id': 0,
        fields: ['value', 'text', 'class', 'type'],
        data : data
    });
            
    this.Filter = new Ext.form.ComboBox({
        store: this.store,
        typeAhead: false,
        transform: dropdownID,
        width:268,
        forceSelection:true,
        editable: false,
        mode: 'local',
        valueField: 'value',
        displayField: 'text', 
        tpl: '<div class="x-combo-list-item"><div class="{class}">{text}</div></div>'
    });
    
   
   this.Filter.on('select', this.onSelect, this);
   this.Filter.on('beforequery', this.onBeforeQuery, this);
   this.Filter.setValue('ALL');
   
    try {
        Ext.get('CategoryResultsBox').setVisibilityMode(Ext.Element.DISPLAY);
            Ext.get('CategoryResultsBox').setVisible(false);
    } catch (e) {}
        
};



Ext.extend(Entegris.ProductCatalog.CategoryLanding, Ext.util.Observable, {
 
   onBeforeQuery: function(combo, e)
   {
    combo.forceAll = true;
    combo.query="";
   }, 
   onSelect: function(combo, record, index) {
        var applicationItemID = 0;
        var processStepItemID = 0;
        
        if (record.data.type == 'Application') {
            applicationItemID = record.data.value;
        }
        if (record.data.type == 'ProcessStep') {
            processStepItemID = record.data.value;
        }
        
        var showResultBox = applicationItemID + processStepItemID > 0;
        
    
        Entegris.API.ProductCatalog.CategoryLanding.GetFilteredProductLines(this.IsBlueBox, this.DivisionItemName, this.CategoryItemName, applicationItemID, processStepItemID, this.onSelect_process, {showResultBox: showResultBox})
    },
    
    onSelect_process: function (response) {
        Ext.get('FilteredResults').update(response.value);
        
        try {
            Ext.get('CategoryResultsBox').setVisible(response.context.showResultBox);
        } catch (e) {}
    }
 
});