From 9df3ff8d633a18e934d4e62b0e2e718620760552 Mon Sep 17 00:00:00 2001 From: jelemux Date: Tue, 9 Feb 2021 22:38:40 +0100 Subject: add file input field, include file as data url in vcard --- src/viewmodel/organizational.rs | 47 ++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'src/viewmodel/organizational.rs') diff --git a/src/viewmodel/organizational.rs b/src/viewmodel/organizational.rs index e7a4ae7..c8f7164 100644 --- a/src/viewmodel/organizational.rs +++ b/src/viewmodel/organizational.rs @@ -4,7 +4,7 @@ use super::*; #[derive(Clone,Debug,PartialEq)] pub struct Organizational { pub org: String, - pub logo: String, + pub logo: Option, pub title: String, pub role: String, pub member: String, @@ -15,7 +15,7 @@ impl VCardPropertyInputObject for Organizational { fn new() -> Self { Self { org: String::new(), - logo: String::new(), + logo: None, title: String::new(), role: String::new(), member: String::new(), @@ -33,13 +33,44 @@ impl VCardPropertyInputObject for Organizational { value: self.org.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ // TODO: Add Upload for logo + VCardPropertyInputField::File{ // TODO: Add Upload for logo label: "Logo".to_string(), - id: Some("logo".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| Msg::UpdateLogo(e.value)), + name: "logo".to_string(), + callback: link.callback(|file: Option| + /* + if let ChangeData::Files(files) = c { + match files.item(0) { + Some(file) => { + let filereader = match FileReaderSync::new() { + Ok(reader) => reader, + Err(_) => { + ConsoleService::warn("Couldn't create new filereader."); + return Msg::UpdateLogo(None) + }, + }; + let content = match filereader.read_as_data_url(&file) { + Ok(content) => content, + Err(_) => { + ConsoleService::warn("Error: Couldn't get file as data url."); + return Msg::UpdateLogo(None) + }, + }; + Msg::UpdateLogo( + Some(File { + name: file.name(), + content, + }) + ) + }, + None => Msg::UpdateLogo(None), + } + } else { + Msg::UpdateLogo(None) + } + */ + Msg::UpdateLogo(file) + ), value: self.logo.clone(), - typ: typ.clone(), }, VCardPropertyInputField::Text{ label: "Title".to_string(), @@ -77,7 +108,7 @@ impl VCardPropertyInputObject for Organizational { } fn is_empty(&self) -> bool { self.org.is_empty() && - self.logo.is_empty() && + self.logo.is_none() && self.title.is_empty() && self.role.is_empty() && self.member.is_empty() && -- cgit v1.2.3