summaryrefslogtreecommitdiff
path: root/src/viewmodel/telephone.rs
blob: 44b938fcfb4355e49cee0a03eee2b92684ded089 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use super::*;
use crate::view::telephone::*;

#[derive(Clone, Debug, PartialEq)]
pub struct Telephone {
    pub number: String,
    pub work: bool,
    pub home: bool,
    pub text: bool,
    pub voice: bool,
    pub fax: bool,
    pub cell: bool,
    pub video: bool,
    pub pager: bool,
    pub text_phone: bool,
}

impl VCardPropertyInputObject<TelephoneView> for Telephone {
    fn new() -> Self {
        Self {
            number: String::new(),
            work: false,
            home: false,
            text: false,
            voice: false,
            fax: false,
            cell: false,
            video: false,
            pager: false,
            text_phone: false,
        }
    }
    fn get_input_fields(
        &self,
        link: &ComponentLink<TelephoneView>,
    ) -> Vec<VCardPropertyInputField> {
        let typ = String::from("tel");
        vec![
            VCardPropertyInputField::Text {
                label: "Number".to_string(),
                id: Some("number".to_string()),
                placeholder: None,
                oninput: link.callback(|e: InputData| Msg::UpdateNumber(e.value)),
                value: self.number.clone(),
                typ,
            },
            VCardPropertyInputField::CheckBox {
                label: "Work".to_string(),
                id: Some("work".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleWork),
                value: self.work,
            },
            VCardPropertyInputField::CheckBox {
                label: "Home".to_string(),
                id: Some("home".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleHome),
                value: self.home,
            },
            VCardPropertyInputField::CheckBox {
                label: "Text".to_string(),
                id: Some("text".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleText),
                value: self.text,
            },
            VCardPropertyInputField::CheckBox {
                label: "Voice".to_string(),
                id: Some("voice".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleVoice),
                value: self.voice,
            },
            VCardPropertyInputField::CheckBox {
                label: "Fax".to_string(),
                id: Some("fax".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleFax),
                value: self.fax,
            },
            VCardPropertyInputField::CheckBox {
                label: "Cell".to_string(),
                id: Some("cell".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleCell),
                value: self.cell,
            },
            VCardPropertyInputField::CheckBox {
                label: "Video".to_string(),
                id: Some("video".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleVideo),
                value: self.video,
            },
            VCardPropertyInputField::CheckBox {
                label: "Pager".to_string(),
                id: Some("pager".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::TogglePager),
                value: self.pager,
            },
            VCardPropertyInputField::CheckBox {
                label: "Text Phone".to_string(),
                id: Some("text_phone".to_string()),
                onclick: link.callback(|_: MouseEvent| Msg::ToggleTextPhone),
                value: self.text_phone,
            },
        ]
    }
    fn is_empty(&self) -> bool {
        self.number.is_empty()
    }
}