summaryrefslogtreecommitdiff
path: root/src/viewmodel
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-02-05 18:05:16 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-02-05 18:05:16 +0100
commitfd5b054fe655c81533c8a1138ba55a82a7b9d085 (patch)
tree2d90466a05356490ed3d15fa19e8dc0fe763499e /src/viewmodel
parent87007b8785be959ca7687e2bec7401514e92581d (diff)
downloadwasm-card-fd5b054fe655c81533c8a1138ba55a82a7b9d085.tar.gz
wasm-card-fd5b054fe655c81533c8a1138ba55a82a7b9d085.tar.bz2
add date properties
Diffstat (limited to 'src/viewmodel')
-rw-r--r--src/viewmodel/address.rs8
-rw-r--r--src/viewmodel/dates.rs43
-rw-r--r--src/viewmodel/mod.rs11
-rw-r--r--src/viewmodel/name.rs6
-rw-r--r--src/viewmodel/telephone.rs2
-rw-r--r--src/viewmodel/vcard.rs4
6 files changed, 70 insertions, 4 deletions
diff --git a/src/viewmodel/address.rs b/src/viewmodel/address.rs
index 6fd3173..26e168a 100644
--- a/src/viewmodel/address.rs
+++ b/src/viewmodel/address.rs
@@ -29,6 +29,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
}
}
fn get_input_fields(&self, link: &ComponentLink<AddressView>) -> Vec<VCardPropertyInputField> {
+ let typ = String::from("text");
vec![
VCardPropertyInputField::Text{
label: "Post Office Box".to_string(),
@@ -36,6 +37,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdatePostOfficeBox(e.value)),
value: self.post_office_box.clone(),
+ typ: typ.clone(),
},
VCardPropertyInputField::Text{
label: "Extension".to_string(),
@@ -43,6 +45,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdateExtension(e.value)),
value: self.extension.clone(),
+ typ: typ.clone(),
},
VCardPropertyInputField::Text{
label: "Street".to_string(),
@@ -50,6 +53,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdateStreet(e.value)),
value: self.street.clone(),
+ typ: typ.clone(),
},
VCardPropertyInputField::Text{
label: "Locality".to_string(),
@@ -57,6 +61,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdateLocality(e.value)),
value: self.locality.clone(),
+ typ: typ.clone(),
},
VCardPropertyInputField::Text{
label: "Region".to_string(),
@@ -64,6 +69,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdateRegion(e.value)),
value: self.region.clone(),
+ typ: typ.clone(),
},
VCardPropertyInputField::Text{
label: "Code".to_string(),
@@ -71,6 +77,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdateCode(e.value)),
value: self.code.clone(),
+ typ: typ.clone(),
},
VCardPropertyInputField::Text{
label: "Country".to_string(),
@@ -78,6 +85,7 @@ impl VCardPropertyInputObject<AddressView> for Address {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdateCountry(e.value)),
value: self.country.clone(),
+ typ,
},
VCardPropertyInputField::CheckBox{
label: "Work".to_string(),
diff --git a/src/viewmodel/dates.rs b/src/viewmodel/dates.rs
new file mode 100644
index 0000000..6c7fa37
--- /dev/null
+++ b/src/viewmodel/dates.rs
@@ -0,0 +1,43 @@
+use crate::view::dates::*;
+use super::*;
+
+/// Type that represents the vcard `anniversary` and `birthday` properties.
+#[derive(Clone, Debug)]
+pub struct Dates {
+ pub anniversary: String,
+ pub birthday: String,
+}
+
+impl VCardPropertyInputObject<DatesView> for Dates {
+ fn new() -> Self {
+ Self {
+ anniversary: String::new(),
+ birthday: String::new(),
+ }
+ }
+ fn get_input_fields(&self, link: &yew::html::Scope<DatesView>) -> std::vec::Vec<VCardPropertyInputField> {
+ let typ = String::from("date");
+ vec![
+ VCardPropertyInputField::Text{
+ label: "Anniversary".to_string(),
+ id: Some("anniversary".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| Msg::UpdateAnniversary(e.value)),
+ value: self.anniversary.clone(),
+ typ: typ.clone(),
+ },
+ VCardPropertyInputField::Text{
+ label: "Birthday".to_string(),
+ id: Some("birthday".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| Msg::UpdateBirthday(e.value)),
+ value: self.birthday.clone(),
+ typ,
+ },
+ ]
+ }
+ fn is_empty(&self) -> bool {
+ self.anniversary.is_empty()
+ && self.birthday.is_empty()
+ }
+} \ No newline at end of file
diff --git a/src/viewmodel/mod.rs b/src/viewmodel/mod.rs
index d5d0de3..edd1a8e 100644
--- a/src/viewmodel/mod.rs
+++ b/src/viewmodel/mod.rs
@@ -2,10 +2,11 @@ use yew::prelude::*;
use crate::view::VCardPropertyInputComponent;
pub mod vcard;
+pub mod utility;
pub mod address;
pub mod name;
pub mod telephone;
-pub mod utility;
+pub mod dates;
/// Trait for types that represent the data of a vcard property used inside of a `VCardPropertyInputComponent`.
@@ -48,6 +49,7 @@ pub enum VCardPropertyInputField {
placeholder: Option<String>,
oninput: Callback<InputData>,
value: String,
+ typ: String
},
CheckBox {
label: String,
@@ -67,7 +69,8 @@ impl VCardPropertyInputField {
placeholder,
oninput,
value: _,
- } => Self::text_field_input(label, id, placeholder, oninput),
+ typ,
+ } => Self::text_field_input(label, id, placeholder, oninput, typ),
Self::CheckBox {
label,
id,
@@ -77,7 +80,7 @@ impl VCardPropertyInputField {
}
}
/// Returns an `Html` representation of a text input field with the given parameters.
- fn text_field_input(label: &str, id: &Option<String>, placeholder: &Option<String>, oninput: &Callback<InputData>) -> Html {
+ fn text_field_input(label: &str, id: &Option<String>, placeholder: &Option<String>, oninput: &Callback<InputData>, typ: &str) -> Html {
html!{
<div class="field column
is-one-fifth-widescreen
@@ -87,7 +90,7 @@ impl VCardPropertyInputField {
<label class="label">{ label }</label>
<div class="control">
<input id=id.as_ref().unwrap_or(&"".to_string())
- type="text"
+ type=typ
placeholder=placeholder.as_ref().unwrap_or(&"".to_string())
oninput=oninput
/>
diff --git a/src/viewmodel/name.rs b/src/viewmodel/name.rs
index b6ded60..aa6747c 100644
--- a/src/viewmodel/name.rs
+++ b/src/viewmodel/name.rs
@@ -36,6 +36,7 @@ impl VCardPropertyInputObject<NameView> for Name {
}
}
fn get_input_fields(&self, link: &ComponentLink<NameView>) -> std::vec::Vec<VCardPropertyInputField> {
+ let typ = String::from("text");
vec![
VCardPropertyInputField::Text{
label: "Prefix".to_string(),
@@ -43,6 +44,7 @@ impl VCardPropertyInputObject<NameView> for Name {
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(),
@@ -50,6 +52,7 @@ impl VCardPropertyInputObject<NameView> for Name {
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(),
@@ -57,6 +60,7 @@ impl VCardPropertyInputObject<NameView> for Name {
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(),
@@ -64,6 +68,7 @@ impl VCardPropertyInputObject<NameView> for Name {
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(),
@@ -71,6 +76,7 @@ impl VCardPropertyInputObject<NameView> for Name {
placeholder: Some("CBE FRAS".to_string()),
oninput: link.callback(|e: InputData| Msg::UpdateSuffix(e.value)),
value: self.suffix.clone(),
+ typ,
},
]
}
diff --git a/src/viewmodel/telephone.rs b/src/viewmodel/telephone.rs
index 6c930a2..774b63d 100644
--- a/src/viewmodel/telephone.rs
+++ b/src/viewmodel/telephone.rs
@@ -31,6 +31,7 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone {
}
}
fn get_input_fields(&self, link: &ComponentLink<TelephoneView>) -> Vec<VCardPropertyInputField> {
+ let typ = String::from("tel");
vec![
VCardPropertyInputField::Text{
label: "Number".to_string(),
@@ -38,6 +39,7 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone {
placeholder: None,
oninput: link.callback(|e: InputData| Msg::UpdateNumber(e.value)),
value: self.number.clone(),
+ typ,
},
VCardPropertyInputField::CheckBox{
label: "Work".to_string(),
diff --git a/src/viewmodel/vcard.rs b/src/viewmodel/vcard.rs
index 2b81fd8..565b1ff 100644
--- a/src/viewmodel/vcard.rs
+++ b/src/viewmodel/vcard.rs
@@ -1,3 +1,4 @@
+use crate::viewmodel::dates::Dates;
use crate::viewmodel::telephone::Telephone;
use crate::viewmodel::address::Address;
use crate::viewmodel::name::Name;
@@ -8,6 +9,7 @@ pub struct VCardData {
pub names: Vec<Name>,
pub addresses: Vec<Address>,
pub telephones: Vec<Telephone>,
+ pub datess: Vec<Dates>,
}
macro_rules! make_vec_adder_fn {
@@ -24,9 +26,11 @@ impl VCardData {
names: Vec::new(),
addresses: Vec::new(),
telephones: Vec::new(),
+ datess: Vec::new(),
}
}
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_dates datess => dates: Dates );
} \ No newline at end of file