	Ext.define('TradePortal.controller.Orders', {
	extend : 'Ext.app.Controller',

	stores : [ 'getVehicleTypes', 'QuoteOrders' ],

	views : [ 'orders.Panel', 'orders.OrderGrid' ],

	models : [ 'Quotes', 'getVehicleTypes' ],

	init : function() {
		if (typeof console !== "undefined") {
			console.log('Initialized Orders!');
		}

		this.control({
			'viewport > panel' : {
				render : this.onPanelRendered
			},
			'#new_order_button': {
				click: this.onTransactionButton
			},
			'#order_grid': {
				itemclick: this.onOpenOrder
			}
		});
	},
	onPanelRendered : function() {
		if (typeof console !== "undefined") {
			console.log('Orders panel was rendered');
		}
	},
	onTransactionButton: function() {
		Ext.getCmp('main_panel').items.items[1].down('panel').items.each(function(panel) {
			panel.hide();
		});
		Ext.getCmp('products_panel').show();
		Ext.getCmp('products_panel').loadAndBuildTopMenu();
	},
	onOpenOrder : function(row, record, item, index, e, eOpts ) {
		Ext.getCmp('viewport').setLoading('Loading...');

		Ext.getStore('DrillDownInfo').load({
			params: {
				userName: Ext.getStore('HomeStatistic').data.last().data.id_user,
				deviceID: Ext.getStore('Config').data.last().data.device_id,
				companyID: Ext.getStore('Config').data.last().data.company_id,
				customerID: Ext.getStore('HomeStatistic').last().data.id_cust,
				transactionNumber: record.data.transactionNumber,
				transactionSuffix: record.data.transactionSuffix,
				tranType: record.data.transactionType
			}
		});
	}
});
