37338-vm/patch_modal.py
2026-03-02 07:38:53 +00:00

74 lines
3.5 KiB
Python

import re
with open('_get_instance_details.php', 'r') as f:
content = f.read()
patch_code = """<?php if ($instance): // INSTANCE EXISTS ?>
<?php
$instanceId = $instance['id'];
$isCompleted = in_array($instance['current_status'], ['completed', 'positive', 'negative', 'error']);
?>
<?php if ($isCompleted): ?>
<div class="alert alert-info d-flex justify-content-between align-items-center">
<div>
<strong><?= t('modal.process_completed', 'Proces zakończony.') ?></strong>
Obecny status: <?= htmlspecialchars($instance['current_status']) ?>.
</div>
<button id="startNewProcessBtn" class="btn btn-sm btn-primary" data-person-id="<?= $person_id ?>" data-process-id="<?= $process_definition_id ?>">
<?= t('modal.start_new_instance', 'Rozpocznij od nowa') ?>
</button>
</div>
<script>
document.getElementById('startNewProcessBtn')?.addEventListener('click', function() {
const personId = this.getAttribute('data-person-id');
const processId = this.getAttribute('data-process-id');
if (confirm('Czy na pewno chcesz rozpocząć nową instancję tego procesu? Dotychczasowa historia pozostanie, ale proces rozpocznie się od nowa.')) {
fetch('_init_single_instance.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'person_id=' + personId + '&process_id=' + processId + '&force=1'
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Reload the modal content
fetch('_get_instance_details.php?person_id=' + personId + '&process_id=' + processId)
.then(response => response.text())
.then(html => {
document.getElementById('instanceModalBody').innerHTML = html;
// Trigger custom event to re-attach handlers and update title
const event = new Event('instanceModalLoaded');
document.getElementById('instanceModalBody').dispatchEvent(event);
// Set a flag to refresh the matrix when the modal closes
window.matrixNeedsRefresh = true;
});
} else {
alert('Błąd: ' + (data.error || 'Nieznany błąd'));
}
})
.catch(error => {
console.error('Error:', error);
alert('Wystąpił błąd podczas uruchamiania nowej instancji.');
});
}
});
</script>
<?php endif; ?>
<?php
$definition = $process['definition_json'] ? json_decode($process['definition_json'], true) : null;"""
content = content.replace(
"""<?php if ($instance): // INSTANCE EXISTS ?>
<?php
$instanceId = $instance['id'];
$definition = $process['definition_json'] ? json_decode($process['definition_json'], true) : null;""",
patch_code
)
with open('_get_instance_details.php', 'w') as f:
f.write(content)
print("Patched.")