Makes Grant selector disable when Funder is not selected on Grant Tab of DMP Editor.

This commit is contained in:
gkolokythas 2019-10-04 12:16:59 +03:00
parent cf16779010
commit da325854c9
2 changed files with 34 additions and 7 deletions

View File

@ -68,7 +68,7 @@
<mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-GRANT' | translate}}</span>
</div>
<div class="col-12" [ngClass]="isNewVersion?'disabled-toggle':'add-entity'" *ngIf="!isCreateNew" (click)="createGrant()">
<div class="col-12" [ngClass]="isNewVersion || isGrantDisabled()?'disabled-toggle':'add-entity'" *ngIf="!isCreateNew" (click)="createGrant()">
<mat-icon>add</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.CREATE-NEW-GRANT' | translate}}</span>
</div>

View File

@ -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";
}
}