2012-05-09 18 views
1

ファイル&を検索して結果を返すsearch.jsファイル(大きなスクリプトの一部)があります。これらの検索結果をJavaScriptでフィルタリングするにはどうすればよいですか?

「不要」を含むファイル名またはパスが表示されないように検索結果をフィルタリングしようとしています。

これはそれの全体がsearch.jsファイルです。

FR = { 
    UI: {translations:[]} 
}; 

function setLookInValue() { 
    var path = window.parent.FR.searching.path.replace('/ROOT/HOME', ''); 
    lookin.setValue(path ? path : '/'); 
    FR.grid.getStore().removeAll(); 
} 

Ext.onReady(function() { 
    window.parent.Ext.get(window.parent.FR.UI.searchPopup.getLayout().container.body.dom).unmask(); 
metadataField = new Ext.form.ComboBox({ 
    fieldLabel: FR.T('Metadata Field'), 
    autoCreate:true, mode: 'local', 
    emptyText:FR.T('Select...'), 
    displayField:'filetype', 
    valueField:'id', name: 'metadata_field_id', hiddenName:'metadata_field_id', 
    editable: false, triggerAction:'all', disableKeyFilter: true, 
    forceSelection:true, value:0, width:130, 
    store: new Ext.data.SimpleStore({ 
     fields: ['id', 'filetype'], 
     data: FR.metadataFields 
    }) 
}); 
metadataValue = new Ext.form.TextField({ 
    fieldLabel: FR.T('Metadata'), name: 'metadata_value', width: 130, value: '' 
}); 
FR.rightColumnFields = []; 
if (window.parent.User.perms.metadata) { 
    FR.rightColumnFields.push(metadataField); 
    FR.rightColumnFields.push(metadataValue); 
} 
FR.rightColumnFields.push(new Ext.Button({ 
    text: FR.T('Search'), 
    style: (!window.parent.User.perms.metadata ? '' : 'margin-left:98px'), 
    handler: function(){ 
     ds.load({ 
      params:{ 
       filename: Ext.getCmp('filename').getValue(), 
       keyword: Ext.getCmp('keyword').getValue(), 
       metafield: metadataField.getValue(), 
       metavalue: metadataValue.getValue(), 
       path: encodeURIComponent(window.parent.FR.searching.path) 
      } 
     }); 
    } 
})); 

FR.form = new Ext.form.FormPanel({ 
    labelAlign: 'right', 
    labelWidth: 90, 
    border: false, 
    hideBorders: true, 
    bodyBorder: false, 
    bodyStyle: 'padding:5px', 
    items: [{ 
     layout:'column', 
     items: [{ 
      columnWidth:.5, 
      layout: 'form', 
      border: false, bodyBorder: false, 
      items: [{ 
       id: 'filename', xtype:'textfield', 
       fieldLabel: FR.T('File name'), 
       name: 'file_name', width: 130, value: '' 
      }, 
      { 
       id: 'keyword', xtype:'textfield', 
       fieldLabel: FR.T('File contents'), 
       name: 'file_contents', 
       width: 130, value: '', 
       disabled: !window.parent.Settings.fullTextSearch 
      }, 
      lookin = new Ext.form.TextField({ 
       fieldLabel: FR.T('Look in'), 
       name: 'lookin', width: 130, value: '', readOnly: true 
      }) 
      ] 
     },{ 
      columnWidth:.5, 
      id: 'secondCol', 
      layout: 'form', 
      border: false, 
      bodyBorder: false, 
      items: FR.rightColumnFields 
     }] 
    }] 
}); 

var ds = new Ext.data.Store({ 
    proxy: new Ext.data.HttpProxy({ 
     url: URLRoot+'/?module=search&section=ajax&page=search' 
    }), 
    reader: new Ext.data.JsonReader({ 
      root: 'files', 
      totalProperty: 'totalCount', 
      id: 'id' 
     }, 
     [ 
      {name: 'icon'}, 
      {name: 'id'}, 
      {name: 'filename'}, 
      {name: 'path'}, 
      {name: 'technical_path'}, 
      {name: 'score', type: 'float'} 
     ] 
    ) 
}); 

var cm = new Ext.grid.ColumnModel({ 
    defaults: {sortable: true}, 
    columns: [ 
     {id: 'filename', header: FR.T("File name"), dataIndex: 'filename', width: 160, 
      renderer: function (value, p, record) { 
       return '<img src="'+URLRoot+'/images/fileman/file_icons/small/'+record.data.icon+'" width="16" height="16" align="absmiddle"> '+value; 
      } 
     }, 
     {id: 'path', header: FR.T("Path"), dataIndex: 'path'} 
    ] 
}); 
cm.defaultSortable = true; 

grid = new Ext.grid.GridPanel({ 
    ds: ds, 
    cm: cm, 
    border: false, bodyBorder: false, hideBorders: true, 
    selModel: new Ext.grid.RowSelectionModel({singleSelect:true}), 
    loadMask: {msg: FR.T('Searching...')}, 
    enableColumnHide: false, 
    enableColumnMove: false, 
    autoExpandColumn: 'path', 
    selModel: new Ext.grid.RowSelectionModel({singleSelect:true}) 
}); 

grid.on('rowclick', function (grid, rowIndex, e){ 
    var rowData = grid.getStore().data.items[rowIndex].data; 
    var path = rowData.technical_path; 
    var filename = rowData.filename; 
    if (window.parent.FR.currentPath != path) { 
     window.parent.FR.UI.tree.panel.selectPath(path, 'pathname', function() { 
      window.parent.FR.UI.grid.highlightOnDisplay = filename; 
     }); 
    } else { 
     window.parent.FR.UI.grid.highlight(filename); 
    } 
}); 

grid.on('rowcontextmenu', function(grid, rowIndex, e) {e.stopEvent();return false;}) 
FR.grid = grid; 

new Ext.Viewport({ 
    layout: 'border', 
    hideBorders: true, 
    items: [ 
     { 
      region: 'north', layout: 'fit', split: true, height:100, 
      hideBorders: true, bodyBorder: false, border: false, 
      items: [FR.form] 
     }, 
     { 
      region: 'center', layout: 'fit', autoHeigh: true, 
      items: grid 
     } 
    ] 
}); 
setLookInValue(); 
}); 

私はかなり迷ってしまいました。誰に私はこれらの検索結果をフィルタリングするのに役立つ十分な情報を与えるだろう、このJavaScriptで何があります

if (someVar.indexOf("unwanted") == -1) { ... 

:私は、私のような何かを行うことができ、コードのどこかで思いましたか?

+4

これはかなりのコードです。最も重要な部分にカットしてみてください。 –

答えて

0

これはExt JSを使用するコードのように見え、それに応じてタグを追加しました。ドキュメントをちょっと覗いてみると、Ext.data.Storeページの[フィルタリングと並べ替え]セクションが適切なトラックに表示されます。

+0

ありがとうございます。私はその部分を自分自身で見ていましたが、参照される外部ページだけがzendエンコードされていて、開発者からサポートを受けることができなかったので、このjsファイルの結果をフィルタリングする方法を見つけようとしています。 – JROB

関連する問題