Headless CMS and Content Managment Hub
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.
 
 
 
 
 

61 lines
1.7 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { AppLanguageDto, fadeAnimation, FieldForm, ModalModel } from '@app/shared';
@Component({
selector: 'sqx-field-copy-button[formModel][languages]',
styleUrls: ['./field-copy-button.component.scss'],
templateUrl: './field-copy-button.component.html',
animations: [
fadeAnimation,
],
})
export class FieldCopyButtonComponent implements OnChanges {
@Input()
public formModel: FieldForm;
@Input()
public languages: ReadonlyArray<AppLanguageDto>;
public languageCodes: ReadonlyArray<string>;
public copySource: string;
public copyTargets: ReadonlyArray<string>;
public dropdown = new ModalModel();
public get isLocalized() {
return this.formModel.field.isLocalizable && this.languages.length > 1;
}
public ngOnChanges(changes: SimpleChanges) {
if (changes['languages']) {
this.setCopySource(this.languages[0]?.iso2Code);
}
}
public setCopySource(language: string) {
this.copySource = language;
this.copyTargets = [];
this.languageCodes = this.languages.map(x => x.iso2Code).filter(x => x !== language);
}
public copy() {
if (this.copySource && this.copyTargets?.length > 0) {
const source = this.formModel.get(this.copySource).form.value;
for (const target of this.copyTargets) {
if (target !== this.copySource) {
this.formModel.get(target)?.setValue(source);
}
}
}
}
}