diff options
Diffstat (limited to 'src/view/telephone.rs')
-rw-r--r-- | src/view/telephone.rs | 137 |
1 files changed, 24 insertions, 113 deletions
diff --git a/src/view/telephone.rs b/src/view/telephone.rs index 28a6f01..516552e 100644 --- a/src/view/telephone.rs +++ b/src/view/telephone.rs @@ -1,100 +1,14 @@ -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 - } -} +use super::input_objects::telephone::*; +use super::input_objects::VCardPropertyInputObject; +use super::VCardPropertyInputComponent; pub struct TelephoneView { link: ComponentLink<Self>, value: Telephone, oninput: Callback<Telephone>, + errors: Vec<String>, } pub enum Msg { @@ -117,6 +31,18 @@ pub struct Props { //pub errors: Vec<String>, } +impl VCardPropertyInputComponent<properties::Telephone, Telephone> for TelephoneView { + fn get_input_object(&self) -> Telephone { + self.value.clone() + } + fn get_title(&self) -> String { + "Telephone".to_string() + } + fn get_errors(&self) -> Vec<String> { + self.errors.clone() + } +} + impl Component for TelephoneView { type Message = Msg; type Properties = Props; @@ -125,6 +51,7 @@ impl Component for TelephoneView { link, value: Telephone::new(), oninput: props.oninput, + errors: vec![], } } fn update(&mut self, msg: <Self as yew::Component>::Message) -> bool { @@ -151,32 +78,16 @@ impl Component for TelephoneView { 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)) - ) } + { + self.render_errors() + } - { util::text_field_input( - "Extension", - "extension", - None, - self.link.callback(|e: InputData| Msg::UpdateExtension(e.value)) - ) } + <h3 class="subtitle">{ self.get_title() }</h3> - { util::checkbox_field_input( - "Work", - "work", - self.value.work, - self.link.callback(|_| Msg::ToggleWork) - ) } + { + self.get_input_object().render(&self.link) + } - </div> </div> } } |