diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-17 17:06:48 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-17 17:06:48 +0100 |
commit | cb310a66e94db4e0c4f7d0373a670156b012412a (patch) | |
tree | 501fd4ed17d892d693d4123fffaca8d942144e3b /src/viewmodel/name.rs | |
parent | be3367dd2921eb30ae7970d233b83ac3af861952 (diff) | |
parent | 0660151a8b641fa0a23dde2598132029970f7ae4 (diff) | |
download | wasm-card-cb310a66e94db4e0c4f7d0373a670156b012412a.tar.gz wasm-card-cb310a66e94db4e0c4f7d0373a670156b012412a.tar.bz2 |
Merge branch 'main' of codeberg.org:jelemux/wasm-card
Diffstat (limited to 'src/viewmodel/name.rs')
-rw-r--r-- | src/viewmodel/name.rs | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/src/viewmodel/name.rs b/src/viewmodel/name.rs deleted file mode 100644 index de0aa81..0000000 --- a/src/viewmodel/name.rs +++ /dev/null @@ -1,119 +0,0 @@ -use super::*; -use crate::view::name::*; - -/// Type that represents a vcard `name` property -/// -/// # Examples -/// ``` -/// # use bcard_wasm_webapp::viewmodel::name::Name; -/// # use crate::bcard_wasm_webapp::viewmodel::VCardPropertyInputObject; -/// let mut name = Name::new(); -/// name.prefix = String::from("Sir"); -/// name.first_name = String::from("Arthur"); -/// name.middle_name = String::from("Charles"); -/// name.last_name = String::from("Clarke"); -/// name.suffix = String::from("CBE FRAS"); -/// -/// assert_eq!(name.generate_fn(), String::from("Sir Arthur Charles Clarke, CBE FRAS")); -/// ``` -#[derive(Clone, Debug, PartialEq)] -pub struct Name { - pub prefix: String, - pub first_name: String, - pub middle_name: String, - pub last_name: String, - pub suffix: String, -} - -impl VCardPropertyInputObject<NameView> for Name { - fn new() -> Self { - Self { - prefix: String::new(), - first_name: String::new(), - middle_name: String::new(), - last_name: String::new(), - suffix: String::new(), - } - } - fn get_input_fields( - &self, - link: &ComponentLink<NameView>, - ) -> std::vec::Vec<VCardPropertyInputField> { - let typ = String::from("text"); - vec![ - VCardPropertyInputField::Text { - label: "Prefix".to_string(), - id: Some("prefix".to_string()), - placeholder: Some("Sir".to_string()), - oninput: link.callback(|e: InputData| Msg::UpdatePrefix(e.value)), - value: self.prefix.clone(), - typ: typ.clone(), - }, - VCardPropertyInputField::Text { - label: "First Name".to_string(), - id: Some("first_name".to_string()), - placeholder: Some("Arthur".to_string()), - oninput: link.callback(|e: InputData| Msg::UpdateFirstName(e.value)), - value: self.first_name.clone(), - typ: typ.clone(), - }, - VCardPropertyInputField::Text { - label: "Middle Name".to_string(), - id: Some("middle_name".to_string()), - placeholder: Some("Charles".to_string()), - oninput: link.callback(|e: InputData| Msg::UpdateMiddleName(e.value)), - value: self.middle_name.clone(), - typ: typ.clone(), - }, - VCardPropertyInputField::Text { - label: "Last Name".to_string(), - id: Some("last_name".to_string()), - placeholder: Some("Clarke".to_string()), - oninput: link.callback(|e: InputData| Msg::UpdateLastName(e.value)), - value: self.last_name.clone(), - typ: typ.clone(), - }, - VCardPropertyInputField::Text { - label: "Suffix".to_string(), - id: Some("suffix".to_string()), - placeholder: Some("CBE FRAS".to_string()), - oninput: link.callback(|e: InputData| Msg::UpdateSuffix(e.value)), - value: self.suffix.clone(), - typ, - }, - ] - } - fn is_empty(&self) -> bool { - self.prefix.is_empty() - && self.first_name.is_empty() - && self.middle_name.is_empty() - && self.last_name.is_empty() - && self.suffix.is_empty() - } -} - -impl Name { - pub fn generate_fn(&self) -> String { - let mut full_name = String::new(); - - full_name.push_str(&self.prefix); - if !self.first_name.is_empty() { - full_name.push_str(" "); - full_name.push_str(&self.first_name); - } - if !self.middle_name.is_empty() { - full_name.push_str(" "); - full_name.push_str(&self.middle_name); - } - if !self.last_name.is_empty() { - full_name.push_str(" "); - full_name.push_str(&self.last_name); - } - if !self.suffix.is_empty() { - full_name.push_str(", "); - full_name.push_str(&self.suffix); - } - - full_name - } -} |