From da325854c969ca527c4251d1d4a3cfed75f4a51d Mon Sep 17 00:00:00 2001 From: gkolokythas Date: Fri, 4 Oct 2019 12:16:59 +0300 Subject: [PATCH] Makes Grant selector disable when Funder is not selected on Grant Tab of DMP Editor. --- .../editor/grant-tab/grant-tab.component.html | 2 +- .../editor/grant-tab/grant-tab.component.ts | 39 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html index 45ad4b56d..ce7eab906 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html @@ -68,7 +68,7 @@ settings_backup_restore {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-GRANT' | translate}} -
+
add {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.CREATE-NEW-GRANT' | translate}}
diff --git a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts index 9969509c5..f14e36cd3 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts @@ -10,17 +10,19 @@ import { FunderService } from '../../../../core/services/funder/funder.service'; import { FunderCriteria } from '../../../../core/query/funder/funder-criteria'; import { ProjectCriteria } from '../../../../core/query/project/project-criteria'; import { TranslateService } from '@ngx-translate/core'; +import { takeUntil } from "rxjs/operators"; +import { BaseComponent } from "../../../../core/common/base/base.component"; @Component({ selector: 'app-grant-tab', templateUrl: './grant-tab.component.html', styleUrls: ['./grant-tab.component.scss'] }) -export class GrantTabComponent implements OnInit { +export class GrantTabComponent extends BaseComponent implements OnInit { @Input() grantformGroup: FormGroup; @Input() projectFormGroup: FormGroup; - @Input() funderFormGroup: FormGroup; + @Input() funderFormGroup: FormGroup = null; @Input() isFinalized: boolean; @Input() isNewVersion: boolean; @@ -38,7 +40,9 @@ export class GrantTabComponent implements OnInit { private projectService: ProjectService, private funderService: FunderService, private language: TranslateService - ) { } + ) { + super(); + } ngOnInit() { @@ -47,7 +51,7 @@ export class GrantTabComponent implements OnInit { this.funderAutoCompleteConfiguration = { filterFn: this.searchFunder.bind(this), - initialItems: (extraData) => this.searchFunder(''), + initialItems: () => this.searchFunder(''), displayFn: (item) => item['label'], titleFn: (item) => item['label'], subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') @@ -55,7 +59,7 @@ export class GrantTabComponent implements OnInit { this.grantAutoCompleteConfiguration = { filterFn: this.searchGrant.bind(this), - initialItems: (extraData) => this.searchGrant(''), + initialItems: () => this.searchGrant(''), displayFn: (item) => item['label'], titleFn: (item) => item['label'], subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') @@ -63,7 +67,7 @@ export class GrantTabComponent implements OnInit { this.projectAutoCompleteConfiguration = { filterFn: this.searchProject.bind(this), - initialItems: (extraData) => this.searchProject(''), + initialItems: () => this.searchProject(''), displayFn: (item) => item['label'], titleFn: (item) => item['label'], subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') @@ -75,6 +79,7 @@ export class GrantTabComponent implements OnInit { this.setGrantValidators(); this.setProjectValidators(); this.setFunderValidators(); + this.registerFormListeners(); } searchGrant(query: any) { @@ -103,6 +108,7 @@ export class GrantTabComponent implements OnInit { createGrant() { if (this.isNewVersion) { return }; + if (this.isGrantDisabled()) return; this.isCreateNew = !this.isCreateNew; this.setGrantValidators(); } @@ -169,4 +175,25 @@ export class GrantTabComponent implements OnInit { } } + registerFormListeners() { + this.funderFormGroup.valueChanges + .pipe(takeUntil(this._destroyed)) + .subscribe(x => { + this.funderValueChanged(x); + }) + } + + funderValueChanged(funder: any) { + if ((funder.id !== undefined) || (funder.existFunder !== null && funder.existFunder.id !== undefined)) { + this.grantformGroup.enable(); + } + else { + this.grantformGroup.reset(); + this.grantformGroup.disable(); + } + } + + isGrantDisabled() { + return this.grantformGroup.status === "DISABLED"; + } }