Ext.define('Ext.ux.widget.folderorganizer.Navigation', {

	extend: 'Ext.ux.folderorganizer.Organizer',

	alias: ['widget.widgetnavigation'],

	initComponent: function () {

		var i_cmp = this;
		var o_config = i_cmp.initialConfig;
		var o_settings = {};

		var a_proxyMap = [
			'folderTitle', 'folderUiName', 'folderOrderBy',
			'folderKey', 'propertyKey', 'contentToken',
			'folderToken', 'contentKey', 'propertyKey',
			'contentTitle', 'contentFilter',
			'folderDataLibrary', 'folderUiName',
			'statusTitle', 'publicationTitle'
		];

		// Start building the settings object from the initialConfig
		Ext.apply(o_settings, ip2.pick(i_cmp.initialConfig, [
			'proxy', 'dmd', 'entity', 'xpd', 'extraProps', 'environment',
			'menus', 'buttons',	'expandToLevel', 'levelSelectFirst'
		]));

		Ext.apply(o_settings, ip2.pick(o_config, a_proxyMap));

		o_settings.folderProperty = {
			ID: o_settings.folderKey || 'NAMNAMTKN',
			PARENTID: o_settings.contentKey || 'NAMPNTTKN',
			PROPERTIES: o_settings.propertyKey || 'NAMPROP'
		};

		var o_organizer = {};

		Ext.apply(o_organizer, {
			xpd: o_settings.xpd || 'menus.xpd',
			environment: o_settings.environment || 'menuorganizer',
			folder: {
				dmd: o_settings.dmd || 'webshop.dmd',
				proxy: o_settings.proxy,
				entity: o_settings.entity || 'WSHMNUET00',
				menus: o_settings.menus || ['edit', 'remove', 'expandChildren'],
				buttons: o_settings.buttons || ['add', 'edit', 'remove', 'refresh'],
				propertyNameMapping: o_settings.folderProperty,
				displayRootNode: true,
				expandToLevel: o_settings.expandToLevel || 3,
				levelSelectFirst: o_settings.levelSelectFirst || 2,
				extraProps: o_settings.extraProps || 'page',
				extraColumns: [
					{
						header: o_settings.statusTitle ? ip2.i18n(o_settings.statusTitle) : ip2.i18n({
							da: 'Status',
							en: 'Status'
						}),
						width: 60,
						renderer: function(value, meta, record, rowIndex, colIndex) {
							if (record.data.rowProps && ip2.page) {
								return ip2.page.formatPublish(Ext.decode(record.data.rowProps).properties);
							}
							else {
								return '';
							}
						}
					},
					{
						header: o_settings.publicationTitle ? ip2.i18n(o_settings.publicationTitle) : ip2.i18n({
							da: 'Publikationsdatoer',
							en: 'Publication Dates'
						}),
						width: 260,
						renderer: function(value, meta, record, rowIndex, colIndex) {
							if (record.data.rowProps && ip2.page) {
								return ip2.page.formatPublishDate(Ext.decode(record.data.rowProps).properties);
							}
							else {
								return '';
							}
						}
					}
				],
				title: o_settings.folderTitle === false ? false : o_settings.folderTitle || ip2.i18n({
					da: 'Navigation',
					en: 'Navigation'
				})
			},
			content: {
				title: o_settings.contentTitle === false ? false : o_settings.contentTitle || ip2.i18n({
					da: 'Indhold',
					en: 'Content'
				})
			}
		});

		Ext.apply(i_cmp, o_organizer);

		// Clean up;
		ip2.each(a_proxyMap, function (s_property) {
			delete i_cmp[s_property];
		});

		i_cmp.callParent(arguments);

		return i_cmp;
	}
});
