SD.timeClock.addPopup('absence', new Ext.Window({
	layout: 'fit',
	title: 'Report an Absence',
	width: 311,
	height: 230,
	closeAction: 'hide',
	modal: true,
	plain: true,
	items: [{
		xtype: 'form',
		id: 'tcAbsentForm',
		labelAlign: 'top',
		cls: 'formpadding',
		border: false,
		items: [{
			xtype: 'datefield',
			fieldLabel: 'Date from',
			name: 'beginDate',
			width: 160
		},
		{
			xtype: 'datefield',
			fieldLabel: 'Date to',
			name: 'endDate',
			width: 160
		},
		{
			xtype: 'combo',
			id: 'tcAbsentReason',
			fieldLabel: 'Reason',
			width: 260,
			hiddenName: 'reasonid',
			valueField: 'reasonid',
			displayField: 'reason',
			typeAhead: true,
			triggerAction: 'all',
			store: new Ext.data.Store({
				url: 'main_menu/timeclock_data.json.php',
				baseParams: {
					command: 'getReasons'
				},
				autoLoad: false,
				reader: new Ext.data.JsonReader({
					root: 'reasons'
				}, ['reasonid', 'reason'])
			})
		}]
	}],
	buttons: [{
		text: 'Submit',
		handler: function() {
			Ext.getCmp('tcAbsentForm').getForm().submit({
				url: 'main_menu/timeclock_data.json.php',
				params: {
					command: 'reportAbsence',
					staffid: Ext.getCmp('tcStaffMember').getValue(),
					tcPassword: Ext.getCmp('tcPassword').getValue()
				},
				success: function(form) {
					Ext.Msg.alert('Success');
				},
				failure: function(form, response) {
					Ext.Msg.alert('ERROR', 'Failure: Absence failed to be reported');
				}
			});
		}
	},
	{
		text: 'Close',
		handler: function(btn) {
			this.ownerCt.ownerCt.hide();
		}
	}],
	listeners: {
		beforeShow: function() {
			if (SchoolDynamics.TeacherID != 'KIOSK') {
				return true;
			}
			var showPopup;
			Ext.Ajax.request({
				url: 'main_menu/timeclock_data.json.php',
				async: false,
				success: function(r) {
					if (r.responseText.trim() == 'true') {
						showPopup = true;
					} else {
						Ext.Msg.alert('ERROR', 'Wrong password');
						showPopup = false;
					}
				},
				params: {
					command: 'isValidPass',
					staffid: Ext.getCmp('tcStaffMember').getValue(),
					tcPassword: Ext.getCmp('tcPassword').getValue()
				}
			});
			return showPopup;
		},
		show: function() {
			Ext.getCmp('tcAbsentReason').store.load();
		}
	}
})
);

