1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary DataGridControlPanel 5 */ 6 7 goog.provide('Banana.Controls.DataGridControlPanel'); 8 9 goog.require('Banana.Controls.DataGridFilterManager'); 10 11 /** @namespace Banana.Controls.DataGridControlPanel */ 12 namespace('Banana.Controls').DataGridControlPanel = Banana.Control.extend( 13 /** @lends Banana.Controls.DataGridControlPanel.prototype */ 14 { 15 16 /** 17 * Creates control panel for datagrid. 18 * A control panel holds filters, pagers and search controls. It places them automatically 19 * at predefined places. 20 * @constructs 21 * @extends Banana.Control 22 */ 23 init : function() 24 { 25 this._super(); 26 this.createLayout(); 27 this.buttons = []; 28 this.topButtons = []; 29 }, 30 31 /** 32 * @ignore 33 */ 34 updateDisplay : function() 35 { 36 this.top.setVisible(this.top.controls.length); 37 this.middle.setVisible(this.middle.controls.length); 38 this.bottom.setVisible(this.bottom.controls.length-1); //-1 to compensate the arrow 39 }, 40 41 /** 42 * Sets array of filters 43 * @param {Array} filters 44 */ 45 setFilters : function(filters) 46 { 47 for (var i=0,len = filters.length; i < len; i++) 48 { 49 if (filters[i] instanceof Banana.Controls.DataGridPagerFilter) 50 { 51 this.setPagerFilter(filters[i]); 52 } 53 else if (filters[i] instanceof Banana.Controls.DataGridDropDownFilter) 54 { 55 this.setDropDownFilter(filters[i]); 56 } 57 else if (filters[i] instanceof Banana.Controls.DataGridSearchFilter) 58 { 59 this.setSearchFilter(filters[i]); 60 } 61 else if (filters[i] instanceof Banana.Controls.DataGridDateFilter) 62 { 63 this.setDateFilter(filters[i]); 64 } 65 else if (filters[i] instanceof Banana.Controls.DataGridCheckboxFilter) 66 { 67 this.setCheckboxFilter(filters[i]); 68 } 69 else 70 { 71 log.error('Filter ' + filters[i] + ' not supported by datagrid control panel!'); 72 } 73 } 74 }, 75 76 /** 77 * sets the search filter 78 * @param {Banana.Controls.DataGridSearchFilter} filter 79 */ 80 setSearchFilter : function(filter) 81 { 82 this.middle.addControl(filter); 83 }, 84 85 /** 86 * sets the pager filter 87 * @param {Banana.Controls.DataGridPagerFilter} filter 88 */ 89 setPagerFilter : function(pager) 90 { 91 this.bottom.addControl(pager); 92 }, 93 94 /** 95 * sets checkbox filter 96 * @param {Banana.Controls.DataGridCheckboxFilter} filter 97 */ 98 setCheckboxFilter : function(filter) 99 { 100 filter.setStyle('float:left;'); 101 this.top.addControl(filter); 102 }, 103 104 /** 105 * sets the date filter 106 * @param {Banana.Controls.DataGridDateFilter} filter 107 */ 108 setDateFilter : function(filter) 109 { 110 this.top.addControl(filter); 111 }, 112 113 /** 114 * sets a dropdown filter 115 * @param {Banana.Controls.DataGridDropDownFilter} filter 116 */ 117 setDropDownFilter : function(filter) 118 { 119 filter.setStyle('float:left;'); 120 this.middle.addControl(filter); 121 }, 122 123 /** 124 * set top buttons 125 * by default they are aligned from the right 126 * @param {Array} buttons 127 */ 128 setTopButtons : function(buttons) 129 { 130 this.topButtons = buttons; 131 132 var i,len; 133 for (i=0,len = buttons.length; i < len; i++) 134 { 135 this.top.addControl(buttons[i]); 136 buttons[i].setStyle('float:right;margin-right:2px;'); 137 } 138 }, 139 140 /** 141 * set buttons 142 * by default the are aligned from the left 143 * @param {Array} buttons 144 */ 145 setButtons : function(buttons) 146 { 147 this.buttons = buttons; 148 149 buttondownadded = false; 150 151 for (var i=0,len = buttons.length; i < len; i++) 152 { 153 buttondownadded = true; 154 this.bottom.addControl(buttons[i]); 155 } 156 157 //if a dropdown is added we show the arrow indicator 158 if (buttondownadded) 159 { 160 this.arrow.setVisible(true); 161 } 162 }, 163 164 /** 165 * create layout 166 * @ignore 167 */ 168 createLayout : function() 169 { 170 this.top = new Banana.Controls.Panel().addCssClass('BDataGridControlPanelTop'); 171 this.middle = new Banana.Controls.Panel().addCssClass('BDataGridControlPanelCenter'); 172 this.bottom = new Banana.Controls.Panel().addCssClass('BDataGridControlPanelBottom'); 173 174 this.addControl(this.top); 175 this.addControl(this.middle); 176 this.addControl(this.bottom); 177 178 this.arrow = new Banana.Controls.Panel().addCssClass('BDataGridControlArrow'); 179 //default is invisible. later when we add filters we make it visible 180 this.arrow.setVisible(false); 181 this.bottom.addControl(this.arrow); 182 } 183 }); 184