diff options
Diffstat (limited to 'src/app/form.rs')
-rw-r--r-- | src/app/form.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/app/form.rs b/src/app/form.rs index 6c42cd0..7f75db0 100644 --- a/src/app/form.rs +++ b/src/app/form.rs @@ -46,11 +46,14 @@ pub async fn show(app: &App, event: Event, is_new: bool) { vbox.append(&label("Fin")); vbox.append(&end); - let button = gtk::Button::with_label("Créer"); + let button = gtk::Button::builder() + .label(if is_new { "Créer" } else { "Modifier" }) + .margin_bottom(10) + .build(); vbox.append(&button); let conn = app.conn.clone(); let tx = app.tx.clone(); - button.connect_clicked(glib::clone!(@weak dialog => move |_| { + button.connect_clicked(glib::clone!(@weak dialog, @strong event => move |_| { match event::validate(event.id, date.buffer().text(), name.buffer().text(), start.buffer().text(), end.buffer().text()) { Some(new) => { match if is_new { db::insert(&conn, &new) } else { db::update(&conn, &new) } { @@ -66,6 +69,22 @@ pub async fn show(app: &App, event: Event, is_new: bool) { } })); + if !is_new { + let button = gtk::Button::builder().label("Supprimer").build(); + vbox.append(&button); + let conn = app.conn.clone(); + let tx = app.tx.clone(); + button.connect_clicked(glib::clone!(@weak dialog => move |_| { + match db::delete(&conn, &event.id) { + Ok(_) => { + update::send(tx.clone(), Msg::DeleteEvent { event: event.clone() }); + dialog.close() + }, + Err(_) => () + } + })); + } + dialog.run_future().await; } |