From d72e8f67df39b85792adffc67d370561e1db524a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 29 Feb 2012 18:51:36 +0000 Subject: [PATCH] avoid duplicated code and use more generic solution for filtering git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1295211 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/webapp/js/archiva/search.js | 61 ++++++------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js index a8de514c6..16d10f082 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js @@ -734,49 +734,9 @@ $(function() { "simpleGrid: gridViewModel,simpleGridTemplate:'search-results-view-grid-tmpl',pageLinksId:'search-results-view-grid-pagination'"); ko.applyBindings(self.resultViewModel,searchResultsGrid.get(0)); } - // FIXME something generic here ! - - $( "#main-content #search-filter-auto-groupId" ).autocomplete({ - minLength: 1, - source: function(request, response){ - var groupIds=[]; - $(self.resultViewModel.artifacts()).each(function(idx,artifact){ - if(artifact.groupId.startsWith(request.term)){ - groupIds.push(artifact.groupId); - } - }); - response(unifyArray(groupIds,true)); - } - }); - - $( "#main-content #search-filter-auto-artifactId" ).autocomplete({ - minLength: 1, - source: function(request, response){ - var artifactIds=[]; - $(self.resultViewModel.artifacts()).each(function(idx,artifact){ - if(artifact.artifactId.startsWith(request.term)){ - artifactIds.push(artifact.artifactId); - } - }); - response(unifyArray(artifactIds,true)); - } - }); - - $( "#main-content #search-filter-auto-version" ).autocomplete({ - minLength: 1, - source: function(request, response){ - var versions=[]; - $(self.resultViewModel.artifacts()).each(function(idx,artifact){ - if(artifact.version.startsWith(request.term)){ - versions.push(artifact.version); - } - }); - response(unifyArray(versions,true)); - } - }); - - - + applyAutocompleteOnHeader('groupId'); + applyAutocompleteOnHeader('artifactId'); + applyAutocompleteOnHeader('version'); activateSearchResultsTab(); } }, @@ -793,6 +753,21 @@ $(function() { ); } + applyAutocompleteOnHeader=function(property){ + $( "#main-content #search-filter-auto-"+property ).autocomplete({ + minLength: 1, + source: function(request, response){ + var founds=[]; + $(self.resultViewModel.artifacts()).each(function(idx,artifact){ + if(artifact[property].startsWith(request.term)){ + founds.push(artifact[property]); + } + }); + response(unifyArray(founds,true)); + } + }); + } + // olamy not used as we cannot filter on className etc... filterResults=function(){ var filtered=[]; -- 2.39.5