Skip to content
Snippets Groups Projects
webpage-family-form.component.ts 1.33 KiB
Newer Older
François Agneray's avatar
François Agneray committed
/**
 * This file is part of Anis Client.
 *
 * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { UntypedFormGroup, UntypedFormControl, Validators } from '@angular/forms';
François Agneray's avatar
François Agneray committed

import { WebpageFamily } from 'src/app/metamodel/models';

@Component({
    selector: 'app-webpage-family-form',
    templateUrl: 'webpage-family-form.component.html'
})
export class WebpageFamilyFormComponent implements OnInit {
    @Input() webpageFamily: WebpageFamily;
    @Output() onSubmit: EventEmitter<WebpageFamily> = new EventEmitter();

    public form = new UntypedFormGroup({
        label: new UntypedFormControl('', [Validators.required]),
        icon: new UntypedFormControl(null),
        display: new UntypedFormControl('', [Validators.required])
François Agneray's avatar
François Agneray committed
    });

    ngOnInit() {
        if (this.webpageFamily) {
            this.form.patchValue(this.webpageFamily);
        }
    }

    submit() {
        if (this.webpageFamily) {
            this.onSubmit.emit({
                ...this.webpageFamily,
                ...this.form.value
            });
        } else {
            this.onSubmit.emit(this.form.value);
        }
    }
}