Ext.define("Portfolio.menu.util.Favorite", {

	constructor: function() {

		var s_id = ip2.baseconfig.session.preset.origin;

		var o_settings = Portfolio.util.Handler.global.get(s_id + ".favorites-settings", {
		});

		Ext.applyIf(o_settings, {
			title: ip2.i18n({
				da: "Favoritter",
				en: "Favorites"
			}),
			binding: {
				ctrl: false,
				shift: false,
				alt: false,
				keyCode: null
			}
		});

		var i_window = Ext.widget("window", {
			layout: "fit",
			height: 300,
			minWidth: 600,
			closable: false,
			modal: true,
			title: ip2.i18n({
				da: "Favorit indstillinger",
				en: "Favorite settings"
			})
		});

		var i_btnSave = Ext.widget("button", {
			text: ip2.i18n({
				da: "Gem",
				en: "Save"
			}),
			disabled: true,
			iconCls: "pf-floppy_disk",
			handler: function() {

				var i_form = i_panel.getForm();

				var o_values = i_form.getFieldValues();
				var o_settings = Portfolio.util.Handler.global.get(s_id + ".favorites-settings", {});

				Ext.apply(o_settings, o_values);

				Portfolio.util.Handler.global.set(s_id + ".favorites-settings", Ext.encode(o_settings));

				i_window.close();
			}
		});

		var i_btnClose = Ext.widget("button", {
			text: ip2.i18n({
				da: "Luk",
				en: "Close"
			}),
			disabled: false,
			iconCls: "pf-navigate_cross",
			handler: function() {
				i_window.close();
			}
		});

		var i_panel = Ext.widget("form", {
			layout: "anchor",
			bodyPadding: 10,
			defaults: {
				anchor: "100%"
			},
			items: [
				{
					xtype: "i18n-textfield",
					name: "title",
					fieldLabel: ip2.i18n({
						da: "Title",
						en: "Title"
					}),
					value: o_settings.title
				},
				{
					xtype: "portfolio-bindigfield",
					name: "binding",
					fieldLabel: ip2.i18n({
						da: "Genvejstast",
						en: "Shortcut"
					}),
					value: o_settings.binding
				}
			],
			listeners: {
				dirtychange: {
					fn: function(i_form, b_dirty) {

						i_btnSave[b_dirty ? "enable" : "disable"]();
					}
				}
			}
		});

		var i_toolbar = Ext.widget("toolbar", {
			dock: "bottom",
			items: [
				"->",
				i_btnSave,
				i_btnClose
			]
		});

		i_panel.addDocked(i_toolbar);

		i_window.add(i_panel);

		i_window.show();
	}
});
