import { Component, OnInit, ViewChild } from '@angular/core'; import { LookupsService } from 'src/app/shared/services/lookups.service'; import { FeedbackPanelComponent } from 'src/app/shared/components/feedback-panel/feedback-panel.component'; import { Currency } from 'tournee.businesslogic'; @Component({ selector: 'app-system-admin-lookups-currency', templateUrl: './system-admin-lookups-currency.component.html', styleUrls: ['./system-admin-lookups-currency.component.css'] }) export class SystemAdminLookupsCurrencyComponent implements OnInit { @ViewChild('FeedbackPanel') FeedbackPanel:FeedbackPanelComponent; isWorking: boolean = false; Expanded: boolean = false; Currencies: Array = []; EditModel: Currency = new Currency(); constructor(private lookups: LookupsService) { } ngOnInit() { this.load() } toggle() { this.Expanded = !this.Expanded; } load() { if (this.isWorking) { return; } this.isWorking = true; this.lookups.get(this.EditModel.getType()) .then((result) => { this.Currencies = result.result.map((c) => { return new Currency(c); }); this.isWorking = false; }) .catch((err) => { this.isWorking = false; console.log(err); }); } save() { if (this.isWorking) { return; } this.isWorking = true; if (this.EditModel.id) { this.edit(); } else { this.add(); } } add() { this.lookups.add(this.EditModel) .then((result) => { this.Currencies = result.result.map((c) => { return new Currency(c); }); this.isWorking = false; this.reset(); this.FeedbackPanel.triggerSuccess("Currency Saved Successfully"); }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } edit() { this.lookups.update(this.EditModel) .then((result) => { this.Currencies = result.result.map((c) => { return new Currency(c); }); this.isWorking = false; this.reset(); this.FeedbackPanel.triggerSuccess("Currency Saved Successfully"); }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } beginEdit(currency) { this.EditModel.name = currency.name; this.EditModel.currency_code = currency.currency_code; this.EditModel.currency_symbol = currency.currency_symbol; this.EditModel.id = currency.id; } reset() { this.EditModel.name = null; this.EditModel.currency_code = null; this.EditModel.currency_symbol = null; this.EditModel.id = null; } }