81 lines
2.9 KiB
Python
81 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Script to update all signing confirmation dialogs to use centralized modal.
|
||
Replaces confirm() with showConfirmModal() for better UX.
|
||
"""
|
||
|
||
import os
|
||
import re
|
||
|
||
# Template files to update
|
||
TEMPLATES_TO_UPDATE = [
|
||
'aba/templates/aba/session_detail.html',
|
||
'ot/templates/ot/session_detail.html',
|
||
'ot/templates/ot/consult_detail.html',
|
||
'slp/templates/slp/consultation_detail.html',
|
||
'slp/templates/slp/assessment_detail.html',
|
||
'slp/templates/slp/intervention_detail.html',
|
||
'slp/templates/slp/progress_detail.html',
|
||
'medical/templates/medical/consultation_detail.html',
|
||
'medical/templates/medical/followup_detail.html',
|
||
'nursing/templates/nursing/encounter_detail.html',
|
||
]
|
||
|
||
def update_template_confirmation(template_path):
|
||
"""Update template to use showConfirmModal instead of confirm()."""
|
||
|
||
if not os.path.exists(template_path):
|
||
print(f"⚠️ {template_path} not found - skipping")
|
||
return False
|
||
|
||
with open(template_path, 'r') as f:
|
||
content = f.read()
|
||
|
||
original_content = content
|
||
|
||
# Pattern 1: onsubmit="return confirm('...')"
|
||
pattern1 = r"onsubmit=\"return confirm\('([^']+)'\);\""
|
||
replacement1 = r'onsubmit="event.preventDefault(); showConfirmModal(\'\1\', \'{% trans "Confirm Signature" %}\').then((confirmed) => { if (confirmed) this.submit(); });"'
|
||
content = re.sub(pattern1, replacement1, content)
|
||
|
||
# Pattern 2: onsubmit='return confirm("...")'
|
||
pattern2 = r'onsubmit=\'return confirm\("([^"]+)"\);\''
|
||
replacement2 = r'onsubmit="event.preventDefault(); showConfirmModal(\'\1\', \'{% trans "Confirm Signature" %}\').then((confirmed) => { if (confirmed) this.submit(); });"'
|
||
content = re.sub(pattern2, replacement2, content)
|
||
|
||
# Pattern 3: Mixed quotes
|
||
pattern3 = r'onsubmit="return confirm\("([^"]+)"\);"'
|
||
replacement3 = r'onsubmit="event.preventDefault(); showConfirmModal(\'\1\', \'{% trans "Confirm Signature" %}\').then((confirmed) => { if (confirmed) this.submit(); });"'
|
||
content = re.sub(pattern3, replacement3, content)
|
||
|
||
# Only write if changes were made
|
||
if content != original_content:
|
||
with open(template_path, 'w') as f:
|
||
f.write(content)
|
||
print(f"✅ Updated {template_path}")
|
||
return True
|
||
else:
|
||
print(f"ℹ️ No changes needed for {template_path}")
|
||
return False
|
||
|
||
def main():
|
||
"""Main execution."""
|
||
print("=" * 70)
|
||
print("Updating Signing Confirmations to Use Centralized Modal")
|
||
print("=" * 70)
|
||
|
||
total_updated = 0
|
||
|
||
for template_path in TEMPLATES_TO_UPDATE:
|
||
if update_template_confirmation(template_path):
|
||
total_updated += 1
|
||
|
||
print("\n" + "=" * 70)
|
||
print(f"✅ Modal updates complete!")
|
||
print(f" Updated: {total_updated} files")
|
||
print("=" * 70)
|
||
print("\nAll signing confirmations now use the centralized modal!")
|
||
|
||
if __name__ == '__main__':
|
||
main()
|