Ext.define("Portfolio.designer.ui.domainModelEntityComboBox", {

	extend: "Ext.form.ComboBox",

	alias: [
		"widget.ip2DomainModelEntityComboBox"
	],
	displayField: "value",

	valueField: "key",

	matchFieldWidth: false,

	autoScroll: true,

	queryMode: "local",

	listConfig: {
		width: 400
	},

	initComponent: function() {

		var i_self = this;

		i_self.store = Ext.create("Ext.data.Store", {
			fields: ["key", "value"],
			renderer: function(key) {
				var r = this.store.findRecord("key", key);
				return (r ? r.get("value") : key);
			}
		});

		i_self.callParent();

		var i_store = i_self.getStore();

		i_self.renderer = i_store.renderer;

		i_self.loadData(i_self.entities);
	},

	loadData: function(a_entities) {

		var i_self = this;
		var i_store = i_self.getStore();

		var o_hidden = i_self.hiddenEntities = i_self.hiddenEntities || {};

		var a_data = [];

		Ext.Array.each(a_entities, function(value) {
			if (!o_hidden.hasOwnProperty(value.name)) {
				a_data.push({ "key": value.name, "value": value.name + "-" + ip2.i18n(value.title)});
			}
		});

		i_store.loadData(a_data);
	}
  });
