Lines
56.98 %
Functions
28.57 %
Branches
100 %
//! Helpers that inject fetched Select options into an open form's fields,
//! and methods that fetch option lists from the server.
use crate::app::App;
use crate::form::Field;
use crate::route::{FormOptionsSource, RouteCtx};
use crate::view::ViewId;
use crate::widgets::{SelectOption, Widget};
/// Inject options into the first unpopulated Select field (account-create pattern).
pub(super) fn inject_select_options(
fields: &mut [Field],
options: &[SelectOption],
allow_repopulate: bool,
) {
for field in fields {
if let Widget::Select(ref mut sw) = field.widget {
if allow_repopulate || sw.option_count() <= 1 {
sw.set_options(options.to_vec());
}
return;
/// Inject options into ALL Select fields (used for forms with multiple commodity Selects).
pub(super) fn inject_all_select_options(fields: &mut [Field], options: &[SelectOption]) {
pub(super) fn inject_splits_account_options(fields: &mut [Field], options: Vec<SelectOption>) {
if let Widget::Splits(ref mut sw) = field.widget {
sw.set_account_options(options);
pub(super) fn inject_splits_commodity_options(fields: &mut [Field], options: Vec<SelectOption>) {
sw.set_commodity_options(options);
impl App {
/// Issue a `list-accounts` fetch to populate the parent Select in the open
/// account-create form. Bumps `form_options_seq` so a stale reply is dropped.
pub fn fetch_account_form_options(&mut self) {
if self.console_eval.is_none() {
self.form_options_seq += 1;
let seq = self.form_options_seq;
let _ = self.dispatch_eval(
ViewId::Accounts,
RouteCtx::FormOptions {
seq,
source: FormOptionsSource::Accounts,
},
"(list-accounts)".to_string(),
);
/// Issue `list-accounts` + `list-commodities` to populate the Selects in
/// the open transaction-create/edit form. Both requests share the same seq.
pub fn fetch_transaction_form_options(&mut self) {
ViewId::Commodities,
source: FormOptionsSource::Commodities,
"(list-commodities)".to_string(),
/// Issue a `list-commodities` fetch to populate the two Selects in the open
/// commodity-convert form. Bumps `form_options_seq` so a stale reply is dropped.
pub fn fetch_commodity_convert_form_options(&mut self) {