TimeEntryDialog::TimeEntryDialog( QWidget * parent )
: QDialog( parent )
{
	setupUi( this );

	mAssetModel = new ElementModel( mAssetTree );
	mAssetModel->setSecondColumnIsLocation( true );
	mAssetTree->setModel( mAssetModel );

//	mCalendarButton->hide();

	connect( mChooseStartDateButton, SIGNAL( clicked() ), SLOT( chooseStartDate() ) );
	connect( mChooseEndDateButton, SIGNAL( clicked() ), SLOT( chooseEndDate() ) );
	connect( mProjectCombo, SIGNAL( activated( const QString & ) ), SLOT( projectSelected( const QString & ) ) );
	connect( mTypeCombo, SIGNAL( currentChanged( const Record & ) ), SLOT( assetTypeChanged( const Record & ) ) );
	connect( mAssetFilterEdit, SIGNAL( textChanged( const QString & ) ), SLOT( slotFilterAssets() ) );
	
	setDateRange( QDate::currentDate() );
	ProjectList pl = Project::select().filter( "fkeyProjectStatus", 4 ).sorted( "name" );
	mProject = pl[0];
	mProjectCombo->addItems( pl.names() );

	mTypeCombo->setTagFilters( QStringList() << "timesheet" );
	mTypeCombo->setShowFirst( User::currentUser().roles() );
	mAssetType = mTypeCombo->current();
	mUser = User::currentUser();

	mForcedProjectCategories += "Vacation";
	mForcedProjectCategories += "Sick";
	mForcedProjectCategories += "Comp Time";
	mForcedProjectCategories += "Unpaid Leave";
	mForcedProjectCategories += "Holidays";

	mVirtualProject = Project::recordByName( "_virtual_project" );
}
ScheduleDialog::ScheduleDialog( QWidget * parent )
: QDialog( parent )
, mAssetModel( 0 )
, mDisableUpdates( false )
{
	setupUi( this );

	mAssetModel = new ElementModel( mAssetTree );
	mAssetModel->setSecondColumnIsLocation( true );
	mAssetModel->setAutoSort( true );
	mAssetTree->setModel( mAssetModel );

	mUserModel = new ElementModel( mUserCombo );
	mUserModel->setAutoSort( true );
	mUserCombo->setModel( mUserModel );
	mUserCombo->setModelColumn( 0 );

//	connect( mCalendarButton, SIGNAL( clicked() ), SLOT( showCalendar() ) );
	connect( mProjectCombo, SIGNAL( activated( const QString & ) ), SLOT( projectSelected( const QString & ) ) );
	connect( mTypeCombo, SIGNAL( currentChanged( const Record & ) ), SLOT( assetTypeChanged( const Record & ) ) );
	connect( mTypeFilterCheck, SIGNAL( toggled( bool ) ), SLOT( setUseTypeFilter( bool ) ) );
	connect( mTypeFilterAssetsCheck, SIGNAL( toggled( bool ) ), SLOT( setUseAssetsTypeFilter( bool ) ) );

	connect( mUserCombo, SIGNAL( currentChanged( const Record & ) ), SLOT( employeeSelected( const Record & ) ) );

	connect( mChooseStartDateButton, SIGNAL( clicked() ), SLOT( chooseStartDate() ) );
	connect( mChooseEndDateButton, SIGNAL( clicked() ), SLOT( chooseEndDate() ) );

	QDate d( QDate::currentDate() );
	setDateRange( d, d );
	ProjectList pl = Project::select().filter( "fkeyProjectStatus", 4 ).sorted( "name" );
	mProject = pl[0];
	mProjectCombo->addItems( pl.names() );

	mTypeCombo->setTagFilters( QStringList() << "schedule" );
	mAssetType = mTypeCombo->current();

	updateUsers();

	mDateStartEdit->setMaximumDate( QDate::currentDate() );
	mDateEndEdit->setMinimumDate( QDate::currentDate() );
}