2019-12-11 15:51:03 +01:00
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
|
|
import { DmpModel } from '@app/core/model/dmp/dmp';
|
|
|
|
import { FunderModel } from '@app/core/model/funder/funder';
|
|
|
|
import { GrantListingModel } from '@app/core/model/grant/grant-listing';
|
|
|
|
import { ProjectModel } from '@app/core/model/project/project';
|
|
|
|
import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
|
|
|
import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model';
|
|
|
|
import { ProjectFormModel } from '@app/ui/dmp/editor/grant-tab/project-form-model';
|
|
|
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
|
|
|
import { ValidationContext } from '@common/forms/validation/validation-context';
|
|
|
|
import { DatasetEditorWizardModel } from '../dataset-editor/dataset-editor-wizard-model';
|
|
|
|
import { DmpEditorWizardModel } from '../dmp-editor/dmp-editor-wizard-model';
|
|
|
|
import { GrantEditorWizardModel } from '../grant-editor/grant-editor-wizard-model';
|
|
|
|
|
2019-03-01 16:16:21 +01:00
|
|
|
|
|
|
|
export class QuickWizardEditorWizardModel {
|
2019-12-11 15:51:03 +01:00
|
|
|
public grant: GrantEditorWizardModel;
|
|
|
|
public funder: FunderFormModel;
|
|
|
|
public project: ProjectFormModel;
|
2019-03-01 16:16:21 +01:00
|
|
|
public dmp: DmpEditorWizardModel;
|
|
|
|
public datasets: DatasetEditorWizardModel;
|
|
|
|
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
fromModelGrant(item: GrantListingModel): QuickWizardEditorWizardModel {
|
|
|
|
this.grant.fromModel(item);
|
2019-03-01 16:16:21 +01:00
|
|
|
return this;
|
2019-12-11 15:51:03 +01:00
|
|
|
}
|
2019-08-28 15:53:17 +02:00
|
|
|
|
2019-12-11 15:51:03 +01:00
|
|
|
fromModelFunder(item: FunderModel): QuickWizardEditorWizardModel {
|
|
|
|
this.funder.fromModel(item);
|
|
|
|
return this;
|
|
|
|
}
|
2019-08-28 15:53:17 +02:00
|
|
|
|
2019-12-11 15:51:03 +01:00
|
|
|
fromModelProject(item: ProjectModel): QuickWizardEditorWizardModel {
|
|
|
|
this.project.fromModel(item);
|
|
|
|
return this;
|
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
|
|
|
|
fromModelDmp(item: DmpModel): QuickWizardEditorWizardModel {
|
|
|
|
this.dmp.fromModel(item);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
fromModelDataset(item: DatasetWizardEditorModel[]): QuickWizardEditorWizardModel {
|
|
|
|
this.datasets.fromModel(item);
|
|
|
|
return this;
|
2019-12-11 15:51:03 +01:00
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-03-05 12:21:04 +01:00
|
|
|
buildForm(context: ValidationContext = null): FormGroup {
|
|
|
|
// if (context == null) { context = this.createValidationContext(); }
|
2019-03-01 16:16:21 +01:00
|
|
|
const formGroup = new FormBuilder().group({
|
2019-12-11 15:51:03 +01:00
|
|
|
grant: new GrantEditorWizardModel().buildForm(),
|
|
|
|
funder: new FunderFormModel().buildForm(),
|
|
|
|
project: new ProjectFormModel().buildForm(),
|
2019-03-01 16:16:21 +01:00
|
|
|
dmp: new DmpEditorWizardModel().buildForm(),
|
|
|
|
datasets: new DatasetEditorWizardModel().buildForm()
|
2019-06-12 15:01:55 +02:00
|
|
|
|
2019-03-01 16:16:21 +01:00
|
|
|
});
|
|
|
|
return formGroup;
|
|
|
|
}
|
|
|
|
|
2019-03-05 12:21:04 +01:00
|
|
|
// createValidationContext(): ValidationContext {
|
|
|
|
// const baseContext: ValidationContext = new ValidationContext();
|
2019-08-01 09:54:40 +02:00
|
|
|
// baseContext.validation.push({ key: 'grant', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'grant')] });
|
2019-03-05 12:21:04 +01:00
|
|
|
// baseContext.validation.push({ key: 'dmp', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'dmp')] });
|
2019-06-12 15:01:55 +02:00
|
|
|
// baseContext.validation.push({ key: 'datasets', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'datasets')] });
|
2019-03-05 12:21:04 +01:00
|
|
|
// return baseContext;
|
|
|
|
// }
|
2019-03-01 16:16:21 +01:00
|
|
|
|
2019-06-12 15:01:55 +02:00
|
|
|
}
|