#!/usr/bin/env python3 """ Script to properly fix all signing confirmation modals. Removes inline onsubmit and adds proper JavaScript event handlers. """ import os import re TEMPLATES = { 'ot/templates/ot/session_detail.html': 'ot:session_sign', 'ot/templates/ot/consult_detail.html': 'ot:consult_sign', 'slp/templates/slp/consultation_detail.html': 'slp:consult_sign', 'slp/templates/slp/assessment_detail.html': 'slp:assessment_sign', 'slp/templates/slp/intervention_detail.html': 'slp:intervention_sign', 'slp/templates/slp/progress_detail.html': 'slp:progress_report_sign', 'medical/templates/medical/consultation_detail.html': 'medical:consultation_sign', 'medical/templates/medical/followup_detail.html': 'medical:followup_sign', 'nursing/templates/nursing/encounter_detail.html': 'nursing:encounter_sign', } def fix_template(template_path, sign_url): """Fix a single template.""" if not os.path.exists(template_path): print(f"⚠️ {template_path} not found") return False with open(template_path, 'r') as f: content = f.read() # Check if already has the JS block if 'document.getElementById(\'signForm\')' in content: print(f"ℹ️ {template_path} already fixed") return False # Step 1: Find and replace the form tag - remove onsubmit, add id form_pattern = r'
]*>' def replace_form(match): return match.group(0).split('>')[0].split('onsubmit')[0].rstrip() + ' id="signForm">' content = re.sub(form_pattern, replace_form, content) # Step 2: Add JavaScript block before {% endblock %} if not already there if '{% block js %}' not in content: # Find the last {% endblock %} and add JS before it js_block = ''' {% block js %} {% endblock %}''' # Insert before the last {% endblock %} last_endblock = content.rfind('{% endblock %}') if last_endblock != -1: content = content[:last_endblock] + js_block + '\n' with open(template_path, 'w') as f: f.write(content) print(f"✅ Fixed {template_path}") return True def main(): """Main execution.""" print("=" * 70) print("Fixing All Modal Confirmations") print("=" * 70) fixed = 0 for template_path, sign_url in TEMPLATES.items(): if fix_template(template_path, sign_url): fixed += 1 print("\n" + "=" * 70) print(f"✅ Fixed {fixed} templates") print("=" * 70) print("\nAll signing confirmations now use proper modal implementation!") if __name__ == '__main__': main()