Commit 539e2034 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add getDropdown() method to Search controller.

To avoid using Ext.getCmp() all over the place.
parent f2cbffb8
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ Ext.define('Docs.controller.Search', {
            },
            '#search-field': {
                keyup: function(el, ev) {
                    var dropdown = Ext.getCmp('search-dropdown');
                    var dropdown = this.getDropdown();

                    if (ev.keyCode === Ext.EventObject.ESC || !el.value) {
                        dropdown.hide();
@@ -57,18 +57,21 @@ Ext.define('Docs.controller.Search', {
                    }
                },
                focus: function(el) {
                    var dropdown = Ext.getCmp('search-dropdown');
                    if (el.value && dropdown.store.getCount() > 0) {
                        dropdown.show();
                    if (el.value && this.getDropdown().store.getCount() > 0) {
                        this.getDropdown().show();
                    }
                },
                blur: function() {
                    Ext.getCmp('search-dropdown').hide();
                    this.getDropdown().hide();
                }
            }
        });
    },

    getDropdown: function() {
        return this.dropdown || (this.dropdown = Ext.getCmp('search-dropdown'));
    },

    // loads class/method corrseponding to the record
    loadRecord: function(record) {
        var name = record.get("cls");
@@ -76,7 +79,7 @@ Ext.define('Docs.controller.Search', {
            name += '-' + record.get("type") + '-' + record.get("member");
        }
        Docs.App.getController('Classes').loadClass(name);
        Ext.getCmp('search-dropdown').hide();
        this.getDropdown().hide();
    },

    search: function(term) {
@@ -84,11 +87,10 @@ Ext.define('Docs.controller.Search', {
        var results = this.filterMembers(term);
        Docs.App.getStore('Search').loadData(results, false);
        // position dropdown below search box
        var dropdown = Ext.getCmp('search-dropdown');
        dropdown.alignTo('search-field', 'bl', [-23, 2]);
        this.getDropdown().alignTo('search-field', 'bl', [-23, 2]);
        // hide dropdown when nothing found
        if (results.length === 0) {
            dropdown.hide();
            this.getDropdown().hide();
        }
    },