added redirect and ability to save checkboxes

This commit is contained in:
2025-06-04 22:25:47 +02:00
parent 397189c259
commit e13de7c786
17 changed files with 150 additions and 49 deletions

View File

@@ -1,5 +1,6 @@
#include <string>
#include <vector>
#include <format>
#include "HtmxShItemList.hpp"
#include "HtmxShAttributeList.hpp"
#include "HtmxShCondition.hpp"
@@ -76,6 +77,13 @@ static const vector<string> cArmorParamters = {
"Notes",
};
static const vector<string> genCheckboxIds(){
vector<string> vec;
HtmxShCondition::genIds(vec, "Physical Condition", 18);
HtmxShCondition::genIds(vec, "Stun Condition", 12);
return vec;
}
static const vector<string> genFormIds(){
vector<string> vec;
vec.reserve(200);
@@ -83,16 +91,20 @@ static const vector<string> genFormIds(){
// OBS make sure to update both here and in ShadowrunCharacterForm()
HtmxShAttributeList::genIds(vec, "Character Info", cCharacterInfo);
HtmxShAttributeList::genIds(vec, "Attributes", cAttributes);
HtmxShItemList::genIds(vec, "Active Skills", cSkillParameters, 6);
HtmxShItemList::genIds(vec, "Knowledge Skills", cSkillParameters, 6);
HtmxShItemList::genIds(vec, "Active Skills", cSkillParameters, 8);
HtmxShItemList::genIds(vec, "Knowledge Skills", cSkillParameters, 8);
vec.push_back("positive_qualities");
vec.push_back("negative_qualities");
vec.push_back("datapack_notes");
auto v = genCheckboxIds();
vec.insert(vec.end(), v.begin(), v.end());
HtmxShCondition::genIds(vec, "Physical Condition", 18);
HtmxShCondition::genIds(vec, "Stun Condition", 12);
HtmxShItemList::genIds(vec, "Contacts", cContactsParameters, 6);
HtmxShItemList::genIds(vec, "Ranged Weapons", cRangedWeaponsParameters, 7);
HtmxShItemList::genIds(vec, "Cyberware and Bioware", cImplantParameters, 7);
HtmxShItemList::genIds(vec, "Cyberware and Bioware", cImplantParameters, 9);
HtmxShItemList::genIds(vec, "Melee Weapons", cMeleeWeaponParameters, 7);
HtmxShItemList::genIds(vec, "Armor", cArmorParamters , 3);
@@ -100,44 +112,49 @@ static const vector<string> genFormIds(){
}
const std::vector<std::string> ShadowrunCharacterForm::m_formIds = genFormIds();
const std::vector<std::string> ShadowrunCharacterForm::m_checkboxIds = genCheckboxIds();
ShadowrunCharacterForm::ShadowrunCharacterForm() {
ShadowrunCharacterForm::ShadowrunCharacterForm(std::map<std::string, std::string>& data) {
html.reserve(30000);
html += "<form hx-post='/api/shadowrun/submit-character' hx-target='#form-response' hx-swap='innerHTML'>";
html += HtmxShAttributeList("Character Info", cCharacterInfo).htmx();
html += HtmxShAttributeList("Attributes", cAttributes).htmx();
html += HtmxShAttributeList("Character Info", cCharacterInfo, data).htmx();
html += HtmxShAttributeList("Attributes", cAttributes, data).htmx();
html += "<div style='display: grid; grid-template-columns: 1fr 1fr; gap: 2em;'>";
html += HtmxShItemList("Active Skills", cSkillParameters, 6).htmx();
html += HtmxShItemList("Knowledge Skills", cSkillParameters, 6).htmx();
html += HtmxShItemList("Active Skills", cSkillParameters, 8, data).htmx();
html += HtmxShItemList("Knowledge Skills", cSkillParameters, 8, data).htmx();
auto valuePos = data.contains("positive_qualities") ? data["positive_qualities"] : "";
auto valueNeg = data.contains("negative_qualities") ? data["negative_qualities"] : "";
// add Qualities
html += "<div class='section'>"
html += format("<div class='section'>"
"<h2>Qualities</h2>"
"<label>Positive Qualities:"
"<textarea name='positive_qualities' rows='4'></textarea>"
"<textarea name='positive_qualities' rows='4'>{}</textarea>"
"</label>"
"<label>Negative Qualities:"
"<textarea name='negative_qualities' rows='4'></textarea>"
"<textarea name='negative_qualities' rows='4'>{}</textarea>"
"</label>"
"</div>";
"</div>", valuePos, valueNeg);
auto valueNotes = data.contains("datapack_notes") ? data["datapack_notes"] : "";
// add datapack notes
html += "<div class='section'>"
html += format("<div class='section'>"
"<h2>Datajack / Commlink / Cyberdeck / Notes</h2>"
"<label>Notes:"
"<textarea name='datapack_notes' rows='6'></textarea>"
"<textarea name='datapack_notes' rows='6'>{}</textarea>"
"</label>"
"</div>";
"</div>", valueNotes);
html += HtmxShCondition("Physical Condition", 18).htmx();
html += HtmxShCondition("Stun Condition", 12).htmx();
html += HtmxShItemList("Contacts", cContactsParameters, 6).htmx();
html += HtmxShItemList("Ranged Weapons", cRangedWeaponsParameters, 7).htmx();
html += HtmxShItemList("Cyberware and Bioware", cImplantParameters, 7).htmx();
html += HtmxShItemList("Melee Weapons", cMeleeWeaponParameters, 7).htmx();
html += HtmxShItemList("Armor", cArmorParamters , 3).htmx();
html += HtmxShCondition("Physical Condition", 18, data).htmx();
html += HtmxShCondition("Stun Condition", 12, data).htmx();
html += HtmxShItemList("Contacts", cContactsParameters, 6, data).htmx();
html += HtmxShItemList("Ranged Weapons", cRangedWeaponsParameters, 7, data).htmx();
html += HtmxShItemList("Cyberware and Bioware", cImplantParameters, 9, data).htmx();
html += HtmxShItemList("Melee Weapons", cMeleeWeaponParameters, 7, data).htmx();
html += HtmxShItemList("Armor", cArmorParamters , 3, data).htmx();
html += "</div>";
html += "<div style='text-align:center'>"