import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core'; import { TournamentTicketAllocationRuleFormComponent } from '../../forms/tournament-ticket-allocation-rule-form/tournament-ticket-allocation-rule-form.component'; import { TicketAllocationRule, TournamentTicket, Tournament } from 'tournee.businesslogic'; @Component({ selector: 'app-selectable-listing-tournament-ticket-allocation-rules', templateUrl: './selectable-listing-tournament-ticket-allocation-rules.component.html', styleUrls: ['./selectable-listing-tournament-ticket-allocation-rules.component.css'] }) export class SelectableListingTournamentTicketAllocationRulesComponent implements OnInit { @ViewChild('ruleForm') RuleForm: TournamentTicketAllocationRuleFormComponent; @Input() Ticket: TournamentTicket; @Input() Tournament: Tournament; @Output() OnShown = new EventEmitter(); @Output() OnHidden = new EventEmitter(); SelectedRule: TicketAllocationRule; constructor() { } ngOnInit() { } add() { this.edit(TicketAllocationRule.create(this.Ticket), true); } store(rule: TicketAllocationRule) { this.Ticket.storeRule(rule); this.hide(); } hide() { this.SelectedRule = null; this.RuleForm.reset(); this.OnHidden.emit(); } edit(rule: TicketAllocationRule, isNew = false) { this.SelectedRule = new TicketAllocationRule(JSON.parse(JSON.stringify(rule))); this.RuleForm.initiate(this.Tournament, this.Ticket, this.SelectedRule, isNew); this.OnShown.emit(); } delete(rule: TicketAllocationRule) { this.Ticket.removeRule(rule); } }