dailyAttendanceGrid = function(limitColumns) {
	var sm = new Ext.grid.CheckboxSelectionModel();
	var colReason = new Ext.form.ComboBox({
		allowBlank: false,
		displayField: 'reasons',
		valueField: 'reasonid',
		typeAhead: true,
		triggerAction: 'all',
		editable: false,
		store: reasonstore
	});
	var colExcused = new Ext.form.ComboBox({
		allowBlank: false,
		displayField: 'excusable',
		mode: 'local',
		valueField: 'excusable',
		typeAhead: true,
		triggerAction: 'all',
		store: new Ext.data.SimpleStore({
			fields: ['excusable'],
			data: [
				['Excused'],
				['Unexcused']
			]
		})
	});
	var colStatus = new Ext.form.ComboBox({
		allowBlank: false,
		displayField: 'status',
		mode: 'local',
		valueField: 'status',
		typeAhead: true,
		triggerAction: 'all',
		store: new Ext.data.SimpleStore({
			fields: ['status'],
			data: [
				['Absent'],
				['Tardy'],
				['Checkout']
			]
		})
	});
	var colTime = new Ext.form.TimeField({
		minValue: '7:00 AM',
		maxValue: '6:00 PM',
		increment: 1,
		listeners: {}
	});
	var columns = [
	sm,
	{
		header: "Homeroom",
		width: 75,
		sortable: true,
		dataIndex: 'homeroom',
		align: 'center'
	},
	{
		header: "Student Name",
		width: 150,
		sortable: true,
		menuDisabled: true,
		dataIndex: 'student',
		renderer: QTipRenderer
	},
	{
		header: "Status",
		width: 90,
		sortable: true,
		menuDisabled: true,
		dataIndex: 'status',
		editor: colStatus,
		renderer: comboBoxRenderer(colStatus)
	},
	{
		header: "Excused?",
		width: 100,
		sortable: true,
		menuDisabled: true,
		dataIndex: 'excusable',
		editor: colExcused,
		renderer: comboBoxRenderer(colExcused)
	},
	{
		header: "Reason",
		sortable: false,
		menuDisabled: true,
		id: 'reason',
		dataIndex: 'reasonid',
		editor: colReason,
		renderer: comboBoxRenderer(colReason)
	},
	{
		header: "Out",
		width: 100,
		sortable: false,
		menuDisabled: true,
		dataIndex: 'out',
		editor: {
			xtype: 'timespinner'
		}
	},
	{
		header: "In",
		width: 100,
		sortable: false,
		menuDisabled: true,
		dataIndex: 'in',
		editor: {
			xtype: 'timespinner'
		}
	}];
	// allow samples to limit columns
	if (limitColumns) {
		var cs = [];
		for (var i = 0, len = limitColumns.length; i < len; i++) {
			cs.push(columns[limitColumns[i]]);
		}
		columns = cs;
	}
	dailyAttendanceGrid.superclass.constructor.call(this, {
		title: "Daily Attendance Information",
		tbar: {
			xtype: 'toolbar',
			id: 'dailyAttendanceOptions',
			items: [{
				xtype: 'tbspacer',
				width: 5
			},
			{
				xtype: 'label',
				text: 'Date:'
			},
			{
				xtype: 'tbspacer',
				width: 5
			},
			{
				xtype: 'datefield',
				width: 100,
				value: new Date(),
				id: 'historydate',
				listeners: {
					setvalue: function(datefield, newValue, oldValue) {
						Ext.getCmp('dailyAttendanceGrid').store.baseParams.date = datefield.value;
						Ext.getCmp('dailyAttendanceGrid').store.load();
					}
				}
			},
			{
				xtype: 'tbspacer',
				width: 5
			},
			{
				xtype: 'tbseparator'
			},
			{
				xtype: 'label',
				text: 'Show: '
			},
			{
				xtype: 'tbspacer',
				width: 5
			},
			{
				xtype: 'combo',
				mode: 'local',
				typeAhead: false,
				width: 120,
				id: 'showHRCombo',
				triggerAction: 'all',
				store: new Ext.data.ArrayStore({
					fields: ['view'],
					data: [
						['My Homeroom'],
						['All Homerooms']
					]
				}),
				displayField: 'view',
				listeners: {
					setvalue: function(cmp, newValue) {
						var grid = this.ownerCt.ownerCt;
						if (newValue == 'My Homeroom') {
							grid.store.filter('inHomeroom', '1', true, false);
						} else {
							grid.store.clearFilter();
						}
					}
				}
			}]
		},
		store: new Ext.data.Store({
			url: 'teacher_tools/attendance_data.json.php',
			baseParams: {
				command: 'dailyAttendanceHistory',
				date: new Date().format('m/d/Y')
			},
			reader: new Ext.data.JsonReader({
				root: 'dailyAttendanceHistory',
				idProperty: 'itemno'
			}, [{
				name: 'itemno'
			},
			{
				name: 'homeroom'
			},
			{
				name: 'student'
			},
			{
				name: 'status'
			},
			{
				name: 'excusable'
			},
			{
				name: 'reasonid'
			},
			{
				name: 'out'
			},
			{
				name: 'in'
			},
			{
				name: 'studentid'
			},
			{
				name: 'inHomeroom'
			}]),
			autoLoad: false,
			writer: new Ext.data.JsonWriter({
				writeAllFields: true
			}),
			listeners: {
				load: function() {
					var hrCombo = Ext.getCmp('showHRCombo');
					var showHRValue = hrCombo.getValue();
					if (showHRValue == '') {
						hrCombo.setValue('My Homeroom');
					} else {
						hrCombo.fireEvent('setValue', hrCombo, showHRValue);
					}
				}
			}
		}),
		columns: columns,
		sm: sm,
		border: false,
		layout: 'fit',
		autoScroll: true,
		autoExpandColumn: 'reason',
		id: 'dailyAttendanceGrid',
		listeners: {
			beforeedit: function(e) {
				if (e.record.data.status == "Absent" || e.record.data.status == "Checkout") {
					colReason.store.filter('type', 'Absent');
				} else if (e.record.data.status == "Tardy") {
					colReason.store.filter('type', 'Tardy');
				}
			},
			afteredit: function() {
				colReason.store.clearFilter();
			}
		},
		bbar: [{
			xtype: 'tbfill'
		},
		{
			text: 'Delete',
			iconCls: 'delete',
			listeners: {
				click: function(button) {
					dailyAttendanceGrid = Ext.getCmp('dailyAttendanceGrid');
					dailyAttendanceGrid.store.batchRemove(dailyAttendanceGrid.getSelectionModel().getSelections());
				}
			}
		}]
	});
}
Ext.extend(dailyAttendanceGrid, Ext.grid.EditorGridPanel);

