Ext.define("Ext.ux.call2action.GeneralPanel", {
	extend: "Ext.form.Panel",

	alias: [
		"widget.ip2Call2ActionGeneralPanel"
	],

	border: false,

	bodyPadding: 10,

	layout: "anchor",

	initComponent: function() {

		var i_self = this;
		i_self.callParent();

		var o_data = i_self.config.data;
		i_self.data = o_data;

		var o_xpd = ip2.resource.get("call2action.xpd", true);

		if (o_xpd && Ext.Object.getKeys(o_xpd.collections).length > 1) {

			var a_fields = Ext.ux.xpd.Handler.getFieldsWithValues(o_xpd, 1, o_data);

			i_self.add(a_fields);
		}
	},

	/* ----------------------------------------------------------------------------------------------------
	    Validate and save form
	   ---------------------------------------------------------------------------------------------------- */
	doSave: function(o_options) {

		var i_self = this;
		var o_data = i_self.getData();
		var i_form = i_self.getForm();
		var b_formValid = i_form.isValid();

		var f_success = o_options.success || Ext.emptyFn;
		var f_faliure  = o_options.failure || Ext.emptyFn;

		if (b_formValid) {

			var o_values = i_form.getFieldValues();

			Ext.apply(o_data, o_values);

			f_success();
		}
		else {
			var a_errors = [{
				panel: "general"
			}];
			f_faliure(i_self, a_errors);
		}
	},

	getValue: function() {

		var i_self = this;
		return i_self.getData();
	}

});
