
//Make grid cell contents selectable
//http://extjs.com/forum/showthread.php?p=154426
if (!Ext.grid.GridView.prototype.templates) {
    Ext.grid.GridView.prototype.templates = {};
}
Ext.grid.GridView.prototype.templates.cell = new Ext.Template(
    '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="0" {cellAttr}>',
    '<div class="x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value}</div>',
    '</td>'
);

Ext.namespace("Netopia.grid");
Netopia.grid.Action = function(config){    
    Ext.apply(this, config);
//    for(var myAction in this.actions){
//            if(this.actions.hasOwnProperty(myAction)){
//            	this.privateAction[this.actions[myAction].name]=new Ext.Action({
//                    text:this.actions[myAction].title,
//                    handler:function(){
//                	},
//                	iconCls:this.actions[myAction].iconCls
//                });
//            }
//   } 
    this.renderer = this.renderer.createDelegate(this);
};

Netopia.grid.Action.prototype = {
    /**
     * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
     * number column (defaults to '').
     */
    header: "",
    privateAction:{},
    actions:[],
    callback:"alert",
    /**
     * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
     */
    width: 23,
    separator:" | ",
    paramId:"id",
    /**
     * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
     */
    sortable: false,

    // private
    fixed:true,
    menuDisabled:true,
    dataIndex: '',
    //id: 'numberer',
    
    handleClick:function(e){

    },
    // private
    renderer : function(v, p, record, rowIndex){
    	var action = new Ext.Action({
    	    text: 'Do something',
    	    handler: function(){
    	        Ext.Msg.alert('Click', 'You did something.');
    	    },
    	    iconCls: 'do-something'
    	});
    	var btn=new Ext.Button(action);
        var str='';
        var jAction='';
        var callback;
        if(record.data.disable_action){
        	return;
        }
        for(var myAction in this.actions){
            if(this.actions.hasOwnProperty(myAction)){
//              jAction='javascript:Netopia.getUrl("'+
//              this.actions[myAction].url+'/'+this.paramId+'/'+record.id+'","'+
//              this.actions[myAction].target+'");';
              if(this.actions[myAction].callback){
            	  callback=this.actions[myAction].callback;
              }else{
            	  callback=this.callback;
              }
              var title="";
              if(this.actions[myAction].iconCls){
                title=" ";
              }else{
                this.actions[myAction].iconCls=""
                title=this.actions[myAction].title;
              }
              jAction='javascript:return '+callback+'("'+this.actions[myAction].name+'","'+record.id+'")';
              str+='<a href="#" title="'+this.actions[myAction].title +'" onclick=\''+jAction+'\' class="'+
              this.actions[myAction].iconCls+
              '" id="'+
              this.actions[myAction].name+rowIndex+
              '">'+title+'</a>' + this.separator;
              //Ext.EventManager.on( this.actions[myAction].name+rowIndex, this.actions[myAction].name, this.handleClick);
            }
        } 
        return str.substring(0,str.length-this.separator.length);
    }
};
