summaryrefslogtreecommitdiff
path: root/src/model/property_groups/organizational.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-02-17 22:27:41 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-02-17 22:27:41 +0100
commit9698e6952cb568f6dce49b35bd47b52d992c0f9a (patch)
tree1c8cff0b2c6824653da68b94a81bbbfb314f01dd /src/model/property_groups/organizational.rs
parentd0d42c5ae00560e4464479a98df90ed063a1c773 (diff)
downloadwasm-card-9698e6952cb568f6dce49b35bd47b52d992c0f9a.tar.gz
wasm-card-9698e6952cb568f6dce49b35bd47b52d992c0f9a.tar.bz2
refactor: put input_fields and property_groups into their own modules
Diffstat (limited to 'src/model/property_groups/organizational.rs')
-rw-r--r--src/model/property_groups/organizational.rs121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/model/property_groups/organizational.rs b/src/model/property_groups/organizational.rs
new file mode 100644
index 0000000..1d6ccf2
--- /dev/null
+++ b/src/model/property_groups/organizational.rs
@@ -0,0 +1,121 @@
+use crate::model::input_fields::VCardPropertyInputField;
+use crate::model::*;
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct Organizational {
+ pub org: String,
+ pub logo: Option<File>,
+ pub title: String,
+ pub role: String,
+ pub member: String,
+ pub related: String,
+}
+
+#[derive(Clone, PartialEq)]
+pub enum OrganizationalMsg {
+ UpdateOrg(String),
+ UpdateLogo(Option<File>),
+ UpdateTitle(String),
+ UpdateRole(String),
+ UpdateMember(String),
+ UpdateRelated(String),
+
+ Generate,
+}
+
+impl VCardPropertyInputGroupObject<OrganizationalMsg> for Organizational {
+ fn new() -> Self {
+ Self {
+ org: String::new(),
+ logo: None,
+ title: String::new(),
+ role: String::new(),
+ member: String::new(),
+ related: String::new(),
+ }
+ }
+ fn get_title(&self) -> std::string::String {
+ "Organizational".to_string()
+ }
+ fn get_input_fields(
+ &self,
+ link: &yew::html::Scope<PropertyGroupInputComponent<Self, OrganizationalMsg>>,
+ ) -> std::vec::Vec<VCardPropertyInputField> {
+ let typ = String::from("text");
+ vec![
+ VCardPropertyInputField::Text {
+ label: "Organisation".to_string(),
+ id: Some("org".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateOrg(e.value)),
+ value: self.org.clone(),
+ typ: typ.clone(),
+ },
+ VCardPropertyInputField::File {
+ // TODO: Add Upload for logo
+ label: "Logo".to_string(),
+ name: "logo".to_string(),
+ callback: link.callback(|file: Option<File>| OrganizationalMsg::UpdateLogo(file)),
+ value: self.logo.clone(),
+ },
+ VCardPropertyInputField::Text {
+ label: "Title".to_string(),
+ id: Some("title".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateTitle(e.value)),
+ value: self.title.clone(),
+ typ: typ.clone(),
+ },
+ VCardPropertyInputField::Text {
+ label: "Role".to_string(),
+ id: Some("role".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateRole(e.value)),
+ value: self.role.clone(),
+ typ: typ.clone(),
+ },
+ VCardPropertyInputField::Text {
+ label: "Member".to_string(),
+ id: Some("member".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateMember(e.value)),
+ value: self.member.clone(),
+ typ: typ.clone(),
+ },
+ VCardPropertyInputField::Text {
+ label: "Related".to_string(),
+ id: Some("related".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateRelated(e.value)),
+ value: self.related.clone(),
+ typ: typ,
+ },
+ ]
+ }
+ fn update(
+ &mut self,
+ props: InputProps<Self, OrganizationalMsg>,
+ msg: <PropertyGroupInputComponent<Self, OrganizationalMsg> as yew::Component>::Message,
+ ) -> bool {
+ match msg {
+ OrganizationalMsg::UpdateOrg(o) => self.org = o,
+ OrganizationalMsg::UpdateLogo(l) => self.logo = l,
+ OrganizationalMsg::UpdateTitle(t) => self.title = t,
+ OrganizationalMsg::UpdateRole(r) => self.role = r,
+ OrganizationalMsg::UpdateMember(m) => self.member = m,
+ OrganizationalMsg::UpdateRelated(r) => self.related = r,
+ OrganizationalMsg::Generate => {
+ props.generated.emit(self.clone());
+ }
+ };
+ true
+ }
+ fn is_empty(&self) -> bool {
+ self.org.is_empty()
+ && self.logo.is_none()
+ && self.title.is_empty()
+ && self.role.is_empty()
+ && self.member.is_empty()
+ && self.related.is_empty()
+ }
+}