Ext.define("Portfolio.dynapp.App", {

	extend: "Ext.panel.Panel",

	layout: "fit",

	alias: "widget.dynapp.app",

	options: {},

	alternateClassName: [
		"Ext.dynapp.app"
	],

	requires: [
		"Portfolio.dynapp.util.Service",
		"Portfolio.dynapp.view.Main"
	],

	initComponent: function() {

		var i_self = this;
		i_self.callParent();
		var o_options = i_self.options;

		Portfolio.dynapp.util.Service.getMeta(o_options, function(o_metaData) {

			i_self.options.properties = o_metaData.properties;
			i_self.options.srcPlugin = o_metaData.srcPlugin;

			var o_plugin = i_self.options.properties.plugin;

			if (o_plugin.convertor) {

				Ext.Array.each(o_metaData.fields, function(i_field) {
					if (o_plugin.convertor[i_field.name]) {
						i_field.convertor = function(value) {
							o_plugin.convertor[this.name].call(this, value);
						};
					}
				});
			}

			var i_panel = Ext.widget("dynapp.view.main", {
				meta: o_metaData,
				options: i_self.options,
				itemId: "dynapp-main"
			});

			i_self.add(i_panel);
		});
		return i_self;
	}
});
