diff --git a/apps/common/main/lib/component/ComboBox.js b/apps/common/main/lib/component/ComboBox.js index 098c66e5c..8b24e3caf 100644 --- a/apps/common/main/lib/component/ComboBox.js +++ b/apps/common/main/lib/component/ComboBox.js @@ -85,6 +85,7 @@ define([ menuStyle : '', displayField: 'displayValue', valueField : 'value', + search : false, scrollAlwaysVisible: false }, @@ -119,6 +120,7 @@ define([ this.store = me.options.store || new Common.UI.ComboBoxStore(); this.displayField = me.options.displayField; this.valueField = me.options.valueField; + this.search = me.options.search; this.scrollAlwaysVisible = me.options.scrollAlwaysVisible; me.rendered = me.options.rendered || false; @@ -295,12 +297,14 @@ define([ if (itemTop < 0 || itemTop + itemHeight > listHeight) { $list.scrollTop($list.scrollTop() + itemTop + itemHeight - (listHeight/2)); } + setTimeout(function(){$selected.find('a').focus();}, 1); } if (this.scroller) this.scroller.update({alwaysVisibleY: this.scrollAlwaysVisible}); this.trigger('show:after', this, e); + this._search = {}; }, onBeforeHideMenu: function(e) { @@ -332,6 +336,57 @@ define([ this.closeMenu(); this.onAfterHideMenu(e); return false; + } else if (this.search && e.keyCode > 64 && e.keyCode < 91 && e.key){ + var me = this; + clearTimeout(this._search.timer); + this._search.timer = setTimeout(function () { me._search = {}; }, 1000); + + (!this._search.text) && (this._search.text = ''); + (!this._search.char) && (this._search.char = e.key); + (this._search.char !== e.key) && (this._search.full = true); + this._search.text += e.key; + if (this._search.index===undefined) { + var $items = this.cmpEl.find('ul > li').find('> a'); + this._search.index = $items.index($items.filter(':focus')); + } + this.selectCandidate(); + } + }, + + selectCandidate: function() { + var index = this._search.index || 0, + re = new RegExp('^' + ((this._search.full) ? this._search.text : this._search.char), 'i'), + itemCandidate, idxCandidate; + + for (var i=0; iindex) { + itemCandidate = item; + idxCandidate = i; + break; + } + } + } + + if (itemCandidate) { + this._search.index = idxCandidate; + var item = $('#' + itemCandidate.get('id') + ' a', $(this.el)); + if (this.scroller) { + this.scroller.update({alwaysVisibleY: this.scrollAlwaysVisible}); + var $list = $(this.el).find('ul'); + var itemTop = item.position().top, + itemHeight = item.height(), + listHeight = $list.height(); + if (itemTop < 0 || itemTop + itemHeight > listHeight) { + $list.scrollTop($list.scrollTop() + itemTop + itemHeight - (listHeight/2)); + } + } + item.focus(); } }, diff --git a/apps/common/main/lib/view/LanguageDialog.js b/apps/common/main/lib/view/LanguageDialog.js index 4ce51edc7..123e38dcb 100644 --- a/apps/common/main/lib/view/LanguageDialog.js +++ b/apps/common/main/lib/view/LanguageDialog.js @@ -104,7 +104,8 @@ define([ '', '' ].join('')), - data: this.options.languages + data: this.options.languages, + search: true }); if (this.cmbLanguage.scroller) this.cmbLanguage.scroller.update({alwaysVisibleY: true});