11import {
22 AsyncPipe ,
33 NgClass ,
4+ NgForOf ,
45 NgIf ,
56} from '@angular/common' ;
67import {
8+ ChangeDetectorRef ,
79 Component ,
810 Input ,
911 OnChanges ,
12+ OnInit ,
1013 SimpleChange ,
1114 SimpleChanges ,
1215} from '@angular/core' ;
16+ import { FormsModule } from '@angular/forms' ;
1317import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
14- import {
15- DynamicFormControlModel ,
16- DynamicFormService ,
17- DynamicInputModel ,
18- DynamicTextAreaModel ,
19- } from '@ng-dynamic-forms/core' ;
18+ import { DynamicFormService } from '@ng-dynamic-forms/core' ;
2019import {
2120 TranslateModule ,
2221 TranslateService ,
2322} from '@ngx-translate/core' ;
2423
25- import { environment } from '../../../environments/environment' ;
2624import { AuthService } from '../../core/auth/auth.service' ;
2725import { ObjectCacheService } from '../../core/cache/object-cache.service' ;
2826import { CommunityDataService } from '../../core/data/community-data.service' ;
@@ -34,6 +32,7 @@ import { FormComponent } from '../../shared/form/form.component';
3432import { NotificationsService } from '../../shared/notifications/notifications.service' ;
3533import { UploaderComponent } from '../../shared/upload/uploader/uploader.component' ;
3634import { VarDirective } from '../../shared/utils/var.directive' ;
35+ import { communityFormModels } from './community-form.models' ;
3736
3837/**
3938 * Form used for creating and editing communities
@@ -51,10 +50,12 @@ import { VarDirective } from '../../shared/utils/var.directive';
5150 ComcolPageLogoComponent ,
5251 NgIf ,
5352 NgClass ,
53+ NgForOf ,
5454 VarDirective ,
55+ FormsModule ,
5556 ] ,
5657} )
57- export class CommunityFormComponent extends ComColFormComponent < Community > implements OnChanges {
58+ export class CommunityFormComponent extends ComColFormComponent < Community > implements OnInit , OnChanges {
5859 /**
5960 * @type {Community } A new community when a community is being created, an existing Input community when a community is being edited
6061 */
@@ -65,53 +66,27 @@ export class CommunityFormComponent extends ComColFormComponent<Community> imple
6566 */
6667 type = Community . type ;
6768
68- /**
69- * The dynamic form fields used for creating/editing a community
70- * @type {(DynamicInputModel | DynamicTextAreaModel)[] }
71- */
72- formModel : DynamicFormControlModel [ ] = [
73- new DynamicInputModel ( {
74- id : 'title' ,
75- name : 'dc.title' ,
76- required : true ,
77- validators : {
78- required : null ,
79- } ,
80- errorMessages : {
81- required : 'Please enter a name for this title' ,
82- } ,
83- } ) ,
84- new DynamicTextAreaModel ( {
85- id : 'description' ,
86- name : 'dc.description' ,
87- spellCheck : environment . form . spellCheck ,
88- } ) ,
89- new DynamicTextAreaModel ( {
90- id : 'abstract' ,
91- name : 'dc.description.abstract' ,
92- spellCheck : environment . form . spellCheck ,
93- } ) ,
94- new DynamicTextAreaModel ( {
95- id : 'rights' ,
96- name : 'dc.rights' ,
97- spellCheck : environment . form . spellCheck ,
98- } ) ,
99- new DynamicTextAreaModel ( {
100- id : 'tableofcontents' ,
101- name : 'dc.description.tableofcontents' ,
102- spellCheck : environment . form . spellCheck ,
103- } ) ,
104- ] ;
105-
10669 public constructor ( protected formService : DynamicFormService ,
10770 protected translate : TranslateService ,
10871 protected notificationsService : NotificationsService ,
10972 protected authService : AuthService ,
11073 protected dsoService : CommunityDataService ,
11174 protected requestService : RequestService ,
11275 protected objectCache : ObjectCacheService ,
113- protected modalService : NgbModal ) {
114- super ( formService , translate , notificationsService , authService , requestService , objectCache , modalService ) ;
76+ protected modalService : NgbModal ,
77+ protected cdr : ChangeDetectorRef ) {
78+ super ( formService , translate , notificationsService , authService , requestService , objectCache , modalService , cdr ) ;
79+ }
80+
81+ ngOnInit ( ) {
82+ this . initializeLanguage ( ) ;
83+
84+ this . formModels . set ( this . defaultLanguageCode , communityFormModels ( this . defaultLanguageCode , true ) ) ;
85+ this . languages . forEach ( lang => {
86+ this . formModels . set ( lang . code , communityFormModels ( lang . code , false ) ) ;
87+ } ) ;
88+
89+ super . ngOnInit ( ) ;
11590 }
11691
11792 ngOnChanges ( changes : SimpleChanges ) {
0 commit comments