1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary list control 5 */ 6 7 goog.provide('Banana.Controls.DataControls.ListControls.ListControl'); 8 9 goog.require('Banana.Controls.DataControls.DataControl'); 10 11 /** @namespace Banana.Controls.ListControl */ 12 namespace('Banana.Controls').ListControl = Banana.Controls.DataControl.extend( 13 /** @lends Banana.Controls.ListControl.prototype */ 14 { 15 16 /** 17 * Create a base list control. 18 * Providing functionality to bind the datasource of this control to datasets. 19 * This control should only used as an extension class for more specific controls. 20 * 21 * @constructs 22 * @extends Banana.Controls.DataControl 23 */ 24 init: function() 25 { 26 this._super(); 27 28 this.dataKeyField = 'key'; 29 this.dataValueField = 'value'; 30 this.dataDepthField = 'depth'; 31 } 32 33 }); 34 35 /** 36 * sets datasource on control. 37 * when this method is called we invalidate the control to let the page 38 * rerender the control. We also trigger a dataSourceChanged event 39 * 40 * @param {mixed} data for control 41 * @param {boolean} when true no dataSourCechanged event is triggered 42 * @return {this} 43 */ 44 Banana.Controls.ListControl.prototype.setDataSource = function(datasource,ignoreEvent) 45 { 46 this.datasource = datasource; 47 48 this.invalidateDisplay(); 49 50 if (!ignoreEvent) 51 { 52 this.triggerEvent('dataSourceChanged',datasource); 53 } 54 return this; 55 }, 56 57 /** 58 * @return {mixed} 59 */ 60 Banana.Controls.ListControl.prototype.getDataSource = function() 61 { 62 return this.datasource; 63 }; 64 65 /** 66 * binds a value from datasource from dataset to datasource in this control 67 * 68 * @param {mixed} Banana.Data.DataSet || name of the dataset 69 * @param {string} bind property of the data. can be like value.subvalue.subsubvalue 70 * @return {this} 71 */ 72 Banana.Controls.ListControl.prototype.dataSetSourceBind = function(set,bind) 73 { 74 this.bindedDataSource = [set,bind]; 75 76 if (set instanceof Banana.Data.DataSet) 77 { 78 set.bindControlToDataSource(this); 79 } 80 81 return this; 82 }; 83 84 /** 85 * @param {String} key of the field where the key resists in. 86 * Only use this when your datasource contains complex objects 87 * @return this; 88 */ 89 Banana.Controls.ListControl.prototype.setDataKeyField = function(key) 90 { 91 this.dataKeyField = key; 92 return this; 93 }; 94 95 /** 96 * @param {String} key of the field where the value resists in. 97 * Only use this when your datasource contains complex objects 98 * @return this; 99 */ 100 Banana.Controls.ListControl.prototype.setDataValueField = function(value) 101 { 102 this.dataValueField = value; 103 return this; 104 }; 105 106 /** 107 * @ignore 108 * TODO: I think it should be moved to the Banana.Controls.DropDown class 109 */ 110 Banana.Controls.ListControl.prototype.setDataDepthField = function(value) 111 { 112 this.dataDepthField = value; 113 return this; 114 };