import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core'; import { AttendeeLocationGroupFormComponent } from '../../forms/attendee-location-group-form/attendee-location-group-form.component'; import { AttendeeLocationGroup, Tournament } from 'tournee.businesslogic'; @Component({ selector: 'app-selectable-listing-location-groups', templateUrl: './selectable-listing-location-groups.component.html', styleUrls: ['./selectable-listing-location-groups.component.css'] }) export class SelectableListingLocationGroupsComponent implements OnInit { @ViewChild('Form') Form: AttendeeLocationGroupFormComponent; @Input() EditModel: Tournament; @Output() OnHidden = new EventEmitter(); @Output() OnShown = new EventEmitter(); Selected: AttendeeLocationGroup; constructor() { } ngOnInit() { } add() { this.edit(AttendeeLocationGroup.create(), true); } store(grouping: AttendeeLocationGroup) { this.EditModel.storeGrouping(grouping); this.hide(); } hide() { this.Selected = null; this.Form.reset(); this.OnHidden.emit(); } edit(grouping: AttendeeLocationGroup, isNew = false) { this.Selected = new AttendeeLocationGroup(JSON.parse(JSON.stringify(grouping))); const wildcard_disabled = this.EditModel.location_groups.some((lg) => { return lg.wildcard == true; }); this.Form.initiate(this.Selected, wildcard_disabled, isNew); this.OnShown.emit(); } delete(grouping: AttendeeLocationGroup) { this.EditModel.removeGrouping(grouping); } }