/*
 * 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.Navigation = function() {
};

cwe.navigation.Navigation = Ext.extend(Ext.ux.layout.flexAccord.DropPanel, {
	initComponent : function() {
		var self = this;

		Ext.apply(this, {
		    layoutConfig : {
			    animate : true
		    },
		    region : "west",
		    width : 250,
		    split : true,
		    title : chi.Dict.translate("Navigation"),
		    items : [
		            new cwe.navigation.AccountList(),
		            new cwe.navigation.GlobalSearch(),
		            new Ext.Panel( {
		                title : chi.Dict.translate("Analysis"),
		                iconCls : "analysisIcon",
		    		    collapsed: true,
		                layout : "fit",
		                height : 150,
		                html : "Here will, in some future, be a list of analysis tools."
		            }),
		            new Ext.Panel( {
		                title : chi.Dict.translate("Management"),
		                iconCls : "managementIcon",
		                layout : "fit",
		                height : 400,
		                bodyStyle : "border: 0; overflow: auto;",
		                html : "<ul class='x-panel-mc managementActionList'>" + this.createManagementEntry("Account", "Accounts")
		                        + this.createManagementEntry("TransactionPartner", "Transaction Partners") + this.createManagementEntry("Tag", "Tags")
		                        + this.createManagementEntry("Contract", "Contracts") + this.createManagementEntry("Attachment", "Attachments") + this.createManagementEntry("Currency", "Currencies")
		                        + this.createManagementCustomEntry("settingsIcon", "#", "Settings") + "</ul>"
		            }) ]
		});

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

	}
});

cwe.navigation.Navigation.prototype.createManagementEntry = function(classId, text) {
	var clazz = chi.model.ModelDescriptionContainer.getInstance().getDescription(classId);

	return this.createManagementCustomEntry(clazz.getTreeIconClass(), "{ cwe.modelgrid.ModelGridContainer.getInstance().loadOrShow(chi.model.ModelDescriptionContainer.getInstance().getDescription(\""
	        + classId + "\")); return null; }", text);
};

cwe.navigation.Navigation.prototype.createManagementCustomEntry = function(cssCls, functionCode, text) {
	return "<li class='" + cssCls + "'><a onclick='" + functionCode + "' href='#'>" + chi.Dict.translate(text) + "</a></li>";
};

/**
 * Returns the instance of Navigation.
 * 
 * @return The instance of Navigation.
 * @type cwe.navigation.Navigation
 */
cwe.navigation.Navigation.getInstance = function() {
	if (!cwe.navigation.Navigation.instance) {
		cwe.navigation.Navigation.instance = new cwe.navigation.Navigation();
	}

	return cwe.navigation.Navigation.instance;
};
