Ext.define('Ext.ux.gallery.view.MediaEditorRelation', {
	extend: "Ext.ux.gallery.view.MediaEditor",
	alias: "widget.mediaeditorrelation",

	initComponent: function () {

		var i_cmp = this;
		i_cmp.callParent(arguments);
	},

	createPickerField: function(o_config) {
		var i_cmp = this;
		var i_picker = Ext.widget("uploadpickermanager", {
			itemId: 'uploadpicker',
			name: 'RELCHDTKN',
			path: i_cmp.path,
			extensions: i_cmp.extensions,
			ignoreStaticDir: i_cmp.ignoreStaticDir,
			allowBlank: false,
			userChange: false,
			submitRaw: false,
			fieldLabel: ip2.i18n({
				da: 'Medie',
				en: 'Media'
			}),
			emptyText: ip2.i18n({
				da: 'Sti til lokalt medie eller URL til eksternt medie',
				en: 'Path to local media or URL to external media'
			}),
			listeners: {
				select: {
					fn: function(item, a_records) {
						if (i_cmp.action == "add") {
							var o_record = a_records[0];
							var i_form = item.up("form");
							var i_fieldhead = i_form.down('[name="title"]');
							var i_fieldsub = i_form.down('[name="caption"]');

							i_cmp.systemSet = true;

							if (!i_fieldhead.userChange) {
								i_fieldhead.setValue(o_record.get("FILHEAD"));
							}
							if (!i_fieldsub.userChange) {
								i_fieldsub.setValue(o_record.get("FILSUB"));
							}

							i_cmp.systemSet = false;
						}
					}
				}
			}
		});
		return i_picker;
	}

});
