Ext.define('TradePortal.view.products.CartGridt', {
	extend: 'Ext.grid.Panel',
	alias: 'widget.cartgridt',
	width: 962,
	height: window.innerHeight / 1.5,
	style: "border-color:transparent;",
	store: 'Cart',
	border: false,
	cls: 'cartgrid',
	id: 'cart_grid2',
	loadMask: false,
	selType: 'cellmodel',
	requires: ['Ext.grid.plugin.CellEditing'],
	plugins: [{
		ptype: 'cellediting',
		clicksToEdit: 1,
		listeners: {
			edit: function (editor, e) {
				if (e.field == "prodQty") {
					Ext.getStore('updateCartProduct').load({
						params: {
							sessionID: Ext.getStore('createCart').last().data.sessionID,
							roomTypeID: '',
							productID: e.record.data.productID,
							lineID: e.record.data.lineID,
							customerID: Ext.getStore('HomeStatistic').last().data.id_cust,
							quoteQty: e.record.data.prodQty,
							unitSell: 0,
							quoteComments: '',
							UOM: e.record.data.UOM
						}
					});
					Ext.getCmp('cart_grid').getView().refresh();
				}
			}
		}
	}],
	columns: {
		items: [{
			header: 'Product',
			dataIndex: 'productID',
			flex: 5
		}, {
			header: 'Description',
			dataIndex: 'prodDesc',
			flex: 9,
			renderer: function renderTip(val, meta, rec, rowIndex, colIndex, store) {
				meta.tdAttr = 'data-qtip="' + val + '"';
				return val;
			}
		}, {
			header: 'Qty',
			dataIndex: 'prodQty',
			flex: 2,
			editor: {
				xtype: 'numberfield',
				value: 1,
				minValue: 1
			}
		}, {
			header: 'UOM',
			dataIndex: 'UOM',
			flex: 3
		}, {
			header: 'Customer Price (Inc GST)',
			dataIndex: 'unitPrice',
			flex: 4,
			align: 'right',
			renderer: Ext.util.Format.usMoney
		}, {
			header: '-',
			xtype: 'actioncolumn',
			items: [{
				icon: 'resources/css/images/cross.png',
				tooltip: 'Remove',
				handler: function (grid, rowIndex, colIndex) {
					var rec = grid.getStore().getAt(rowIndex);

					Ext.getStore('deleteCartProduct').load({
						params: {
							sessionID: Ext.getStore('createCart').last().data.sessionID,
							productID: rec.get('productID'),
							lineID: rec.get('lineID')
						}
					});
				}
			}],
			flex: 1
		}],
		defaults: {
			draggable: false,
			hideable: false,
			sortable: false,
			resizable: false
		}
	}
});
