diff options
author | jelemux <jeremias.weber@protonmail.com> | 2020-11-25 10:31:04 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2020-11-25 10:31:04 +0100 |
commit | b1ba906491a1ed396d47b0751f080fef991ea344 (patch) | |
tree | c8e306c217dbdc352e66000822d8fc7e4cdc55fb /src/view/input_objects/address.rs | |
parent | 5a03734b6767fed04c0913384584d8f59dc597ea (diff) | |
download | wasm-card-b1ba906491a1ed396d47b0751f080fef991ea344.tar.gz wasm-card-b1ba906491a1ed396d47b0751f080fef991ea344.tar.bz2 |
Struktur umbauen
Diffstat (limited to 'src/view/input_objects/address.rs')
-rw-r--r-- | src/view/input_objects/address.rs | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/src/view/input_objects/address.rs b/src/view/input_objects/address.rs deleted file mode 100644 index 3975200..0000000 --- a/src/view/input_objects/address.rs +++ /dev/null @@ -1,151 +0,0 @@ -use vcard::properties; -use vcard::parameters; -use vcard::values::{self, text}; -use std::collections::HashSet; -use super::*; -use super::super::address::*; - -#[derive(Clone)] -pub struct Address { - pub post_office_box: String, - pub extension: String, - pub street: String, - pub locality: String, - pub region: String, - pub code: String, - pub country: String, - pub work: bool, - pub home: bool, -} - -impl VCardPropertyInputObject<properties::Address, AddressView> for Address { - fn new() -> Self { - Self { - post_office_box: String::new(), - extension: String::new(), - street: String::new(), - locality: String::new(), - region: String::new(), - code: String::new(), - country: String::new(), - work: false, - home: false, - } - } - fn get_input_fields(&self, link: &ComponentLink<AddressView>) -> Vec<VCardPropertyInputField> { - vec![ - VCardPropertyInputField::Text{ - label: "Post Office Box".to_string(), - id: Some("post_office_box".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdatePostOfficeBox(e.value)), - value: self.post_office_box.clone(), - }, - VCardPropertyInputField::Text{ - label: "Extension".to_string(), - id: Some("extension".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdateExtension(e.value)), - value: self.extension.clone(), - }, - VCardPropertyInputField::Text{ - label: "Street".to_string(), - id: Some("street".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdateStreet(e.value)), - value: self.street.clone(), - }, - VCardPropertyInputField::Text{ - label: "Locality".to_string(), - id: Some("locality".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdateLocality(e.value)), - value: self.locality.clone(), - }, - VCardPropertyInputField::Text{ - label: "Region".to_string(), - id: Some("region".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdateRegion(e.value)), - value: self.region.clone(), - }, - VCardPropertyInputField::Text{ - label: "Code".to_string(), - id: Some("code".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdateCode(e.value)), - value: self.code.clone(), - }, - VCardPropertyInputField::Text{ - label: "Country".to_string(), - id: Some("country".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdateCountry(e.value)), - value: self.country.clone(), - }, - 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, - }, - ] - } - fn to_vcard_property(&self) -> Result<properties::Address, VCardPropertyInputError> { - let address_value = values::address_value::AddressValue::from_components( - match self.post_office_box.is_empty() { - true => None, - false => Some(text::Component::from_str(&self.post_office_box).unwrap()), - }, - match self.extension.is_empty() { - true => None, - false => Some(text::Component::from_str(&self.extension).unwrap()), - }, - match self.street.is_empty() { - true => None, - false => Some(text::Component::from_str(&self.street).unwrap()), - }, - match self.locality.is_empty() { - true => None, - false => Some(text::Component::from_str(&self.locality).unwrap()), - }, - match self.region.is_empty() { - true => None, - false => Some(text::Component::from_str(&self.region).unwrap()), - }, - match self.code.is_empty() { - true => None, - false => Some(text::Component::from_str(&self.code).unwrap()), - }, - match self.country.is_empty() { - true => None, - false => Some(text::Component::from_str(&self.country).unwrap()), - }, - ); - - let mut address = properties::Address::from_address_value(address_value); - - let type_values = { - let mut type_values = HashSet::new(); - - if self.work { - type_values.insert(values::type_value::TypeValue::Work); - } - if self.home { - type_values.insert(values::type_value::TypeValue::Home); - } - - vcard::Set::from_hash_set(type_values).unwrap() - }; - - address.typ = Some(parameters::typ::Type::from_type_values(type_values)); - - Ok(address) - } -}
\ No newline at end of file |