starting work on a confirmation dialog
This commit is contained in:
32
src/ui.cpp
32
src/ui.cpp
@@ -44,18 +44,26 @@ bool setup_data_binding(Rml::Context *context, Rml::DataModelHandle &model_handl
|
||||
|
||||
dmc.Bind("critters", &critter_list);
|
||||
dmc.Bind("page_title", &app_data.page_title);
|
||||
dmc.Bind("is_dialog_open", &app_data.is_dialog_open);
|
||||
dmc.Bind("error_message", &app_data.error_message);
|
||||
dmc.Bind("form", &app_data.form);
|
||||
|
||||
// New Critter dialog
|
||||
dmc.Bind("is_add_critter_dialog_open", &app_data.is_add_critter_dialog_open);
|
||||
dmc.Bind("new_critter_form", &app_data.new_critter_form);
|
||||
|
||||
// Confirmation dialog
|
||||
dmc.Bind("is_confirmation_dialog_open", &app_data.is_confirmation_dialog_open);
|
||||
dmc.Bind("confirmation_dialog_text", &app_data.confirmation_dialog_text);
|
||||
dmc.Bind("confirmation_dialog_result", &app_data.confimation_dialog_result);
|
||||
|
||||
|
||||
dmc.BindEventCallback("submit_add_critter", [&app_data, &critters, &critter_list](Rml::DataModelHandle handle, Rml::Event &, const Rml::VariantList &) {
|
||||
Critter temp;
|
||||
temp.name = app_data.form.name;
|
||||
temp.gender = app_data.form.gender;
|
||||
temp.mother_id = app_data.form.mother_id;
|
||||
temp.father_id = app_data.form.father_id;
|
||||
temp.notes = app_data.form.notes;
|
||||
temp.species = app_data.form.species;
|
||||
temp.name = app_data.new_critter_form.name;
|
||||
temp.gender = app_data.new_critter_form.gender;
|
||||
temp.mother_id = app_data.new_critter_form.mother_id;
|
||||
temp.father_id = app_data.new_critter_form.father_id;
|
||||
temp.notes = app_data.new_critter_form.notes;
|
||||
temp.species = app_data.new_critter_form.species;
|
||||
|
||||
std::string err;
|
||||
if (!validate_critter(temp, critters, err)) {
|
||||
@@ -69,14 +77,14 @@ bool setup_data_binding(Rml::Context *context, Rml::DataModelHandle &model_handl
|
||||
db_get_all_critters(critters);
|
||||
sync_map_to_list(critters, critter_list);
|
||||
|
||||
app_data.form.Clear();
|
||||
app_data.new_critter_form.Clear();
|
||||
app_data.error_message.clear();
|
||||
app_data.is_dialog_open = false;
|
||||
app_data.is_add_critter_dialog_open = false;
|
||||
|
||||
handle.DirtyVariable("critters");
|
||||
handle.DirtyVariable("form");
|
||||
handle.DirtyVariable("new_critter_form");
|
||||
handle.DirtyVariable("error_message");
|
||||
handle.DirtyVariable("is_dialog_open");
|
||||
handle.DirtyVariable("is_add_critter_dialog_open");
|
||||
} else {
|
||||
app_data.error_message = "Failed to write to database.";
|
||||
handle.DirtyVariable("error_message");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "critter.hpp"
|
||||
#include <RmlUi/Config/Config.h>
|
||||
#include <RmlUi/Core/Context.h>
|
||||
#include <RmlUi/Core/DataModelHandle.h>
|
||||
#include <map>
|
||||
@@ -26,9 +27,12 @@ struct NewCritterForm {
|
||||
|
||||
struct AppData {
|
||||
Rml::String page_title = "Main";
|
||||
bool is_dialog_open = false;
|
||||
bool is_add_critter_dialog_open = false;
|
||||
bool is_confirmation_dialog_open = false;
|
||||
Rml::String confirmation_dialog_text = "Are you sure?";
|
||||
bool confimation_dialog_result = false;
|
||||
Rml::String error_message;
|
||||
NewCritterForm form;
|
||||
NewCritterForm new_critter_form;
|
||||
};
|
||||
|
||||
void sync_map_to_list(const std::map<int, Critter> &critters, std::vector<CritterEntry> &critter_list);
|
||||
|
||||
Reference in New Issue
Block a user