Ext.define("Ext.ux.call2action.Window", {

	extend: "Ext.window.Window",

	alias: [
		"widget.ip2Call2ActionWindow"
	],
	height: 501,

	width: 760,

	autoScroll: true,

	collapsible: true,

	layout: "fit",

	config: {
		record: null,
		okFn: Ext.emptyFn,
		success: Ext.emptyFn,
		data: {},
		tabpanel: null
	},

	initComponent: function() {

		var i_self = this;

		var i_record = i_self.getRecord();

		var o_data = Ext.apply({}, i_record.getData());

		var i_tabpanel = Ext.create("Ext.ux.call2action.Tabpanel", {
			wrapper: i_self,
			data: o_data || {},
			border: false,
			layout: "fit"
		});

		i_self.buttons = [{
			xtype: "themedbutton",
			text: ip2.i18n({
				da: "Ok",
				en: "Ok"
			}),
			handler: function() {
				i_tabpanel.doSave({
					success: function() {

						var i_record = i_self.getRecord();
						var i_tabpanel = i_self.getTabpanel();
						var o_data = i_tabpanel.getValue();

						var f_success = i_self.getSuccess();
						var f_okFn = i_self.getOkFn();

						i_record.set(o_data);
						i_record.commit();

						f_success(i_record);

						i_self.close();
						f_okFn();
					}
				});
			}
		},{
			text: ip2.i18n("cancel"),
			handler: function() {
				i_self.close();
			}
		}];

		i_self.callParent();

		i_self.setTabpanel(i_tabpanel);
		i_self.setData(o_data);

		i_self.add(i_tabpanel);
	}
});
