/* results-filters
 
@author Jacob at Goby
 @version 09/02/11
@svn goby_-150
*/

ResultFilter.KeywordFilter=function(module,resultSet){this.__run(module,resultSet)}
ResultFilter.KeywordFilter.prototype=Class({_construct:function(module,resultSet)
{if(resultSet==null)
return false;if(!module)
{var module={method:"keyword",type:"keyword",label:"keywords",field:"keyword",queryFormat:queryFormat.EWIG}}
this.resultSet=resultSet;for(i in module)
this[i]=module[i];objects.push(this);this.init();},inherits:ResultFilter.Result,vars:{field:'keyword'},methods:{init:function()
{this.form=new KeywordForm({values:{'keyword':this.value}},this);this.form.resultSet=this.resultSet;this.form.display();return this.form;},display:function()
{$(this.resultSet.getFilterContainer(this)).append(this.form);},filterResult:function(result)
{var matchCnt=result.getKeywordRelevance(this.value);return(matchCnt>0?true:false);},clearFilter:function(fromResult)
{this.setValues(false);this.resetInputs();if(!fromResult)
{this.resultSet.clearFilters(this.getLabel());return this.resultSet.getBookmark();}},filterResults:function(results)
{var currentResults=[];for(var index in results)
{var result=results[index];if(this.filterResult(result))
currentResults.push(result);}
return currentResults;},resetInputs:function(fromResult)
{this.form.updateField('keyword','');this.setValues('');},updateFilter:function(values)
{try{this.form.updateField('keyword',values);}
catch(e){Goby.reportError(e);}
this.setValues(values);},applyToResults:function()
{if(!this.getValue())
this.resultSet.clearFilter(this);else
this.resultSet.applyFilter(this);},select:function(){this.applyToResults();}}});function KeywordForm(params,admin)
{if(params==null)
return null;this.title=admin.getLabel();this.fields={'keyword':new PrettyField({label:"",name:"keyword",v:'[all:1]',default_value:"keyword filter..."})};this.fields.keyword.callback_delete={object:admin,method:"clearFilter"}
this.button={};var node=this._construct(params,admin);node.id="keywordFilter";return node;}
KeywordForm.prototype=new GrilleForm(null);KeywordForm.prototype.gaID="keyword-form";KeywordForm.prototype.title="Keyword";KeywordForm.prototype.id="keywordFilter";KeywordForm.prototype.updateField=function(name,value)
{this.fields[name].setValue(value);}
KeywordForm.prototype.submit=function(data)
{if(data==null)
return false;this.admin.setValues(this.fields.keyword.getValue());this.admin.setParameters();trackEvent(["sort_box","keyword"]);this.admin.applyToResults();return false;}
KeywordForm.prototype.ende=function(data){}
KeywordForm.prototype.close=function(){}
