/**
 * @author mba
 */
Ext.namespace('Ext.sfweb');
Ext.sfweb.RelatedProductPanel = function(conf){

	this.stripeRows = true;
	this.events = ['itemchanged'];
	this.clicksToEdit = 1;
	this.height = 400;
	this.autoScroll = true;
	this.autoExpandColumn = 'identifier';
    this.sm = new Ext.grid.RowSelectionModel({
		singleSelect:true
	});
	this.enableHdMenu = false;
	this.enableColumnResize = false;
	this.enableColumnMove = false;
	this.enableDragDrop = false;
	this.viewConfig = {
        forceFit: true
    };
	this.data = conf.data;
	this.columnnames = conf.columnnames;

	this.store = new Ext.data.SimpleStore({
        fields:['pid','identifier','price','check','amount','tax','image'],
		data: this.data
    });

    var checkColumn = new Ext.grid.CheckColumn({
       header: 'check',
       dataIndex: 'check',
       width: 35
    });

 	this.plugins = [
		checkColumn
	];

	this.getSelectedProducts = function(){
		var retval = [];
		Ext.each(this.store.data.items, function(el){
			if(el.data.check){
				retval.push(el.data);
			}
		}, this);
		return(retval);
	};

	this.cm = new Ext.grid.ColumnModel({
        defaults: {
            sortable: true
        },
        columns: [
            checkColumn,
			{
                header: this.columnnames.identifier,
                dataIndex: 'identifier',
				id: 'identifier'
			}, {
                header: this.columnnames.amount,
                dataIndex: 'amount',
                align: 'right',
				width: 25,
				editor: new Ext.form.NumberField({
                    allowBlank: false,
                    allowNegative: false,
                    maxValue: 1000
                })
            }, {
                header: this.columnnames.image,
                dataIndex: 'image',
                align: 'left',
				width: 65,
				renderer: renderImage
            }, {
                header: this.columnnames.tax,
                dataIndex: 'tax',
                align: 'center',
				width: 65
            }, {
                header: this.columnnames.price,
                dataIndex: 'price',
                align: 'right',
				width: 50,
				renderer: formatEURCurrency
			}
        ]
    });

	this.onUpdate= function(){
		this.fireEvent('itemchanged');
	};
	this.store.on('update', this.onUpdate.createDelegate(this), this);

	Ext.sfweb.RelatedProductPanel.superclass.constructor.call(this, conf);
}
Ext.extend(Ext.sfweb.RelatedProductPanel, Ext.grid.EditorGridPanel);