Fixed: prepend charname before for= and id=. One problem remains, sometimes q_all and wp_all don't check when all quests or wps are checked

This commit is contained in:
Hash Borgir 2023-06-12 02:23:35 -06:00
parent 46a7bbd378
commit e9fdeede11
2 changed files with 47 additions and 110 deletions

View File

@ -400,11 +400,11 @@ $(document).ready(function () {
return "/saveCharacter.php?cmd=" + cmd + "&name=" + name + "&value=" + value + "&filePath=" + filePath;
}
$(".charform input[name='Difficulty'], .charform .skill, #CharacterName, #CharacterClass, #CharacterLevel, #CharacterClass, .stats input, .form-check-input, #statsdiv input,#setallskills,.wp_all,.q_all").change(function () {
$(".charform input[name='Difficulty'], .charform .skill, .CharacterName, .CharacterClass, .CharacterLevel, .stats input, .form-check-input, .statsdiv input,.setallskills").change(function () {
var name = $(this).attr("name");
var newValue = $(this).val();
var cmd = $(this).attr("cmd") || $(this).attr("id") || name;
var cmd = $(this).attr("cmd") || name;
var parentFormId = $(this).closest("form").attr("id");
var parentFormClass = $(this).closest("form").attr("class");
@ -424,41 +424,31 @@ $(document).ready(function () {
});
$('.q_all, .wp_all').click(function () {
var parentFormId = $(this).closest("form").attr("id");
var targetClass = $(this).attr('class') === 'q_all' ? `#${parentFormId} .qcheck` : `#${parentFormId} .wpcheck`;
var parentForm = $(this).closest('form');
var targetClass = $(this).hasClass('q_all') ? '.qcheck' : '.wpcheck';
var isChecked = $(this).prop('checked');
$(targetClass).prop('checked', isChecked);
parentForm.find(targetClass).prop('checked', isChecked);
});
$('.qcheck').change(function () {
var parentFormId = $(this).closest("form").attr("id");
var qallChecked = $(`#${parentFormId} .qcheck:checked`).length === $(`#${parentFormId} .qcheck`).length;
if (qallChecked == true) {
var qchecked = 'checked';
var val = 1;
} else {
qchecked = '';
var val = 0;
}
$(`#${parentFormId} .q_all`).prop('checked', qchecked).val(val);
});
$('.wpcheck').change(function () {
var parentFormId = $(this).closest("form").attr("id");
var wpallChecked = $(`#${parentFormId} .wpcheck:checked`).length === $(`#${parentFormId} .wpcheck`).length;
if (wpallChecked == true) {
var wpchecked = 'checked';
var val = 1;
} else {
wpchecked = '';
var val = 0;
}
var wpchecked = wpallChecked ? 'checked' : '';
var val = wpallChecked ? 1 : 0;
$(`#${parentFormId} .wp_all`).prop('checked', wpchecked).val(val);
});
$('#setallskills').change(function () {
$('.qcheck').change(function () {
var parentFormId = $(this).closest("form").attr("id");
var qallChecked = $(`#${parentFormId} .qcheck:checked`).length === $(`#${parentFormId} .qcheck`).length;
var qchecked = qallChecked ? 'checked' : '';
var val = qallChecked ? 1 : 0;
$(`#${parentFormId} .q_all`).prop('checked', qchecked).val(val);
});
$('.setallskills').change(function () {
var value = $(this).val();
var parentFormId = $(this).closest("form").attr("id");
$(`#${parentFormId} .skill`).attr('value', value);

View File

@ -67,8 +67,8 @@ EOT;
$checked = ($v == 1) ? 'checked' : '';
$quests .= "<div class='qcheckgroup'>";
$quests .= "<input class='qcheck' diff='{$difficulty}' type='checkbox' value='1' name='{$k}' id='{$k}' {$checked}>";
$quests .= "<label for='{$k}'>{$kD}</label><br>";
$quests .= "<input class='qcheck' diff='{$difficulty}' type='checkbox' value='1' name='{$k}' id='{$c->cData['CharacterName']}-{$k}' {$checked}>";
$quests .= "<label for='{$c->cData['CharacterName']}-{$k}'>{$kD}</label><br>";
$quests .= "</div>";
}
@ -112,8 +112,8 @@ EOT;
$checked = ($v == 1 && $k != '') ? 'checked ' : '';
$wps .= "<div class='wcheckgroup'>";
$wps .= "<input diff='{$diff}' class='wpcheck' type='checkbox' value='1' name='{$wp_count}' id='{$k}' {$checked}>";
$wps .= "<label for='{$k}'>{$kD}</label><br>";
$wps .= "<input diff='{$diff}' class='wpcheck' type='checkbox' value='1' name='{$wp_count}' id='{$c->cData['CharacterName']}-{$k}' {$checked}>";
$wps .= "<label for='{$c->cData['CharacterName']}-{$k}'>{$kD}</label><br>";
$wps .= "</div>";
$wp_count++;
}
@ -146,8 +146,8 @@ EOT;
foreach ($difficulties as $difficulty => $id) {
$checked = ($c->cData['Difficulty'][$difficulty] == 1) ? 'checked' : '';
$radio .= "<input $checked type='radio' id='$difficulty' name='Difficulty' value='$id'>";
$radio .= "<label for='$difficulty'>$difficulty</label><br>";
$radio .= "<input $checked type='radio' id='{$c->cData['CharacterName']}-$difficulty' name='Difficulty' value='$id' class='$difficulty'>";
$radio .= "<label for='{$c->cData['CharacterName']}-$difficulty'>$difficulty</label><br>";
}
$skills = '';
@ -221,8 +221,8 @@ EOT;
$checkboxes .= <<<HTML
<div class="col">
<div class="form-check">
<label class="form-check-label" for="{$status}">{$status}: </label><br>
<input class="form-check-input" {$checked} type="checkbox" id="{$status}" name="CharacterStatus[{$status}]" value="{$c->cData[$dataKey]}">
<label class="form-check-label" for="{$c->cData['CharacterName']}-{$status}">{$status}: </label><br>
<input class="form-check-input" {$checked} type="checkbox" id="{$c->cData['CharacterName']}-{$status}" name="CharacterStatus[{$status}]" value="{$c->cData[$dataKey]}">
</div>
</div>
HTML;
@ -253,10 +253,10 @@ HTML;
$defaultValue = isset($c->cData['stats'][$stat]) ? $c->cData['stats'][$stat] : 0;
// Create an HTML input for the stat
$stats .= '<div class="stats" id="statsdiv" style="border:1px solid #ccc;"><input cmd="stats" type="number" id="' . $stat . '" name="' . $stat . '" max="' . $maxValue . '" value="' . $defaultValue . '">';
$stats .= '<div class="stats" id="statsdiv" class="statsdiv" style="border:1px solid #ccc;"><input cmd="stats" type="number" id="'. "{$c->cData['CharacterName']}-" . $stat . '" name="' . $stat . '" max="' . $maxValue . '" value="' . $defaultValue . '" class="' . $stat . '">';
// Create an HTML label for the stat
$stats .= '<label for="' . $stat . '">' . ucfirst($stat) . ':<br> Max Value - ' . $maxValue . '</label><br></div>';
$stats .= '<label for="' . "{$c->cData['CharacterName']}-" . $stat . '">' . ucfirst($stat) . ':<br> Max Value - ' . $maxValue . '</label><br></div>';
}
@ -377,14 +377,13 @@ HTML;
<div class="container" style="font-size: 14px;">
<div class="row">
<div class="col">
<!--<input class="btn btn-danger" style="" type="submit" value="Save Character">
<img src="/img/chars/{$c->cData['CharacterClass']}.gif" style='height: 64px; width: 64px;'><br>-->
Name: <input type="text" id="CharacterName" name="CharacterName" maxlength="16" value="{$c->cData['CharacterName']}" pattern="[A-Za-z0-9_-]+" title="Character name can only contain alphabets, numbers, underscore, and dash." data-oldvalue="{$c->cData['CharacterName']}">
Name: <input type="text" class="CharacterName" id="CharacterName" name="CharacterName" maxlength="16" value="{$c->cData['CharacterName']}" pattern="[A-Za-z0-9_-]+" title="Character name can only contain alphabets, numbers, underscore, and dash." data-oldvalue="{$c->cData['CharacterName']}">
<br>
<select id='CharacterClass' name='CharacterClass'>
<select id='CharacterClass' class='CharacterClass' name='CharacterClass'>
$option
</select><br>
Character Level: <input style="border: 1px solid black;width: 54px;" type="number" name="CharacterLevel" id="CharacterLevel" value="{$c->cData['CharacterLevel']}">
Character Level: <input style="border: 1px solid black;width: 54px;" type="number" name="CharacterLevel" class="CharacterLevel" id="CharacterLevel" value="{$c->cData['CharacterLevel']}">
<hr>
<div style="background: #efe;">
Difficulty:<br>
@ -399,65 +398,13 @@ $checkboxes
</div>
<hr>
<!-- STATS
<div class="stats">
<div class="form-row" style="background: #eed;">
<div class="form-group col-md-3">
<label for="strength">Strength:</label>
<input type="number" class="form-control" id="strength" name="strength" min="1" max="511" value="{$c->cData['stats']['strength']}" required>
</div>
<div class="form-group col-md-3">
<label for="dexterity">Dexterity:</label>
<input type="number" class="form-control" id="dexterity" name="dexterity" min="1" max="511" value="{$c->cData['stats']['dexterity']}" required>
</div>
<div class="form-group col-md-3">
<label for="vitality">Vitality:</label>
<input type="number" class="form-control" id="vitality" name="vitality" min="1" max="511" value="{$c->cData['stats']['vitality']}" required>
</div>
<div class="form-group col-md-3">
<label for="energy">Energy:</label>
<input type="number" class="form-control" id="energy" name="energy" min="1" max="511" value="{$c->cData['stats']['energy']}" required>
</div>
</div>
<div class="form-row" style="background: #eee;">
<div class="form-group col-md-3">
<label for="hitpoints">Hitpoints:</label>
<input type="number" class="form-control" id="hitpoints" name="hitpoints" min="1" max="2097151" value="{$c->cData['stats']['hitpoints']}" required>
</div>
<div class="form-group col-md-3">
<label for="maxhp">Max HP:</label>
<input type="number" class="form-control" id="maxhp" name="maxhp" min="1" max="2097151" value="{$c->cData['stats']['maxhp']}" required>
</div>
<div class="form-group col-md-3">
<label for="mana">Mana:</label>
<input type="number" class="form-control" id="mana" name="mana" min="1" max="2097151" value="{$c->cData['stats']['mana']}" required>
</div>
<div class="form-group col-md-3">
<label for="maxmana">Max Mana:</label>
<input type="number" class="form-control" id="maxmana" name="maxmana" min="1" max="" value="{$c->cData['stats']['maxmana']}" required>
</div>
</div>
<div class="form-row" style="background: #eed;">
<div class="form-group col-md-6">
<label for="stamina">Stamina:</label>
<input type="number" class="form-control" id="stamina" name="stamina" min="1" max="2097151" value="{$c->cData['stats']['stamina']}" required>
</div>
<div class="form-group col-md-6">
<label for="maxstamina">Max Stamina:</label>
<input type="number" class="form-control" id="maxstamina" name="maxstamina" min="1" max="2097151" value="{$c->cData['stats']['maxstamina']}" required>
</div>
</div>
</div>-->
<hr>
$stats
<div style="background:;">
<h3 style="text-align: center">Skills</h3>
<div class="form-group">
<label for="setallskills">Set all skills:</label>
<input type="number" id="setallskills" class="form-control setallskills" max="99">
<label for="{$c->cData['CharacterName']}-setallskills">Set all skills:</label>
<input type="number" class="setallskills" id="{$c->cData['CharacterName']}-setallskills" class="form-control setallskills" max="99">
</div>
<div class="accordion" id="accordionExample">
@ -469,8 +416,8 @@ $checkboxes
<h3 style="text-align: center">Quests</h3>
<div class="form-group">
<div class="form-check">
<label for="q_all" class="form-check-label">Enable/Disable All Quests</label>
<input $qchecked type="checkbox" id="q_all" name="q_all" value="$qallOnes" class="form-check-input q_all">
<label for="{$c->cData['CharacterName']}-q_all" class="form-check-label">Enable/Disable All Quests</label>
<input $qchecked type="checkbox" id="{$c->cData['CharacterName']}-q_all" name="q_all" value="$qallOnes" class="form-check-input q_all">
</div>
</div>
$quests
@ -479,8 +426,8 @@ $checkboxes
<h3 style="text-align: center">Waypoints</h3>
<div class="form-group">
<div class="form-check">
<label for="wp_all" class="form-check-label">Enable/Disable All Waypoints</label>
<input $wpchecked type="checkbox" id="wp_all" name="wp_all" value="$wpallOnes" class="form-check-input wp_all">
<label for="{$c->cData['CharacterName']}-wp_all" class="form-check-label">Enable/Disable All Waypoints</label>
<input $wpchecked type="checkbox" id="{$c->cData['CharacterName']}-wp_all" name="wp_all" value="$wpallOnes" class="form-check-input wp_all">
</div>
</div>