summaryrefslogtreecommitdiff
path: root/src/view/input_objects/telephone.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2020-11-24 21:58:51 +0100
committerjelemux <jeremias.weber@protonmail.com>2020-11-24 21:58:51 +0100
commit5a03734b6767fed04c0913384584d8f59dc597ea (patch)
tree62ef0a0afc0ab56dd36da1a662db768fd8c22eda /src/view/input_objects/telephone.rs
parent49588f22f7d20193f899226107c9e323a82c6951 (diff)
downloadwasm-card-5a03734b6767fed04c0913384584d8f59dc597ea.tar.gz
wasm-card-5a03734b6767fed04c0913384584d8f59dc597ea.tar.bz2
add traits for viewmodel and view
Diffstat (limited to 'src/view/input_objects/telephone.rs')
-rw-r--r--src/view/input_objects/telephone.rs162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/view/input_objects/telephone.rs b/src/view/input_objects/telephone.rs
new file mode 100644
index 0000000..d7f7194
--- /dev/null
+++ b/src/view/input_objects/telephone.rs
@@ -0,0 +1,162 @@
+use vcard::properties;
+use vcard::parameters;
+use vcard::values;
+use std::collections::HashSet;
+use super::*;
+use super::super::telephone::*;
+
+#[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 VCardPropertyInputObject<properties::Telephone, TelephoneView> for Telephone {
+ 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,
+ }
+ }
+ fn get_input_fields(&self, link: &ComponentLink<TelephoneView>) -> Vec<VCardPropertyInputField> {
+ vec![
+ VCardPropertyInputField::Text{
+ label: "Number".to_string(),
+ id: Some("number".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| Msg::UpdateNumber(e.value)),
+ value: self.number.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::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,
+ },
+ VCardPropertyInputField::CheckBox{
+ label: "Text".to_string(),
+ id: Some("text".to_string()),
+ onclick: link.callback(|_: MouseEvent| Msg::ToggleText),
+ value: self.text,
+ },
+ VCardPropertyInputField::CheckBox{
+ label: "Voice".to_string(),
+ id: Some("voice".to_string()),
+ onclick: link.callback(|_: MouseEvent| Msg::ToggleVoice),
+ value: self.voice,
+ },
+ VCardPropertyInputField::CheckBox{
+ label: "Fax".to_string(),
+ id: Some("fax".to_string()),
+ onclick: link.callback(|_: MouseEvent| Msg::ToggleFax),
+ value: self.fax,
+ },
+ VCardPropertyInputField::CheckBox{
+ label: "Cell".to_string(),
+ id: Some("cell".to_string()),
+ onclick: link.callback(|_: MouseEvent| Msg::ToggleCell),
+ value: self.cell,
+ },
+ VCardPropertyInputField::CheckBox{
+ label: "Video".to_string(),
+ id: Some("video".to_string()),
+ onclick: link.callback(|_: MouseEvent| Msg::ToggleVideo),
+ value: self.video,
+ },
+ VCardPropertyInputField::CheckBox{
+ label: "Pager".to_string(),
+ id: Some("pager".to_string()),
+ onclick: link.callback(|_: MouseEvent| Msg::TogglePager),
+ value: self.pager,
+ },
+ VCardPropertyInputField::CheckBox{
+ label: "Text Phone".to_string(),
+ id: Some("text_phone".to_string()),
+ onclick: link.callback(|_: MouseEvent| Msg::ToggleTextPhone),
+ value: self.text_phone,
+ },
+ ]
+ }
+ fn to_vcard_property(&self) -> Result<properties::Telephone, VCardPropertyInputError> {
+ 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));
+ }
+
+ Ok(telephone)
+ }
+} \ No newline at end of file