Ext.define('Ext.ux.form.field.PrePostTextField', {
	extend: 'Ext.form.field.Text',
	alias: 'widget.preposttextfield',

	initComponent: function() {

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

	onPreLoad: function(n_value) {
		var i_self = this;
		var o_preConfig = i_self.preConfig || {};

		var o_params = {};

		o_params[o_preConfig.token] = n_value;
		o_params.action = o_preConfig.action;

		Ext.Ajax.request({
			url: o_preConfig.url,
			params: o_params,
			success: function (o_response) {

				var o_result = JSON.parse(o_response.responseText);
				if (o_result.success && o_result[o_preConfig.property] != i_self.getValue()) {
					i_self.suspendCheckChange++;
					i_self.setValue(o_result[o_preConfig.property]);
					i_self.resetOriginalValue();
					i_self.suspendCheckChange--;
				}
			}
		});
	},

	onPostSave: function(n_value, f_callback) {
		var i_self = this;
		var s_value = i_self.getValue();
		var o_postConfig = i_self.postConfig || {};

		var o_params = {};

		o_params[o_postConfig.token] = n_value;
		o_params[o_postConfig.property] = s_value;
		o_params.action = o_postConfig.action;

		Ext.Ajax.request({
			url: o_postConfig.url,
			params: o_params,
			success: function (o_response) {

				f_callback();
			}
		});
	}
});
