starting work on a confirmation dialog

This commit is contained in:
2026-08-06 23:59:57 -05:00
parent b3945d9d0e
commit d9a3e8914b
4 changed files with 51 additions and 21 deletions

View File

@@ -11,7 +11,7 @@
<body data-model="app_data"> <body data-model="app_data">
<div id="header"> <div id="header">
<h1>Critterfolio</h1> <h1>Critterfolio</h1>
<button id="new-critter-btn" data-event-click="is_dialog_open = true"><div>+</div></button> <button id="new-critter-btn" data-event-click="is_add_critter_dialog_open = true"><div>+</div></button>
</div> </div>
@@ -41,7 +41,7 @@
<!-- Add Critter Modal Dialog Overlay --> <!-- Add Critter Modal Dialog Overlay -->
<div class="modal-overlay" data-visible="is_dialog_open"> <div class="modal-overlay" data-visible="is_add_critter_dialog_open">
<div class="modal-content"> <div class="modal-content">
<h2>Add New Critter</h2> <h2>Add New Critter</h2>
@@ -67,7 +67,24 @@
<div class="modal-buttons"> <div class="modal-buttons">
<button data-event-click="submit_add_critter">Save</button> <button data-event-click="submit_add_critter">Save</button>
<button data-event-click="is_dialog_open = false">Cancel</button> <button data-event-click="is_add_critter_dialog_open = false">Cancel</button>
</div>
</div>
</div>
<!-- Confirmation Dialog -->
<div class="modal-overlay" data-visible="confirmation_dialog_open">
<div class="modal-content">
<h2>Confirmation</h2>
<p>{{confirmation_dialog_text}}</p>
<!-- <p class="error" data-visible="error_message != ''">{{error_message}}</p> -->
<div class="modal-buttons">
<button data-event-click="confimation_dialog_result = false">Cancel</button>
<button data-event-click="confimation_dialog_result = true">Yes</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -6,8 +6,8 @@
box-sizing: border-box; box-sizing: border-box;
font-family: "Hubballi"; font-family: "Hubballi";
--background-color: #f5e8df; --background-color: #54703f;
--foreground-color: #0a1347; --foreground-color: #000000;
} }
body { body {
@@ -285,7 +285,7 @@ progress-value {
#new-critter-btn { #new-critter-btn {
height: 50px; height: 50px;
width: 50px; width: 50px;
/* border-radius: 50px; */ border-radius: 10px;
font-size: 30pt; font-size: 30pt;
display: flex; display: flex;
text-align: center; text-align: center;
@@ -319,6 +319,7 @@ progress-value {
color: var(--foreground-color); color: var(--foreground-color);
border: 2px var(--foreground-color); border: 2px var(--foreground-color);
text-align: left; text-align: left;
border-radius: 10px;
} }
.critter-card:hover { .critter-card:hover {
@@ -406,7 +407,7 @@ progress-value {
border-color: var(--foreground-color); border-color: var(--foreground-color);
border-width: 2px; border-width: 2px;
padding: 20px; padding: 20px;
border-radius: 0px; border-radius: 10px;
width: 80%; width: 80%;
height: 80%; height: 80%;
} }

View File

@@ -44,18 +44,26 @@ bool setup_data_binding(Rml::Context *context, Rml::DataModelHandle &model_handl
dmc.Bind("critters", &critter_list); dmc.Bind("critters", &critter_list);
dmc.Bind("page_title", &app_data.page_title); 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("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 &) { dmc.BindEventCallback("submit_add_critter", [&app_data, &critters, &critter_list](Rml::DataModelHandle handle, Rml::Event &, const Rml::VariantList &) {
Critter temp; Critter temp;
temp.name = app_data.form.name; temp.name = app_data.new_critter_form.name;
temp.gender = app_data.form.gender; temp.gender = app_data.new_critter_form.gender;
temp.mother_id = app_data.form.mother_id; temp.mother_id = app_data.new_critter_form.mother_id;
temp.father_id = app_data.form.father_id; temp.father_id = app_data.new_critter_form.father_id;
temp.notes = app_data.form.notes; temp.notes = app_data.new_critter_form.notes;
temp.species = app_data.form.species; temp.species = app_data.new_critter_form.species;
std::string err; std::string err;
if (!validate_critter(temp, critters, 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); db_get_all_critters(critters);
sync_map_to_list(critters, critter_list); sync_map_to_list(critters, critter_list);
app_data.form.Clear(); app_data.new_critter_form.Clear();
app_data.error_message.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("critters");
handle.DirtyVariable("form"); handle.DirtyVariable("new_critter_form");
handle.DirtyVariable("error_message"); handle.DirtyVariable("error_message");
handle.DirtyVariable("is_dialog_open"); handle.DirtyVariable("is_add_critter_dialog_open");
} else { } else {
app_data.error_message = "Failed to write to database."; app_data.error_message = "Failed to write to database.";
handle.DirtyVariable("error_message"); handle.DirtyVariable("error_message");

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "critter.hpp" #include "critter.hpp"
#include <RmlUi/Config/Config.h>
#include <RmlUi/Core/Context.h> #include <RmlUi/Core/Context.h>
#include <RmlUi/Core/DataModelHandle.h> #include <RmlUi/Core/DataModelHandle.h>
#include <map> #include <map>
@@ -26,9 +27,12 @@ struct NewCritterForm {
struct AppData { struct AppData {
Rml::String page_title = "Main"; 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; 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); void sync_map_to_list(const std::map<int, Critter> &critters, std::vector<CritterEntry> &critter_list);