From 7c84301c047e4a05ad8aaf3eea745cde86ec8b37 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 29 Jan 2020 18:18:25 +0100 Subject: [PATCH] admin: implement Enter keypress on search --- admin/static/js/app.js | 48 +++++++++++++++++++++++++++ admin/static/views/exercice-list.html | 2 +- admin/static/views/team-list.html | 2 +- admin/static/views/theme-list.html | 2 +- 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 13df1b7d..98d8e848 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -1284,6 +1284,22 @@ angular.module("FICApp") $scope.themes = Theme.query(); $scope.fields = ["name", "authors", "headline", "path"]; + $scope.validateSearch = function(keyEvent) { + if (keyEvent.which === 13) { + var myTheme = null; + $scope.themes.forEach(function(theme) { + if (String(theme.name.toLowerCase()).indexOf($scope.query.toLowerCase()) >= 0) { + if (myTheme === null) + myTheme = theme; + else + myTheme = false; + } + }); + if (myTheme) + $location.url("themes/" + myTheme.id); + } + }; + $scope.show = function(id) { $location.url("/themes/" + id); }; @@ -1343,6 +1359,22 @@ angular.module("FICApp") $scope.exercice = {}; // Array used to save fields to updates in selected exercices $scope.fields = ["title", "headline"]; + $scope.validateSearch = function(keyEvent) { + if (keyEvent.which === 13) { + var myExercice = null; + $scope.exercices.forEach(function(exercice) { + if (String(exercice.title.toLowerCase()).indexOf($scope.query.toLowerCase()) >= 0) { + if (myExercice === null) + myExercice = exercice; + else + myExercice = false; + } + }); + if (myExercice) + $location.url("exercices/" + myExercice.id); + } + }; + $scope.toggleSelectAll = function() { angular.forEach($filter('filter')($scope.exercices, $scope.query), function(ex) { ex.selected = !$scope.selectall @@ -1833,6 +1865,22 @@ angular.module("FICApp") $scope.teams = Team.query(); $scope.fields = ["id", "name"]; + $scope.validateSearch = function(keyEvent) { + if (keyEvent.which === 13) { + var myTeam = null; + $scope.teams.forEach(function(team) { + if (String(team.name.toLowerCase()).indexOf($scope.query.toLowerCase()) >= 0) { + if (myTeam === null) + myTeam = team; + else + myTeam = false; + } + }); + if (myTeam) + $location.url("teams/" + myTeam.id); + } + }; + $scope.desactiveTeams = function() { $http.post("/api/disableinactiveteams").then(function() { $scope.teams = Team.query(); diff --git a/admin/static/views/exercice-list.html b/admin/static/views/exercice-list.html index 03e7254a..1ef934dc 100644 --- a/admin/static/views/exercice-list.html +++ b/admin/static/views/exercice-list.html @@ -20,7 +20,7 @@
-

+

diff --git a/admin/static/views/team-list.html b/admin/static/views/team-list.html index d1ace909..a6306916 100644 --- a/admin/static/views/team-list.html +++ b/admin/static/views/team-list.html @@ -6,7 +6,7 @@ -

+

diff --git a/admin/static/views/theme-list.html b/admin/static/views/theme-list.html index 241f9166..aed9b4ca 100644 --- a/admin/static/views/theme-list.html +++ b/admin/static/views/theme-list.html @@ -4,7 +4,7 @@ -

+