yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { DialogSOP } from '../../libappsop/dialogsop';
import { DateTimeSelectorSOP } from '../../libappsop/datetimeselectorsop';
import { EditFieldSOP } from '../../libappsop/editfieldsop';
import { LabelSOP } from '../../libappsop/labelsop';
import { DropDownListSOP } from '../../libappsop/dropdownlistsop';
 
export interface DialogCurrencyRateFields {
  Currency?: string;
  Start?: string;
  Rate?: string;
  RateLabel?: string;
}
 
/**
 * Currency rate dialog.
 */
export class DialogCurrencyRate extends DialogSOP<DialogCurrencyRateFields> {
  private readonly _ddlCurrency = new DropDownListSOP('DropDownListCurrency');
  private readonly _dtsStart = new DateTimeSelectorSOP('dsStart');
  private readonly _efRate = new EditFieldSOP('EditFieldRate');
  private readonly _labelRate = new LabelSOP('LabelRate');
 
  public constructor() {
    super('DialogCreateEditCurrencyRate');
 
    // Set UI element mapping to pair the UI name to the UI element for use in DialogSOP to find the UI object to set value or verify value
    // This prevents each new Dialog to duplicate code just to set/verify UI element value
    this._uiMap.set('Currency', this._ddlCurrency);
    this._uiMap.set('Start', this._dtsStart);
    this._uiMap.set('Rate', this._efRate);
    this._uiMap.set('RateLabel', this._labelRate);
  }
 
  /**
   * Gets the currency rate label text by specifying the default and source currency.
   *
   * @param defautltCurrency Base currency.
   * @param sourceCurrency Source currency against base currency.
   * @returns Currency rate in the form '<defautltCurrency> to 1 <sourceCurrency>'
   */
  public getLabelRateFormat(defautltCurrency: string, sourceCurrency: string): string {
    return `${defautltCurrency} to 1 ${sourceCurrency}`;
  }
}
 
/**
 * Expected tooltip for OK button when disabled.
 */
export const okButtonDisabledTooltip = {
  // Partial prefix indicates precondition defined partially thus use partial match when verifying.
  partialRateMustGreaterZero: (rate: string): string => `Rate (${rate}) must be greater than 0.`,
  partialRateMustUnique: (): string => 'Currency rate must be unique by currency and start.',
};