Added a confirmation dialog
This commit is contained in:
BIN
assets/local.db
BIN
assets/local.db
Binary file not shown.
@@ -48,45 +48,45 @@
|
|||||||
<p class="error" data-visible="error_message != ''">{{error_message}}</p>
|
<p class="error" data-visible="error_message != ''">{{error_message}}</p>
|
||||||
|
|
||||||
<label>Name:</label>
|
<label>Name:</label>
|
||||||
<input type="text" data-value="form.name" />
|
<input type="text" data-value="new_critter_form.name" />
|
||||||
|
|
||||||
<label>Species:</label>
|
<label>Species:</label>
|
||||||
<input type="text" data-value="form.species" />
|
<input type="text" data-value="new_critter_form.species" />
|
||||||
|
|
||||||
<label>Gender (M/F):</label>
|
<label>Gender (M/F):</label>
|
||||||
<input type="text" data-value="form.gender" />
|
<input type="text" data-value="new_critter_form.gender" />
|
||||||
|
|
||||||
<label>Mother ID (Optional):</label>
|
<label>Mother ID (Optional):</label>
|
||||||
<input type="text" data-value="form.mother_id" />
|
<input type="text" data-value="new_critter_form.mother_id" />
|
||||||
|
|
||||||
<label>Father ID (Optional):</label>
|
<label>Father ID (Optional):</label>
|
||||||
<input type="text" data-value="form.father_id" />
|
<input type="text" data-value="new_critter_form.father_id" />
|
||||||
|
|
||||||
<label>Notes:</label>
|
<label>Notes:</label>
|
||||||
<textarea data-value="form.notes"></textarea>
|
<textarea data-value="new_critter_form.notes"></textarea>
|
||||||
|
|
||||||
<div class="modal-buttons">
|
<div class="modal-buttons">
|
||||||
<button data-event-click="submit_add_critter">Save</button>
|
|
||||||
<button data-event-click="is_add_critter_dialog_open = false">Cancel</button>
|
<button data-event-click="is_add_critter_dialog_open = false">Cancel</button>
|
||||||
|
<button data-event-click="submit_add_critter">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Confirmation Dialog -->
|
<!-- Confirmation Dialog -->
|
||||||
<div class="modal-overlay" data-visible="confirmation_dialog_open">
|
<div class="modal-overlay" data-visible="is_confirmation_dialog_open">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<h2>Confirmation</h2>
|
<h2>Confirmation</h2>
|
||||||
|
|
||||||
<p>{{confirmation_dialog_text}}</p>
|
<p class="dialog-text">{{confirmation_dialog_text}}</p>
|
||||||
|
|
||||||
<!-- <p class="error" data-visible="error_message != ''">{{error_message}}</p> -->
|
|
||||||
|
|
||||||
<div class="modal-buttons">
|
<div class="modal-buttons">
|
||||||
<button data-event-click="confimation_dialog_result = false">Cancel</button>
|
<button data-event-click="confirm_dialog_no">Cancel</button>
|
||||||
<button data-event-click="confimation_dialog_result = true">Yes</button>
|
<button data-event-click="confirm_dialog_yes">Yes</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</rml>
|
</rml>
|
||||||
@@ -443,9 +443,26 @@ progress-value {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dialog-text {
|
||||||
|
font-size: 25pt;
|
||||||
|
/* font-style: italic; */
|
||||||
|
}
|
||||||
|
|
||||||
.modal-buttons {
|
.modal-buttons {
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
flex-direction: row;
|
||||||
|
gap: 20px;
|
||||||
|
/* justify-content: space-between; */
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
font-size: 18pt;
|
font-size: 18pt;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-buttons button {
|
||||||
|
width: 50%;
|
||||||
|
height: 50px;
|
||||||
|
font-size: 20pt;
|
||||||
|
line-height: 50px;
|
||||||
}
|
}
|
||||||
46
src/ui.cpp
46
src/ui.cpp
@@ -53,9 +53,8 @@ bool setup_data_binding(Rml::Context *context, Rml::DataModelHandle &model_handl
|
|||||||
// Confirmation dialog
|
// Confirmation dialog
|
||||||
dmc.Bind("is_confirmation_dialog_open", &app_data.is_confirmation_dialog_open);
|
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_text", &app_data.confirmation_dialog_text);
|
||||||
dmc.Bind("confirmation_dialog_result", &app_data.confimation_dialog_result);
|
|
||||||
|
|
||||||
|
|
||||||
|
// Submit Add Critter
|
||||||
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.new_critter_form.name;
|
temp.name = app_data.new_critter_form.name;
|
||||||
@@ -91,17 +90,48 @@ bool setup_data_binding(Rml::Context *context, Rml::DataModelHandle &model_handl
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dmc.BindEventCallback("delete_critter", [&app_data, &critters, &critter_list](Rml::DataModelHandle handle, Rml::Event &, const Rml::VariantList &args) {
|
// Request Critter Deletion
|
||||||
|
dmc.BindEventCallback("delete_critter", [&app_data, &critters, &critter_list](Rml::DataModelHandle const_handle, Rml::Event &, const Rml::VariantList &args) {
|
||||||
if (args.empty()) return;
|
if (args.empty()) return;
|
||||||
|
|
||||||
|
Rml::DataModelHandle handle = const_handle;
|
||||||
|
|
||||||
int target_id = args[0].Get<int>();
|
int target_id = args[0].Get<int>();
|
||||||
|
|
||||||
if (db_delete_critter(target_id)) {
|
app_data.confirmation_dialog_text = "Are you sure you want to delete critter '" + critters[target_id].name + "'? This action cannot be undone.";
|
||||||
critters.erase(target_id);
|
|
||||||
sync_map_to_list(critters, critter_list);
|
app_data.on_confirm_action = [&critters, &critter_list, target_id, const_handle]() {
|
||||||
handle.DirtyVariable("critters");
|
Rml::DataModelHandle handle = const_handle;
|
||||||
std::cout << "[INFO] Deleted critter with ID #" << target_id << std::endl;
|
if (db_delete_critter(target_id)) {
|
||||||
|
critters.erase(target_id);
|
||||||
|
sync_map_to_list(critters, critter_list);
|
||||||
|
handle.DirtyVariable("critters");
|
||||||
|
std::cout << "[INFO] Deleted critter with ID #" << target_id << std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
app_data.is_confirmation_dialog_open = true;
|
||||||
|
handle.DirtyVariable("confirmation_dialog_text");
|
||||||
|
handle.DirtyVariable("is_confirmation_dialog_open");
|
||||||
|
});
|
||||||
|
|
||||||
|
dmc.BindEventCallback("confirm_dialog_yes", [&app_data](Rml::DataModelHandle const_handle, Rml::Event &, const Rml::VariantList &) {
|
||||||
|
Rml::DataModelHandle handle = const_handle;
|
||||||
|
|
||||||
|
if (app_data.on_confirm_action) {
|
||||||
|
app_data.on_confirm_action();
|
||||||
|
app_data.on_confirm_action = nullptr;
|
||||||
}
|
}
|
||||||
|
app_data.is_confirmation_dialog_open = false;
|
||||||
|
handle.DirtyVariable("is_confirmation_dialog_open");
|
||||||
|
});
|
||||||
|
|
||||||
|
dmc.BindEventCallback("confirm_dialog_no", [&app_data](Rml::DataModelHandle const_handle, Rml::Event &, const Rml::VariantList &) {
|
||||||
|
Rml::DataModelHandle handle = const_handle;
|
||||||
|
|
||||||
|
app_data.on_confirm_action = nullptr;
|
||||||
|
app_data.is_confirmation_dialog_open = false;
|
||||||
|
handle.DirtyVariable("is_confirmation_dialog_open");
|
||||||
});
|
});
|
||||||
|
|
||||||
model_handle = dmc.GetModelHandle();
|
model_handle = dmc.GetModelHandle();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <RmlUi/Config/Config.h>
|
#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 <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -33,6 +34,8 @@ struct AppData {
|
|||||||
bool confimation_dialog_result = false;
|
bool confimation_dialog_result = false;
|
||||||
Rml::String error_message;
|
Rml::String error_message;
|
||||||
NewCritterForm new_critter_form;
|
NewCritterForm new_critter_form;
|
||||||
|
|
||||||
|
std::function<void()> on_confirm_action = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user