Ext.define("IceCap2.ux.form.field.sqlComboBox", {


	xtype: "DDSQL",

	extend: "Ext.form.field.ComboBox",

	minChars : 1,

	valueField: "KEY",

	displayField:"VALUE",

	typeAhead: true,

	mode: "remote",


	triggerAction: "all",

	selectOnFocus:true,

	editable: true,

	config: {
		sqlVoucher: ""
	},

	initComponent:function() {

		var i_self = this;
		var i_store = i_self.createStore();

	    if (i_self.getRawValue() && i_self.getValue()) {
	    	var i_record  = i_store.getModel().create({
	    		KEY: i_self.getValue(),
	    		VALUE: i_self.getRawValue()
	    	});
	    	i_store.add(i_record);
	    }

	    i_self.store = i_store;
	    i_self.callParent();
	},

	createStore: function() {

		var i_self = this;

		var i_store = Ext.create("Ext.data.Store", {
			fields: [
				{
					name: "KEY",
					type: "auto"
				},
				{
					name: "VALUE",
					type: "auto"
				}
			],
			proxy: {
				url: "/menu/DDSQL.aspx?runSql=runsql&sqlVoucher=" + i_self.getSqlVoucher(),
				type: "ajax",
				reader: {
					type: "json",
				}
			}
		});

		return i_store;
	}
});
