1
//! Loading the values of a form from a stored entity.
2

            
3
use forms::{Form, FormValues};
4
use uuid::Uuid;
5

            
6
use super::Failure;
7
use super::account_edit_load::load_account_edit;
8
use super::commodity_edit_load::load_commodity_edit;
9
use super::handler::{Handler, unknown};
10
use super::script_edit_load::load_script_edit;
11
use super::tag_edit_load::load_tag_edit;
12
use super::template_edit_load::load_template_edit;
13
use super::transaction_create_load::load_transaction_create;
14
use super::transaction_edit_load::load_transaction_edit;
15

            
16
/// The values of the compiled-in form `form` for the entity `id`.
17
28739
pub async fn load(user_id: Uuid, form: &Form, id: &str) -> Result<FormValues, Failure> {
18
28739
    match Handler::of(form)? {
19
12115
        Handler::TransactionEdit => load_transaction_edit(user_id, id).await,
20
3854
        Handler::TransactionCreate => load_transaction_create(user_id, id).await,
21
3084
        Handler::AccountEdit => load_account_edit(user_id, id).await,
22
2440
        Handler::CommodityEdit => load_commodity_edit(user_id, id).await,
23
3052
        Handler::TagEdit => load_tag_edit(user_id, id).await,
24
2894
        Handler::TemplateEdit => load_template_edit(user_id, id).await,
25
1299
        Handler::ScriptEdit => load_script_edit(user_id, id)
26
1299
            .await
27
            .map(|(values, _)| values),
28
        Handler::TransactionQuery
29
        | Handler::ReportBalance
30
        | Handler::ReportActivity
31
        | Handler::ReportCategory
32
        | Handler::AccountMerge
33
        | Handler::AccountCreate
34
        | Handler::CommodityCreate
35
        | Handler::TagCreate
36
        | Handler::TemplateCreate
37
        | Handler::ScriptCreate
38
        | Handler::SshKeyAdd
39
        | Handler::TemplateTest
40
        | Handler::ConfigSet
41
1
        | Handler::Convert => Err(unknown(form.name)),
42
    }
43
28739
}