]> source.dussan.org Git - archiva.git/commitdiff
avoid duplicated code and use more generic solution for filtering
authorOlivier Lamy <olamy@apache.org>
Wed, 29 Feb 2012 18:51:36 +0000 (18:51 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 29 Feb 2012 18:51:36 +0000 (18:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1295211 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js

index a8de514c6cfa89e63d4e8f01d170c2c51db93ad9..16d10f082ba26ea5c229c36de9d9bcc65dce4ae4 100644 (file)
@@ -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=[];