1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary DataGridButtonColumn 5 */ 6 7 goog.provide('Banana.Controls.DataControls.ListControls.DataGrid.ColumnControls.DataGridButtonColumn'); 8 9 goog.require('Banana.Controls.DataControls.ListControls.DataGrid.ColumnControls.DataGridColumn'); 10 11 /** @namespace Banana.Controls.DataGridButtonColumn */ 12 namespace('Banana.Controls').DataGridButtonColumn = Banana.Controls.DataGridColumn.extend( 13 /** @lends Banana.Controls.DataGridButtonColumn.prototype */ 14 { 15 /** 16 * Creates Datagrid button column for usage in table list render 17 * @constructs 18 * @extends Banana.Controls.DataGridColumn 19 */ 20 init : function() 21 { 22 this._super(); 23 this.buttonText = ""; 24 }, 25 26 /** 27 * @param {String} text 28 */ 29 setButtonText : function(text) 30 { 31 this.buttonText = text; 32 return this; 33 } 34 }); 35 36 /** 37 * Create the control to use in this column. In this case, a button. 38 * @ignore 39 * @return {Banana.Controls.Button} 40 */ 41 Banana.Controls.DataGridButtonColumn.prototype.getControl = function() 42 { 43 var b = new Banana.Controls.Button(); 44 b.setText(this.buttonText); 45 b.bind('click',this.getProxy(function(e) 46 { 47 function getItemRender(c) 48 { 49 if (c instanceof Banana.Controls.DataGridTableItemRender) 50 { 51 return c; 52 } 53 54 return getItemRender(c.getParent()); 55 } 56 57 var ir = getItemRender(b); 58 59 var index = this.listRender.getIndexByItemRender(ir); 60 61 e.stopPropagation(); 62 63 var params = {'commandName':this.commandName, 64 'index':index, 65 'data':this.listRender.datasource[index] 66 }; 67 68 this.listRender.triggerEvent('onCommand',params); 69 })); 70 71 return b; 72 }; 73 74 /** 75 * sets command name. this name will be available on the grid oncommand event 76 * 77 * @param {String} 78 * @return {this} 79 */ 80 Banana.Controls.DataGridButtonColumn.prototype.setCommandName = function(name) 81 { 82 this.commandName = name; 83 return this; 84 }; 85