From a433e0e79c10a74264b0d456f5596ef7c5092180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 28 May 2015 11:39:08 +0200 Subject: [PATCH] More work on variable dropdown --- public/app/directives/variableValueSelect.js | 27 +++++++++++++++----- public/app/features/templating/editorCtrl.js | 1 + 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/public/app/directives/variableValueSelect.js b/public/app/directives/variableValueSelect.js index 42724a79df9..43c1014160e 100644 --- a/public/app/directives/variableValueSelect.js +++ b/public/app/directives/variableValueSelect.js @@ -115,7 +115,10 @@ function (angular, app, _) { scope.moveHighlight(-1); } if (evt.keyCode === 13) { - scope.optionSelected(scope.search.options[scope.highlightIndex], {}); + scope.optionSelected(scope.search.options[scope.highlightIndex], {}, true, false); + } + if (evt.keyCode === 32) { + scope.optionSelected(scope.search.options[scope.highlightIndex], {}, false, false); } }; @@ -123,24 +126,34 @@ function (angular, app, _) { scope.highlightIndex = (scope.highlightIndex + direction) % scope.search.options.length; }; - scope.optionSelected = function(option, event) { + scope.optionSelected = function(option, event, commitChange, excludeOthers) { + if (!option) { return; } + option.selected = !option.selected; - var hideAfter = false; + commitChange = commitChange || false; + excludeOthers = excludeOthers || false; + var setAllExceptCurrentTo = function(newValue) { _.each(scope.options, function(other) { if (option !== other) { other.selected = newValue; } }); }; - if (option.text === 'All') { + // commit action (enter key), should not deselect it + if (commitChange) { + option.selected = true; + } + + if (option.text === 'All' || excludeOthers) { setAllExceptCurrentTo(false); + commitChange = true; } else if (!variable.multi) { setAllExceptCurrentTo(false); - hideAfter = true; + commitChange = true; } else if (event.ctrlKey || event.metaKey || event.shiftKey) { - hideAfter = true; + commitChange = true; setAllExceptCurrentTo(false); } @@ -168,7 +181,7 @@ function (angular, app, _) { variable.current.value = selected[0].value; } - if (hideAfter) { + if (commitChange) { scope.switchToLink(); } }; diff --git a/public/app/features/templating/editorCtrl.js b/public/app/features/templating/editorCtrl.js index f48452e4569..aeb27b3c832 100644 --- a/public/app/features/templating/editorCtrl.js +++ b/public/app/features/templating/editorCtrl.js @@ -82,6 +82,7 @@ function (angular, _) { }; $scope.update = function() { + $scope.current.tags = []; if ($scope.isValid()) { $scope.runQuery().then(function() { $scope.reset();