Ext.define("Ext.ux.history.view.HistoryView", {
	extend: "Ext.panel.Panel",
	alias: ["widget.historyview"],
	controller: "history",
	requires: [
		"Ext.ux.history.controller.History",
		"Ext.ux.history.viewmodel.History",
		"Ext.ux.history.view.HistoryPanel",
		"Ext.ux.entity.Grid"
	],
	layout: {
		type: "hbox",
		align: "stretch"
	},
	config: {
		historyPanel: null,
		historyGrid: null,
		keys: {},
		entity: null,
		transactiontype: null,
		extraParams: null
	},
	viewModel: {
		type: "history"
	},
	initComponent: function() {

		var i_self = this;
		var o_config = Ext.apply({}, i_self.initialConfig);

		var n_token = 0;

		var o_keys = i_self.getKeys();
		var o_extraParams = i_self.getExtraParams();
		
		for (var key in o_keys) {
			n_token = o_keys[key];
		}

		if (n_token) {
			var a_filter = [{
				property: "LOGTRNTYP",
				value: i_self.getTransactiontype()
			},{
				property: "LOGENTTKN",
				value: n_token
			}];

			o_extraParams = {
				filter: Ext.JSON.encode(a_filter)
			};

			Ext.apply(i_self, {
				extraParams: o_extraParams
			});
		}

		i_self.callParent(arguments);

		var i_historygrid = Ext.widget("ip2pagingGridOld", Ext.apply({
			flex: 1,
			split: true,
			closabled: false,
			dmd: {
				path: "dmd/portfolio.dmd",
				entityName: "NAVLOGTR00"
			},
			uiName: "portfolio",
			transactiontype: "NAVLOGTR00",
			extraParams: o_extraParams,
			listeners: {
				select: {
					fn: function(i_view, i_selected) {

						var i_historypanel = i_self.getHistoryPanel();
						var i_historygrid = i_self.getHistoryGrid();
						i_historypanel.fireEvent("gridrowselect", i_historygrid, i_selected);
					}
				}
			}
		}, o_config));

		var i_historypanel = Ext.widget("historypanel", Ext.apply({
			flex: 2,
			closabled: false,
			split: true
		}, o_config));

		i_self.setHistoryPanel(i_historypanel);
		i_self.setHistoryGrid(i_historygrid);

		i_self.add([
			i_historygrid,
			i_historypanel
		]);
	}
});
