mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
|
|
import { FormBuilder } from '@angular/forms';
|
|
|
|
import {
|
|
AddLanguageForm,
|
|
LanguageDto,
|
|
LanguagesState
|
|
} from '@app/shared';
|
|
|
|
@Component({
|
|
selector: 'sqx-language-add-form',
|
|
styleUrls: ['./language-add-form.component.scss'],
|
|
templateUrl: './language-add-form.component.html',
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
})
|
|
export class LanguageAddFormComponent implements OnChanges {
|
|
@Input()
|
|
public newLanguages: ReadonlyArray<LanguageDto>;
|
|
|
|
public addLanguageForm = new AddLanguageForm(this.formBuilder);
|
|
|
|
constructor(
|
|
private readonly languagesState: LanguagesState,
|
|
private readonly formBuilder: FormBuilder
|
|
) {
|
|
}
|
|
|
|
public ngOnChanges() {
|
|
if (this.newLanguages.length > 0) {
|
|
const language = this.newLanguages[0];
|
|
|
|
this.addLanguageForm.load({ language });
|
|
}
|
|
}
|
|
|
|
public addLanguage() {
|
|
const value = this.addLanguageForm.submit();
|
|
|
|
if (value) {
|
|
this.languagesState.add(value.language)
|
|
.subscribe(() => {
|
|
this.addLanguageForm.submitCompleted();
|
|
}, error => {
|
|
this.addLanguageForm.submitFailed(error);
|
|
});
|
|
}
|
|
}
|
|
}
|