UOMStore = new Array();
Ext.define('TradePortal.view.products.LeftMenu', {
	extend: 'Ext.panel.Panel',
	alias: 'widget.products_left_menu',
	id: 'products_left_menu',
	layout: {
		type: 'table',
		columns: 1
	},
	width: 240,
	height: window.innerHeight / 2 - 5,
	overflowX: 'hidden',
	autoScroll: true,
	border: false,
	buildLeftMenu: function (categories, activeCategory, classes) {
		var menu = Ext.getCmp('products_left_menu');
		//menu.removeAll();
		menu.items.each(function (panel) {
			panel.hide();
		});
		for (i in categories) {
			menu.add(Ext.create('Ext.panel.Panel', {
				html: '<span style="color:rgb(243,112,36);">&gt;</span> ' + categories[i]['text'],
				width: 220,
				height: 20,
				border: true,
				categories: categories,
				category: categories[i],
				listeners: {
					el: {
						click: function () {
							Ext.getCmp('products_top_menu').topMenuClick(Ext.getCmp(this.id));
						}
					}
				}
			}));
			if (categories[i] == activeCategory) {
				for (j in classes) {
					menu.add(Ext.create('Ext.panel.Panel', {
						html: classes[j].get('menuDesc'),
						prodClass: classes[j],
						width: 185,
						height: 20,
						margin: '0 0 0 10',
						cls: 'left-sub-menu-item',
						listeners: {
							el: {
								click: function () {
									Ext.getCmp('products_left_menu').leftMenuClick(Ext.getCmp(this.id));
								}
							}
						}
					}));
				}
			}
		}
	},
	leftMenuClick: function (button) {
		var breadcrum = Ext.getCmp('prod_breadcrumbs').html.slice(0, -8);
		var res = breadcrum.split(" > ");
		if (res.length > 4) {
			breadcrum = res[0] + '>' + res[1] + '>' + res[2] + '>' + res[3];
		}
		Ext.getStore('Products').setExtraParam('userName', Ext.getStore('HomeStatistic').last().data.id_user);
		Ext.getStore('Products').setExtraParam('deviceID', Ext.getStore('Config').data.last().data.device_id);
		Ext.getStore('Products').setExtraParam('templateID', 0);
		Ext.getStore('Products').setExtraParam('searchCategory', button.prodClass.get('prodCategory'));
		Ext.getStore('Products').setExtraParam('searchType', button.prodClass.get('prodType'));
		Ext.getStore('Products').setExtraParam('searchClass', button.prodClass.get('prodClass'));
		Ext.getStore('Products').setExtraParam('searchString', "");
		Ext.getStore('Products').setExtraParam('productIDString', "");
		Ext.getStore('Products').setExtraParam('inStockOnly', false);
		Ext.getStore('Products').setExtraParam('incGST', Ext.getStore('getPriceViewOptionsTP').last().data.GSTInc);
		Ext.getStore('Products').setExtraParam('pagesize', Ext.getStore('Config').data.last().data.pagesize);
		Ext.getStore('Products').pageSize = Ext.getStore('Config').data.last().data.pagesize;
		Ext.getStore('Products').setExtraParam('lineID', 0);
		Ext.getStore('Products').proxy.extraParams.rowsPerPage = Ext.getStore('Config').data.last().data.pagesize;
		Ext.getStore('Products').removeAll();
		UOMStore = new Array();
		Ext.getCmp('products_grid').reconfigure('Products');
		Ext.getStore('Products').loadPage(1, {
			callback: function (records, operation, success) {
				Ext.getCmp('prod_breadcrumbs').update(breadcrum + ' > ' + button.prodClass.data['menuDesc'] + '</small>');
				Ext.getCmp('products_list').buildProductsList(records);
				Ext.getCmp('products_panel').navStore = Ext.getStore('Products');
				Ext.getCmp('products_panel').configureNavButtons();
			}
		});

		Ext.getStore('Attributes').setExtraParam('classId', button.prodClass.get('prodClass'));
		Ext.getStore('Attributes').load({
			callback: function (records, operation, success) {
				//Ext.getCmp('products_left_menu').removeAll();
				Ext.getCmp('products_left_menu').items.each(function (panel) {
					panel.hide();
				});
				if (Ext.getCmp('products_class_attributes') != undefined) {
					Ext.getCmp('products_class_attributes').destroy();
				}
				Ext.getCmp('products_left_menu').add(Ext.create('TradePortal.view.products.AttributeView'));
				Ext.getCmp('products_class_attributes').buildAttributesMenu(records);
			}
		});
	}
});
