From b7875dc4072abeec26f93b3d322d00cecff23cfb Mon Sep 17 00:00:00 2001 From: jelemux Date: Fri, 26 Feb 2021 16:46:50 +0100 Subject: add communication property --- src/model/property_groups/communication.rs | 71 ++++++++++++++++++++++++++++++ src/model/property_groups/mod.rs | 1 + src/model/vcard.rs | 4 ++ 3 files changed, 76 insertions(+) create mode 100644 src/model/property_groups/communication.rs (limited to 'src/model') 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 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>, + ) -> Vec { + 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, + msg: 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() + } +} diff --git a/src/model/property_groups/mod.rs b/src/model/property_groups/mod.rs index 3bfc9f3..ec4e87f 100644 --- a/src/model/property_groups/mod.rs +++ b/src/model/property_groups/mod.rs @@ -1,4 +1,5 @@ pub mod address; +pub mod communication; pub mod name; pub mod organizational; pub mod other_identification; diff --git a/src/model/vcard.rs b/src/model/vcard.rs index 24a47ff..4670fe7 100644 --- a/src/model/vcard.rs +++ b/src/model/vcard.rs @@ -1,4 +1,5 @@ use crate::model::property_groups::address::Address; +use crate::model::property_groups::communication::Communication; use crate::model::property_groups::name::Name; use crate::model::property_groups::organizational::Organizational; use crate::model::property_groups::other_identification::OtherIdentification; @@ -10,6 +11,7 @@ pub struct VCardData { pub names: Vec, pub addresses: Vec
, pub telephones: Vec, + pub communications: Vec, pub other_identifications: Vec, pub organizationals: Vec, } @@ -28,6 +30,7 @@ impl VCardData { names: Vec::new(), addresses: Vec::new(), telephones: Vec::new(), + communications: Vec::new(), other_identifications: Vec::new(), organizationals: Vec::new(), } @@ -35,6 +38,7 @@ impl VCardData { make_vec_adder_fn!( fn add_name names => name: Name ); make_vec_adder_fn!( fn add_address addresses => address: Address ); make_vec_adder_fn!( fn add_telephone telephones => telephone: Telephone ); + make_vec_adder_fn!( fn add_communication communications => communication: Communication ); make_vec_adder_fn!( fn add_other_identification other_identifications => other_identification: OtherIdentification ); make_vec_adder_fn!( fn add_organizational organizationals => organizational: Organizational ); } -- cgit v1.2.3