1 /**
  2  * @author Gillis Haasnoot <gillis.haasnoot@gmail.com>
  3  * @package Banana.Controls
  4  * @summary BaseDataGridFilter 
  5  */
  6 
  7 goog.provide('Banana.Controls.BaseDataGridFilter');
  8 
  9 /** @namespace Banana.Controls.BaseDataGridFilter */
 10 namespace('Banana.Controls').BaseDataGridFilter = Banana.Controls.Panel.extend(
 11 /** @lends Banana.Controls.BaseDataGridFilter.prototype */		
 12 {
 13 	
 14 	/**
 15 	 * Base class for datagrid list filters.
 16 	 * Filters are not filtering data inside of Banana. They should be used as reference material
 17 	 * for your own implementations. for more info see {@link Banana.Controls.DataGridFilterManager}
 18 	 * 
 19 	 * @constructs
 20 	 * @extends Banana.Controls.Panel
 21 	 */
 22 	init : function()
 23 	{
 24 		this._super();
 25 		this.addCssClass("BDataGridFilter")
 26 		this.allKey = '%';
 27 		this.allTitle = null;
 28 	},
 29 	
 30 	/**
 31 	 * Sets datasource on the filter
 32 	 * 
 33 	 * @param {Object} datasource
 34 	 * @param {boolean} ignoreEvent
 35 	 */
 36 	setDataSource : function(datasource,ignoreEvent)
 37 	{
 38 		var newds = {};
 39 
 40 		newds[this.allKey] = this.allTitle || 'All '+this.filterField;
 41 		for (var prop in datasource)
 42 		{
 43 			if (typeof(datasource[prop]) == 'function') continue;
 44 			
 45 			newds[prop] = datasource[prop];
 46 		}
 47 		
 48 		datasource = newds
 49 
 50 		this._super(newds,ignoreEvent)
 51 		return this;
 52 	},	
 53 	
 54 	/**
 55 	 * Sets data on the filter
 56 	 * @param {mixed} data
 57 	 * @return {this}
 58 	 */
 59 	setData : function(data)
 60 	{
 61 		this.data = data;
 62 		return this;
 63 	},
 64 
 65 	/**
 66 	 * gets data from the filter
 67 	 * @return {mixed}
 68 	 */
 69 	getData : function()
 70 	{
 71 		return this.data;
 72 	}
 73 });
 74 
 75 
 76 
 77 /**
 78  * Sets all title on the filter. This all title use most of the time used as a filter value 
 79  * represending all values inside.
 80  * 
 81  * @param {String} title
 82  * @param {String} key
 83  */
 84 Banana.Controls.BaseDataGridFilter.prototype.setAllTitle = function(title,key)
 85 {
 86 	this.allTitle = title;
 87 	
 88 	if (key)
 89 	{
 90 		this.allKey = key;
 91 	}
 92 	
 93 	return this;
 94 };
 95 
 96 /**
 97  * Sets field to filter on
 98  * @param {String} ff
 99  * @return {this}
100  */
101 Banana.Controls.BaseDataGridFilter.prototype.setFilterField = function(ff)
102 {
103 	this.filterField = ff;
104 	return this;
105 };
106 
107 /**
108  * @return {String}
109  */
110 Banana.Controls.BaseDataGridFilter.prototype.getFilterfield = function()
111 {
112 	return this.filterField;
113 };
114 
115 /**
116  * Sets name of the filter
117  * @param {String} n
118  * @return {this}
119  */
120 Banana.Controls.BaseDataGridFilter.prototype.setName = function(n)
121 {
122 	this.name = n;
123 	return this;
124 };