close on outside click and escape

This commit is contained in:
Mads Rasmussen
2018-09-19 16:01:12 +02:00
parent ff6509be34
commit b2fa7ea475
4 changed files with 15 additions and 10 deletions

View File

@@ -20,14 +20,12 @@
vm.$onInit = onInit;
vm.$onDestroy = onDestroy;
vm.search = search;
vm.handleKeyUp = handleKeyUp;
vm.closeSearch = closeSearch;
function onInit() {
vm.searchResults = [];
vm.hasResults = false;
console.log("init search thingy");
backdropService.open();
}
@@ -35,6 +33,13 @@
backdropService.close();
}
function handleKeyUp(event) {
// esc
if(event.keyCode === 27) {
closeSearch();
}
}
/**
* Used to proxy a callback
*/
@@ -49,11 +54,9 @@
* @param {string} searchQuery
*/
function search(searchQuery) {
console.log(searchQuery);
if(searchQuery.length > 0) {
var search = {"term": searchQuery};
searchService.searchAll(search).then(function(result){
//result is a dictionary of group Title and it's results
var filtered = {};
_.each(result, function (value, key) {
@@ -61,12 +64,10 @@
filtered[key] = value;
}
});
// bind to view model
vm.searchResults = filtered;
// check if search has results
vm.hasResults = Object.keys(vm.searchResults).length > 0;
console.log("results", vm.searchResults);
console.log("has results", vm.hasResults);
});
} else {

View File

@@ -43,6 +43,10 @@ function MainController($scope, $location, appState, treeService, notificationsS
eventsService.emit("app.closeDialogs", event);
};
$scope.closeSearch = function() {
appState.setSearchState("show", false);
};
var evts = [];
//when a user logs out or timesout

View File

@@ -1,5 +1,5 @@
<div class="umb-search" on-outside-click="vm.closeSearch()">
<div class="umb-search" on-outside-click="vm.closeSearch()" ng-keyup="vm.handleKeyUp($event)">
<div class="flex items-center">
<i class="umb-search-input-icon icon-search"></i>