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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
use yew::services::ConsoleService;
use yew::prelude::*;
use vcard::properties;
use vcard::parameters;
use vcard::values::{self, text};
use vcard::validators::ValidatedWrapper;
use std::collections::HashSet;
use crate::util;
#[derive(Clone)]
pub struct Telephone {
pub number: String,
pub extension: 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 Telephone {
pub fn new() -> Self {
Self {
number: String::new(),
extension: String::new(),
work: false,
home: false,
text: false,
voice: false,
fax: false,
cell: false,
video: false,
pager: false,
text_phone: false,
}
}
pub fn to_vcard_value(&self) -> properties::Telephone {
let mut telephone = properties::Telephone::from_telephone_value(
values::telephone_value::TelephoneValue::from_telephone_number_str(
self.number.clone(),
match self.extension.is_empty() {
true => None::<&str>,
false => Some(&self.extension),
},
).unwrap()
);
let type_values = {
let mut type_values = HashSet::new();
if self.work {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Work);
}
if self.home {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Home);
}
if self.text {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Text);
}
if self.voice {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Voice);
}
if self.fax {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Fax);
}
if self.cell {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Cell);
}
if self.video {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Video);
}
if self.pager {
type_values.insert(values::type_value::TypeValueWithTelephoneType::Pager);
}
if self.text_phone {
type_values.insert(values::type_value::TypeValueWithTelephoneType::TextPhone);
}
vcard::Set::from_hash_set(type_values).unwrap()
};
if let properties::Telephone::TelephoneValue { ref mut typ, .. } = telephone {
*typ = Some(parameters::typ::TypeWithTelType::from_type_values(type_values));
}
telephone
}
}
pub struct TelephoneView {
link: ComponentLink<Self>,
value: Telephone,
oninput: Callback<Telephone>,
}
pub enum Msg {
UpdateNumber(String),
UpdateExtension(String),
ToggleWork,
ToggleHome,
ToggleText,
ToggleVoice,
ToggleFax,
ToggleCell,
ToggleVideo,
TogglePager,
ToggleTextPhone,
}
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
pub oninput: Callback<Telephone>,
//pub errors: Vec<String>,
}
impl Component for TelephoneView {
type Message = Msg;
type Properties = Props;
fn create(props: <Self as yew::Component>::Properties, link: yew::html::Scope<Self>) -> Self {
Self {
link,
value: Telephone::new(),
oninput: props.oninput,
}
}
fn update(&mut self, msg: <Self as yew::Component>::Message) -> bool {
match msg {
Msg::UpdateNumber(n) => self.value.number = n,
Msg::UpdateExtension(e) => self.value.extension = e,
Msg::ToggleWork => self.value.work = !self.value.work,
Msg::ToggleHome => self.value.home = !self.value.home,
Msg::ToggleText => self.value.text = !self.value.text,
Msg::ToggleVoice => self.value.voice = !self.value.voice,
Msg::ToggleFax => self.value.fax = !self.value.fax,
Msg::ToggleCell => self.value.cell = !self.value.cell,
Msg::ToggleVideo => self.value.video = !self.value.video,
Msg::TogglePager => self.value.pager = !self.value.pager,
Msg::ToggleTextPhone => self.value.text_phone = !self.value.text_phone,
};
self.oninput.emit(self.value.clone());
true
}
fn change(&mut self, props: <Self as yew::Component>::Properties) -> bool {
self.oninput = props.oninput;
true
}
fn view(&self) -> yew::virtual_dom::VNode {
html!{
<div class="box">
<h3 class="subtitle">{ "Telephone" }</h3>
<div class="columns is-mobile is-multiline">
{ util::text_field_input(
"Number",
"number",
None,
self.link.callback(|e: InputData| Msg::UpdateNumber(e.value))
) }
{ util::text_field_input(
"Extension",
"extension",
None,
self.link.callback(|e: InputData| Msg::UpdateExtension(e.value))
) }
{ util::checkbox_field_input(
"Work",
"work",
self.value.work,
self.link.callback(|_| Msg::ToggleWork)
) }
</div>
</div>
}
}
}
|