1
use crate::app::App;
2
use crate::form::{Form, FormSubmit, validate};
3
use crate::modal::{ConfirmAction, Modal};
4
use crate::view::Tab;
5

            
6
2
pub(super) fn execute_confirm(app: &mut App, action: ConfirmAction) {
7
2
    match action {
8
2
        ConfirmAction::DeleteTransaction(id) => {
9
2
            app.submit_delete_transaction(&id);
10
2
        }
11
    }
12
2
}
13

            
14
pub(super) fn submit_form(app: &mut App, form: Form) {
15
    match validate(&form) {
16
        Err(msg) => {
17
            app.set_status(msg);
18
            app.overlays.push(Modal::Form(form));
19
        }
20
        Ok(FormSubmit::Report {
21
            kind,
22
            from,
23
            to,
24
            chart,
25
        }) => {
26
            app.switch_tab(Tab::Reports);
27
            app.fetch_report(kind, &from, &to, &chart);
28
        }
29
        Ok(FormSubmit::ConfigSet { key, value }) => {
30
            if !app.submit_config_set(&key, &value) {
31
                app.overlays.push(Modal::Form(form));
32
            }
33
        }
34
        Ok(FormSubmit::CommodityCreate { symbol, name }) => {
35
            if !app.submit_commodity_create(&symbol, &name) {
36
                app.overlays.push(Modal::Form(form));
37
            }
38
        }
39
        Ok(FormSubmit::CommodityConvert {
40
            amount_num_denom,
41
            amount_str,
42
            from,
43
            from_label,
44
            to,
45
            to_label,
46
        }) => {
47
            if !app.submit_commodity_convert(
48
                &amount_num_denom,
49
                &amount_str,
50
                &from,
51
                &from_label,
52
                &to,
53
                &to_label,
54
            ) {
55
                app.overlays.push(Modal::Form(form));
56
            }
57
        }
58
        Ok(FormSubmit::AccountCreate { name, parent }) => {
59
            if !app.submit_account_create(&name, parent.as_deref()) {
60
                app.overlays.push(Modal::Form(form));
61
            }
62
        }
63
        Ok(FormSubmit::TransactionCreate { note, date, splits }) => {
64
            if !app.submit_transaction_create(&splits, &note, &date) {
65
                app.overlays.push(Modal::Form(form));
66
            }
67
        }
68
        Ok(FormSubmit::TransactionEdit {
69
            id,
70
            note,
71
            date,
72
            splits,
73
        }) => {
74
            if !app.submit_transaction_edit(&id, &splits, &note, &date) {
75
                app.overlays.push(Modal::Form(form));
76
            }
77
        }
78
        Ok(FormSubmit::AccountTag {
79
            account_id,
80
            name,
81
            value,
82
        }) => {
83
            if !app.submit_account_tag(&account_id, &name, &value) {
84
                app.overlays.push(Modal::Form(form));
85
            }
86
        }
87
        Ok(FormSubmit::TransactionTag {
88
            transaction_id,
89
            name,
90
            value,
91
        }) => {
92
            if !app.submit_transaction_tag(&transaction_id, &name, &value) {
93
                app.overlays.push(Modal::Form(form));
94
            }
95
        }
96
    }
97
}