var proxy = 'ec2dbProxy.aspx?model=product';

var ds = new Ext.data.Store({
	url: proxy,
	autoLoad: true,
	reader: new Ext.data.JsonReader({})
})

ds.on('update', function(t, rec, s) {
  // Convert the store record to form object used in ajax
  var parm =  {};
  for (var i=0; i < rec.fields.length; i++) {
    var f = rec.data[rec.fields.items[i].name];
    if (typeof f == "object" && typeof f.isLeapYear == 'function') {
       f = f.format('Y-m-d');      
    }
    parm[rec.fields.items[i].name] = f;
  }
  Ext.Ajax.request({
    url: proxy,
    method: 'POST',
    jsonData: parm,
    success: function ( result, request ) {
      if (rec.data['id'] == 0) {
        rec.data['id'] = parseInt(result.responseText);
      }
    },
    failure: function ( result, request) {
    // error .. TODO
    }
  });
});
    
    
var panel1 = new Ext.Panel({
  title: 'Standard',
  renderTo : Ext.getBody(),
  width: '100%',
  height: 600,
  title: 'Grid1',
  layout: 'fit',
	autoScroll: true,
  items: [{
  	autoScroll: true,
    clicksToEdit:1,
	  xtype: 'editorgrid',
		store: ds,
    colModel: new Ext.grid.ColumnModel({
			defaults: {
				width: 120,
				sortable: true
			},
			columns: ec2.buildColumns([
        new Ext.grid.RowNumberer(),
      {
        header: 'Text', 
        width: 200, 
        sortable: true, 
        dataIndex: 'DESC'  ,
        editor: new App.beskrivelse({
        })
      }, {
        header: 'Price', 
        renderer: function(v) {return iceEditDec(v,2)},
        sortable: true, 
        dataIndex: 'PRICE',
        align: 'right',
        editor: new Ext.form.NumberField({
          decimalPrecision:2,
          decimalSeparator:','
        })
      },{
        header: 'Manufacturer', 
        sortable: true, 
        dataIndex: 'MANUID'
      },{
        header: 'Last Updated', 
        width: 50,
        sortable: true, 
        dataIndex: 'STOCKDATE', 
        xtype: 'datecolumn', 
        renderer: Ext.util.Format.dateRenderer('d-m-Y'),
        editor: new Ext.form.DateField({
          format: 'd-m-Y',
        })
      }]),
    }),
    viewConfig: {
      forceFit: true,
    },
    sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
    iconCls: 'icon-grid'
	}]
});
      



