Ext.define("Portfolio.message.view.Main", {

	extend: "Ext.grid.Panel",

	xtype: "portfolio-message-grid",

	title: ip2.i18n({
		da: "Log & beskeder",
		en: "Log & Messages"
	}),

	requires: [
		"Portfolio.message.model.Error"
	],

	listeners: {
		itemdblclick: {
			fn: function(i_view, i_record) {

				var i_self = this;
				i_self.fireEvent("viewerror", i_record);
			}
		}
	},

	header: {
		listeners: {
			click: {
				fn: function(i_header) {
					var i_panel = i_header.up("panel");
					i_panel.toggleCollapse();
				}
			}
		}
	},

	ui: "menu-navigation",

	initComponent: function() {

		var i_self = this;

		var i_store = i_self.createStore();
		var a_columns = i_self.createColumns();

		Ext.apply(i_self, {
			store: i_store,
			columns: a_columns
		});

		i_self.callParent(arguments);
	},

	createStore: function() {

		var i_self = this;

		var i_store = Ext.create("Ext.data.Store", {
			model: "Portfolio.message.model.Error",
			proxy: {
				type: "memory"
			}
		});

		return i_store;
	},

	createColumns: function() {

		var i_self = this;

		var a_columns = [
			{
				header: ip2.i18n({
					da: "Tidspunkt",
					en: "Time"
				}),
				sortable: true,
				dataIndex: "date",
				width: 130,
				renderer: Ext.util.Format.dateRenderer("Y.m.d   H:m:s")
			},
			{
				header: ip2.i18n({
					da: "Beskrivelse",
					en: "Description"
				}),
				sortable: true,
				flex: 1,
				dataIndex: "description"
			},
			{
				header: ip2.i18n({
					da: "Tekst",
					en: "Text"
				}),
				sortable: true,
				flex: 1,
				dataIndex: "urlText"
			},
			{
				header: ip2.i18n({
					da: "Url",
					en: "Url"
				}),
				sortable: true,
				flex: 1,
				dataIndex: "url"
			},
			{
				header: ip2.i18n({
					da: "Linje no.",
					en: "Line No."
				}),
				sortable: true,
				flex: 1,
				dataIndex: "lineNo"
			}
		];

		return a_columns;
	}
});
