From ca094449be1fa8146c76b975a9aaa4d60605ac0b Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 3 Apr 2014 18:27:14 +0600 Subject: [PATCH] SONAR-5167 It should be possible to use "Tab" to navigate in the new search forms --- .../navigator/filters/ajax-select-filters.js | 4 +- .../main/js/navigator/filters/base-filters.js | 3 +- .../main/js/navigator/filters/filter-bar.js | 54 +++++++++++++++++++ .../js/navigator/filters/metric-filters.js | 4 +- .../filters/more-criteria-filters.js | 3 +- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/sonar-server/src/main/js/navigator/filters/ajax-select-filters.js b/sonar-server/src/main/js/navigator/filters/ajax-select-filters.js index dd2e246d217..0f6c130e347 100644 --- a/sonar-server/src/main/js/navigator/filters/ajax-select-filters.js +++ b/sonar-server/src/main/js/navigator/filters/ajax-select-filters.js @@ -100,7 +100,7 @@ define(['backbone', 'navigator/filters/base-filters', 'navigator/filters/choice- var that = this, keyup = function(e) { - if (e.keyCode !== 38 && e.keyCode !== 40) { + if (e.keyCode !== 37 && e.keyCode !== 38 && e.keyCode !== 39 && e.keyCode !== 40) { that.search(); } }, @@ -162,7 +162,7 @@ define(['backbone', 'navigator/filters/base-filters', 'navigator/filters/choice- keydown: function(e) { - if (_([37, 38, 39, 40, 13]).indexOf(e.keyCode) !== -1) { + if (_([38, 40, 13]).indexOf(e.keyCode) !== -1) { e.preventDefault(); } }, diff --git a/sonar-server/src/main/js/navigator/filters/base-filters.js b/sonar-server/src/main/js/navigator/filters/base-filters.js index 8699c601f44..09cccd3f8b8 100644 --- a/sonar-server/src/main/js/navigator/filters/base-filters.js +++ b/sonar-server/src/main/js/navigator/filters/base-filters.js @@ -110,11 +110,12 @@ define(['backbone', 'backbone.marionette', 'common/handlebars-extensions'], func toggleDetails: function(e) { e.stopPropagation(); + this.options.filterBarView.selected = this.options.filterBarView.getEnabledFilters().index(this.$el); if (this.$el.hasClass('active')) { key.setScope('list'); this.hideDetails(); } else { - key.setScope('filter'); + key.setScope('filters'); this.showDetails(); } }, diff --git a/sonar-server/src/main/js/navigator/filters/filter-bar.js b/sonar-server/src/main/js/navigator/filters/filter-bar.js index a859c721382..6f98ba5b058 100644 --- a/sonar-server/src/main/js/navigator/filters/filter-bar.js +++ b/sonar-server/src/main/js/navigator/filters/filter-bar.js @@ -39,6 +39,60 @@ define( that.hideDetails(); }); this.addMoreCriteriaFilter(); + + key.filter = function(e) { + var el = jQuery(e.target), + tabbableSet = el.closest('.navigator-filter-details-inner').find(':tabbable'); + return tabbableSet.index(el) >= tabbableSet.length - 1; + }; + key('f', function() { + key.setScope('filters'); + that.selectFirst(); + return false; + }); + key('shift+tab', 'filters', function() { + that.selectPrev(); + return false; + }); + key('tab', 'filters', function() { + that.selectNext(); + return false; + }); + }, + + + getEnabledFilters: function() { + return this.$(this.itemViewContainer).children() + .not('.navigator-filter-disabled') + .not('.navigator-filter-inactive') + .not('.navigator-filter-favorite'); + }, + + + selectFirst: function() { + this.selected = -1; + this.selectNext(); + }, + + + selectPrev: function() { + var filters = this.getEnabledFilters(); + if (this.selected > 0) { + this.selected--; + filters.eq(this.selected).click(); + } + }, + + + selectNext: function() { + var filters = this.getEnabledFilters(); + if (this.selected < filters.length - 1) { + this.selected++; + filters.eq(this.selected).click(); + } else { + this.hideDetails(); + this.$('.navigator-filter-submit').focus(); + } }, diff --git a/sonar-server/src/main/js/navigator/filters/metric-filters.js b/sonar-server/src/main/js/navigator/filters/metric-filters.js index f680d0e06e1..cac789dc4aa 100644 --- a/sonar-server/src/main/js/navigator/filters/metric-filters.js +++ b/sonar-server/src/main/js/navigator/filters/metric-filters.js @@ -66,9 +66,7 @@ define(['navigator/filters/base-filters', 'common/handlebars-extensions'], funct onShow: function() { var select = this.$('[name=metric]'); - if (!select.val()) { - select.select2('open'); - } + select.select2('open'); } }); diff --git a/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js b/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js index 755c4bbfb42..a1b2887ebf1 100644 --- a/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js +++ b/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js @@ -1,6 +1,6 @@ define(['navigator/filters/base-filters', 'navigator/filters/choice-filters', 'common/handlebars-extensions'], function (BaseFilters, ChoiceFilters) { - var DetailsMoreCriteriaFilterView = BaseFilters.DetailsFilterView.extend({ + var DetailsMoreCriteriaFilterView = ChoiceFilters.DetailsChoiceFilterView.extend({ template: getTemplate('#more-criteria-details-filter-template'), @@ -13,6 +13,7 @@ define(['navigator/filters/base-filters', 'navigator/filters/choice-filters', 'c var id = $j(e.target).data('id'); this.model.view.options.filterBarView.enableFilter(id); this.model.view.hideDetails(); + this.updateCurrent(0); }, -- 2.39.5