From a6b2122ef6f61ac78502cd892a372cb75965a9f5 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 3 Sep 2011 14:59:15 +0200 Subject: [PATCH] improve repository search --- .../js/repository/sonia.repository.grid.js | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js index 1a759ba8ff..b699503737 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js @@ -39,6 +39,8 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { colUrlText: 'Url', emptyText: 'No repository is configured', formTitleText: 'Repository Form', + + searchValue: null, initComponent: function(){ @@ -51,6 +53,12 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { fields: [ 'id', 'name', 'type', 'contact', 'description', 'creationDate', 'url', 'public', 'permissions', 'properties' ], sortInfo: { field: 'name' + }, + listeners: { + load: { + fn: this.storeLoad, + scope: this + } } }); @@ -86,6 +94,12 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.repository.Grid.superclass.initComponent.apply(this, arguments); }, + + storeLoad: function(store){ + if (this.searchValue){ + this.searchStore(store); + } + }, onFallBelowMinHeight: function(height, minHeight){ var p = Ext.getCmp('repositoryEditPanel'); @@ -99,8 +113,18 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { }, search: function(value){ - value = value.toLowerCase(); - this.getStore().filterBy(function(rec){ + this.searchValue = value; + var store = this.getStore(); + if ( ! value ){ + store.clearFilter(); + } else { + this.searchStore(store); + } + }, + + searchStore: function(store){ + var value = this.searchValue.toLowerCase(); + store.filterBy(function(rec){ return ! value || rec.get('name').toLowerCase().indexOf(value) >= 0 || rec.get('description').toLowerCase().indexOf(value) >= 0;