@fleetbase/ember-ui
Version:
Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.
51 lines (38 loc) • 1.48 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import getCurrency from '../utils/get-currency';
export default class CurrencySelectComponent extends Component {
currentUser;
currencies = getCurrency();
currency;
currencyData;
constructor() {
super(...arguments);
let whois = this.currentUser.getOption('whois');
this.currency = this.args.currency ?? this.args.value ?? whois?.currency?.code ?? 'USD';
this.currencyData = this.args.currencyData ?? getCurrency(this.currency);
}
onChange(currency) {
const { onChange, onCurrencyChange, onSelect } = this.args;
this.currency = currency.code;
this.currencyData = currency;
if (typeof onCurrencyChange === 'function') {
onCurrencyChange(currency.code, currency);
}
if (typeof onSelect === 'function') {
onSelect(currency.code, currency);
}
if (typeof onChange === 'function') {
onChange(currency);
}
}
searchCurrencies(currency, term) {
if (!term || typeof term !== 'string') {
return -1;
}
let name = `${currency.title} ${currency.code} ${currency.iso2}`.toLowerCase();
return name.indexOf(term.toLowerCase());
}
}