parent
4ee5447cf9
commit
c135650018
|
@ -140,6 +140,9 @@ impl Card {
|
|||
self.last_edited.to_rfc2822()
|
||||
}
|
||||
|
||||
pub fn set_id(&mut self, new: Uuid) {
|
||||
self.id = new;
|
||||
}
|
||||
pub fn set_title(&mut self, new: &str) {
|
||||
self.title = new.to_string();()
|
||||
}
|
||||
|
@ -176,3 +179,39 @@ impl Card {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
impl From<FnvHashMap<String, String>> for Card {
|
||||
fn from(mut map: FnvHashMap<String, String>) -> Card {
|
||||
let mut card = Card::new();
|
||||
if let Some(val) = map.remove("Title") {
|
||||
card.title = val;
|
||||
}
|
||||
if let Some(val) = map.remove("First Name") {
|
||||
card.firstname = val;
|
||||
}
|
||||
if let Some(val) = map.remove("Last Name") {
|
||||
card.lastname = val;
|
||||
}
|
||||
if let Some(val) = map.remove("Additional Name") {
|
||||
card.additionalname = val;
|
||||
}
|
||||
if let Some(val) = map.remove("Name Prefix") {
|
||||
card.name_prefix = val;
|
||||
}
|
||||
if let Some(val) = map.remove("Name Suffix") {
|
||||
card.name_suffix = val;
|
||||
}
|
||||
|
||||
if let Some(val) = map.remove("E-mail") {
|
||||
card.email = val;
|
||||
}
|
||||
if let Some(val) = map.remove("url") {
|
||||
card.url = val;
|
||||
}
|
||||
if let Some(val) = map.remove("key") {
|
||||
card.key = val;
|
||||
}
|
||||
card.extra_properties = map;
|
||||
card
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ pub struct ContactManager {
|
|||
pub card: Card,
|
||||
mode: ViewMode,
|
||||
form: FormWidget,
|
||||
account_pos: usize,
|
||||
content: CellBuffer,
|
||||
dirty: bool,
|
||||
initialized: bool,
|
||||
|
@ -51,6 +52,7 @@ impl Default for ContactManager {
|
|||
card: Card::new(),
|
||||
mode: ViewMode::Read,
|
||||
form: FormWidget::default(),
|
||||
account_pos: 0,
|
||||
content: CellBuffer::new(200, 100, Cell::with_char(' ')),
|
||||
dirty: true,
|
||||
initialized: false,
|
||||
|
@ -126,7 +128,9 @@ impl Component for ContactManager {
|
|||
match self.form.buttons_result() {
|
||||
None => {},
|
||||
Some(true) => {
|
||||
eprintln!("fields: {:?}", std::mem::replace(&mut self.form, FormWidget::default()).collect());
|
||||
let mut new_card = Card::from(std::mem::replace(&mut self.form, FormWidget::default()).collect().unwrap());
|
||||
new_card.set_id(*self.card.id());
|
||||
context.accounts[self.account_pos].address_book.add_card(new_card);
|
||||
context.replies.push_back(UIEvent {
|
||||
id: 0,
|
||||
event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage("Saved.".into())),
|
||||
|
|
|
@ -119,6 +119,7 @@ impl Component for ContactList {
|
|||
let card = book[&self.id_positions[self.cursor_pos]].clone();
|
||||
let mut manager = ContactManager::default();
|
||||
manager.card = card;
|
||||
manager.account_pos = self.account_pos;
|
||||
let entity = Entity::from(Box::new(manager));
|
||||
|
||||
self.mode = ViewMode::View(*entity.id());
|
||||
|
|
Loading…
Reference in New Issue