/*
 * Copyright (c) 2009 The Olympos Development Team.
 * 
 * http://sourceforge.net/projects/olympos/
 * 
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html. If redistributing this code, this
 * entire header must remain intact.
 */
Ext.namespace("cwe.navigation");

/**
 */
cwe.navigation.AccountList = function() {
};

cwe.navigation.AccountList = Ext.extend(Ext.grid.GridPanel, {
	initComponent : function() {
		var self = this;

		this.store = new chi.model.Store( {
			modelDescription : chi.model.ModelDescriptionContainer.getInstance().getDescription("Account")
		});

		Ext.apply(this, {
		    store : this.store,
		    loadMask : true,
		    viewConfig : {
		        forceFit : true,
		        markDirty : false
		    },
		    iconCls : "TransactionTreeIcon16x16",
		    hideHeaders : true,
		    height : 200,
		    title : chi.Dict.translate("Show transactions of account"),
		    columns : [ {
		        header : "title",
		        width : 200,
		        dataIndex : "title",
		        renderer : function(value, metaData, record, rowIndex, colIndex, store) {
			        return "<a class='alwaysBlue' href='#'>" + value + "</a>";
		        }
		    }, {
		        header : "currentAmount",
		        width : 100,
		        dataIndex : "currentAmount",
		        align : "right",
		        renderer : function(value, metaData, record, rowIndex, colIndex, store) {
			        var clazz = "";

			        if (value < 0) {
				        clazz = "negativeNumber";
			        }

			        return "<span class='" + clazz + "'>" + cwe.Util.formatNumber(value) + "</span>";
		        }
		    } ]
		});

		cwe.navigation.AccountList.superclass.initComponent.apply(this, arguments);

		this.on("rowclick", function(list, rowIndex, e) {
			self.openList(rowIndex);
		});

		this.store.load();
	}
});

cwe.navigation.AccountList.prototype.openList = function(rowIndex) {
	var store = this.getStore();

	var record = store.getAt(rowIndex);

	if (record) {
		chi.model.ModelDescriptionContainer.getInstance().getDescription("Transaction").openGrid( {
			account : record
		});
	}
};

