form-instance.component.ts 1.24 KB
Newer Older
François Agneray's avatar
François Agneray committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';

import { Instance } from '../../store/model';

@Component({
    selector: 'app-form-instance',
    templateUrl: 'form-instance.component.html'
})
export class FormInstanceComponent {
    @ViewChild(NgForm, {static: true}) ngForm: NgForm;
    @Input() model: Instance = new Instance();
    @Output() submitted: EventEmitter<Instance> = new EventEmitter();

15
    getConfigSearchEnabled(): boolean {
16
17
18
        if (this.model.config && this.model.config.search) {
            return this.model.config.search;
        }
19
20
21
22
        return false;
    }

    getConfigSearchMultipleEnabled(): boolean {
23
24
25
        if (this.model.config && this.model.config.search_multiple) {
            return this.model.config.search_multiple;
        }
26
27
28
        return false;
    }

François Agneray's avatar
François Agneray committed
29
30
31
    emit(instance: Instance) {
        let instanceEmitted: Instance;
        (this.model.name) ? instanceEmitted = {name: this.model.name, ...instance} : instanceEmitted = instance;
32
33
34
35
        instanceEmitted.config = {
            search: this.ngForm.form.value.search,
            search_multiple: this.ngForm.value.search_multiple
        };
François Agneray's avatar
François Agneray committed
36
37
38
        this.submitted.emit(instanceEmitted);
    }
}