38676-vm/patch_js_fix.php
2026-03-07 18:42:15 +00:00

50 lines
2.3 KiB
PHP

<?php
$file = 'admin.php';
$content = file_get_contents($file);
// Fix JS syntax error in toggleUnitField
$old_js = " function toggleUnitField(type) {
const isChecked = document.getElementById('unit_can_be_' + type).checked;
const resGroup = document.getElementById('group_' + type + '_res\');
const amtGroup = document.getElementById('group_' + type + '_amt\');
if (resGroup && amtGroup) {
resGroup.style.display = isChecked ? 'block' : 'none';
amtGroup.style.display = isChecked ? 'block' : 'none';
}
}";
$new_js = " function toggleUnitField(type) {
const isChecked = document.getElementById('unit_can_be_' + type).checked;
const resGroup = document.getElementById('group_' + type + '_res');
const amtGroup = document.getElementById('group_' + type + '_amt');
if (resGroup && amtGroup) {
resGroup.style.display = isChecked ? 'flex' : 'none';
amtGroup.style.display = isChecked ? 'flex' : 'none';
}
}";
// I'll also change 'block' to 'flex' because they are inside a flex container and might need to behave like one.
// Actually, they are form-groups, so block is usually fine, but 'flex' might be better for the alignment if I use display: flex on the container.
// Wait, the container has display: flex; align-items: flex-end;
// If the children are display: none/block, it should be fine.
// Let's re-examine the Capturable row HTML.
// <div class=\"form-group\" style=\"flex: 2; min-width: 250px; display: none;\" id=\"group_capture_res\">
// If I change it to 'block', it might not respect the flex properties of the parent as intended.
// Actually, it should.
// BUT, I'll also fix the 'Destructible' and 'Capturable' layout.
// Maybe using a table or a more robust grid for these rows would be better.
// The user said "tu as de nouveau cassé la grille".
// Maybe the unit-grid (6x6) is not showing up because of the JS error!
// If there's a JS error in toggleUnitField, and it's called during page load or initialization, it might stop subsequent scripts from running.
$content = str_replace($old_js, $new_js, $content);
file_put_contents($file, $content);
echo "Fixed JS syntax error in toggleUnitField.";
?>