Ext.define("Ext.ux.mailChimp.Panel", {
	extend: "Ext.window.Window",
	alias: ["widget.mailchimppanel"],
	title: "Subscribe",
	layout: "fit",
	modal: true,
	autoScroll: true,
	initComponent: function() {
		var me = this;

		me.items = Ext.create("Ext.form.Panel", {
			bodyPadding: 15,
			width: 600,
			url: "/ip2-services/" + "wshMailChimp.aspx?action=subscribe&listid=" + me.listid,
			layout: "anchor",
			defaults: {
				anchor: "100%"
			},
			defaultType: "textfield",
			items: [{
				fieldLabel: ip2.i18n({ da: "Email", en: "Email" }),
				name: "email",
				vtype: "email",
				allowBlank: false
			}],
			buttons: [{
				text: ip2.i18n({ da: "Gem", en: "Save" }),
				formBind: true,
				disabled: true,
				handler: function() {
					var form = this.up("form").getForm();
					if (form.isValid()) {
						form.submit({
							success: function(form, action) {
								if (Ext.isFunction(me.success)) {
									me.success.call(window, action.result.response);
								}

								me.close();
							},
							failure: function(form, action) {
								Ext.Msg.alert("Failed", action.result.response.error);
							}
						});
					}
				}
			},{
				text: ip2.i18n({ da: "Nulstil", en: "Reset" }),
				handler: function() {
					this.up("form").getForm().reset();
				}
			},{
				text: ip2.i18n({ da: "Luk", en: "Close" }),
				handler: function() {
					me.close();
				}
			}]
		});

		me.callParent();
	}
});
