diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-26 16:46:50 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-26 16:46:50 +0100 |
commit | b7875dc4072abeec26f93b3d322d00cecff23cfb (patch) | |
tree | 78c70a075642ec67aa85e1c3dfb04d72e632c3ec /src/model/property_groups/communication.rs | |
parent | ac31460bac3c050abe1e45ec975f3537d1937751 (diff) | |
download | wasm-card-b7875dc4072abeec26f93b3d322d00cecff23cfb.tar.gz wasm-card-b7875dc4072abeec26f93b3d322d00cecff23cfb.tar.bz2 |
add communication property
Diffstat (limited to 'src/model/property_groups/communication.rs')
-rw-r--r-- | src/model/property_groups/communication.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/model/property_groups/communication.rs b/src/model/property_groups/communication.rs new file mode 100644 index 0000000..82fce2a --- /dev/null +++ b/src/model/property_groups/communication.rs @@ -0,0 +1,71 @@ +use crate::model::input_fields::VCardPropertyInputField; +use crate::model::*; + +#[derive(Clone, Debug, PartialEq)] +pub struct Communication { + pub email_address: String, + pub impp: String, +} + +#[derive(Clone, PartialEq)] +pub enum CommunicationMsg { + UpdateEmailAddress(String), + UpdateImpp(String), + + Generate, +} + +impl VCardPropertyInputGroupObject<CommunicationMsg> for Communication { + fn new() -> Self { + Self { + email_address: String::new(), + impp: String::new(), + } + } + fn get_title(&self) -> String { + String::from("Communication") + } + fn get_input_fields( + &self, + link: &yew::html::Scope<PropertyGroupInputComponent<Self, CommunicationMsg>>, + ) -> Vec<VCardPropertyInputField> { + vec![ + VCardPropertyInputField::Text { + label: "Email Address".to_string(), + id: Some("email_address".to_string()), + placeholder: None, + oninput: link + .callback(|e: InputData| CommunicationMsg::UpdateEmailAddress(e.value)), + value: self.email_address.clone(), + typ: String::from("email"), + }, + VCardPropertyInputField::Text { + label: "Instant Messaging URI".to_string(), + id: Some("impp".to_string()), + placeholder: None, + oninput: link.callback(|e: InputData| CommunicationMsg::UpdateImpp(e.value)), + value: self.impp.clone(), + typ: String::from("text"), + }, + ] + } + fn update( + &mut self, + props: InputProps<Self, CommunicationMsg>, + msg: <PropertyGroupInputComponent<Self, CommunicationMsg> as yew::Component>::Message, + ) -> bool { + match msg { + CommunicationMsg::UpdateEmailAddress(a) => self.email_address = a, + CommunicationMsg::UpdateImpp(i) => self.impp = i, + + CommunicationMsg::Generate => { + props.generated.emit(self.clone()); + } + }; + + true + } + fn is_empty(&self) -> bool { + self.email_address.is_empty() && self.impp.is_empty() + } +} |