partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 2f6e9939eadaeca9f766769d3910f3fac39e231d
parent 2823749dfa7894ce1f625bede7b5781499775470
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 14 Nov 2015 17:40:09 +0100

Added typeAhead documentation

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/StorageLocationPicker.js | 45+++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/StorageLocationPicker.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/StorageLocationPicker.js @@ -2,6 +2,23 @@ Ext.define("PartKeepr.StorageLocationPicker", { extend: "Ext.form.field.Picker", alias: 'widget.StorageLocationPicker', + /** + * @cfg {Number} typeAheadDelay + * The length of time in milliseconds to wait until the typeahead function is called + */ + typeAheadDelay: 250, + + /** + * @var {Ext.util.DelayedTask} typeAheadTask + * The internal task for the typeAhead delay + */ + typeAheadTask: null, + + /** + * @var {PartKeepr.StorageLocationBundle.Entity.StorageLocation} selectedStorageLocation + * The selected storage location + */ + selectedStorageLocation: null, initComponent: function () { @@ -22,10 +39,38 @@ Ext.define("PartKeepr.StorageLocationPicker", { groupField: 'categoryPath' }); + this.on("change", Ext.bind(this.onFieldChange, this)); + this.on("blur", Ext.bind(this.onBlur, this)); this.callParent(); }, + onFieldChange: function (f, newValue) { + if (this.selectedStorageLocation instanceof PartKeepr.StorageLocationBundle.Entity.StorageLocation) { + if (this.selectedStorageLocation.get("name") === newValue) { + return; + } + } + if (!this.typeAheadTask) { + this.typeAheadTask = new Ext.util.DelayedTask(this.onTypeAhead, this, [newValue]); + } + this.typeAheadTask.delay(this.typeAheadDelay, false, false, [newValue]); + }, + getValue: function () { + return this.selectedStorageLocation; + }, + onTypeAhead: function (newValue) { + var picker = this.getPicker(newValue); + picker.setSearchValue(newValue); + this.expand(); + }, + onBlur: function () { + var picker = this.getPicker(); + + if (picker.getGrid().getStore().count() === 1) { + this.setValue(picker.getGrid().getStore().getAt(0)); + } + }, setValue: function (value) { this.selectedStorageLocation = value; PartKeepr.StorageLocationPicker.superclass.setValue.call(this, value.get("name"));