Ext.define("IceCap.ux.form.field.FileLibraryDependency", {

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

	alias: [
		"widget.FileLibraryDependency"
	],

	valueField: "obj",
	displayField: "txt",
	fieldLabel: "File",

	typeAhead: true,

	mode: "remote",

	triggerAction: "all",

	selectOnFocus: true,

	matchFieldWidth: false,

	editable: true,

	config: {
		lib: "qtemp",
		obj: "*all",
		typ: "*all",
		atr: "*all"
	},

	initComponent: function() {

		var i_self = this;
		i_self.tpl = i_self.createTemplate();

		var i_store = Ext.create("Ext.data.Store", {
			params: {
				lib: i_self.getLib(),
				obj: i_self.getObj(),
				typ: i_self.getTyp(),
				atr: i_self.getAtr()
			},
			proxy: {
				url: "/icecap/ddlibs.aspx?func=getRows",
				type: "ajax",
				reader: {
					type: "json"
				}
			},
			fields: [
				{
					name: "obj",
					type: "auto"
				},
				{
					name: "txt",
					type: "auto"
				}
			],
			autoLoad: true
		});

		i_self.store = i_store;

		i_self.callParent();
	},

	createTemplate: function() {

		var i_template = new Ext.XTemplate(
			"<tpl for=\".\">",
				"<li role=\"option\" class=\"x-boundlist-item\" style=\"text-overflow: ellipsis; white-space: nowrap; overflow:hidden;\">",
					"<b>{key} - </b> {value}",
				"</li>",
			"</tpl>"
		);

		return i_template;
	}
})
