File size: 5,258 Bytes
0a40ab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{% extends "base.html" %}

{% block title %}Run Impact Analysis - PoliSage{% endblock %}

{% block content %}
<div class="container mt-4">
    <h2>Run New Impact Analysis</h2>

    {% with messages = get_flashed_messages(with_categories=true) %}
      {% if messages %}
        {% for category, message in messages %}
          <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
            {{ message }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
          </div>
        {% endfor %}
      {% endif %}
    {% endwith %}

    <form method="POST" action="{{ url_for("analysis.run_analysis") }}">
        <div class="mb-3">
            <label for="document_type" class="form-label">Document Type <span class="text-danger">*</span></label>
            <select class="form-select" id="document_type" name="document_type" required onchange="updateDocumentList()">
                <option value="" disabled {% if not document_type %}selected{% endif %}>Select Type...</option>
                <option value="Legislation" {% if document_type == "Legislation" %}selected{% endif %}>Legislation</option>
                <option value="Draft" {% if document_type == "Draft" %}selected{% endif %}>Draft</option>
                <option value="Amendment" {% if document_type == "Amendment" %}selected{% endif %}>Amendment</option>
            </select>
        </div>

        <div class="mb-3">
            <label for="document_id" class="form-label">Document <span class="text-danger">*</span></label>
            <select class="form-select" id="document_id" name="document_id" required>
                <option value="" disabled selected>Select Document Type First...</option>
                <!-- Options will be populated by JavaScript -->
            </select>
            <div class="form-text">Choose the specific document to analyze.</div>
        </div>

        <div class="mb-3">
            <label for="analysis_type" class="form-label">Analysis Type <span class="text-danger">*</span></label>
            <select class="form-select" id="analysis_type" name="analysis_type" required>
                <option value="" disabled {% if not analysis_type %}selected{% endif %}>Select Analysis Type...</option>
                <option value="Societal" {% if analysis_type == "Societal" %}selected{% endif %}>Societal Impact</option>
                <option value="Economic" {% if analysis_type == "Economic" %}selected{% endif %}>Economic Impact</option>
                <option value="Environmental" {% if analysis_type == "Environmental" %}selected{% endif %}>Environmental Impact</option>
                <option value="Overall" {% if analysis_type == "Overall" %}selected{% endif %}>Overall Impact</option>
            </select>
            <div class="form-text">Select the dimension of impact to analyze.</div>
        </div>

        <button type="submit" class="btn btn-primary">Run Analysis</button>
        <a href="{{ url_for("analysis.list_analyses") }}" class="btn btn-secondary">Cancel</a>
    </form>
</div>
{% endblock %}

{% block scripts_extra %}
<script>
    const documents = {
        Legislation: [
            {% for leg in legislations %}
                { id: {{ leg.id }}, title: "{{ leg.title | escape | replace("\"", "\\\"") }}" },
            {% endfor %}
        ],
        Draft: [
            {% for draft in drafts %}
                { id: {{ draft.id }}, title: "{{ draft.title | escape | replace("\"", "\\\"") }}" },
            {% endfor %}
        ],
        Amendment: [
            {% for amendment in amendments %}
                { id: {{ amendment.id }}, title: "Amendment #{{ amendment.id }} for {{ (amendment.legislation.title if amendment.legislation else \"Unknown\") | escape | replace("\"", "\\\"") }}" },
            {% endfor %}
        ]
    };

    const documentTypeSelect = document.getElementById("document_type");
    const documentIdSelect = document.getElementById("document_id");
    const selectedDocumentId = "{{ document_id or \"\" }}"; // Get pre-selected ID if form re-rendered

    function updateDocumentList() {
        const selectedType = documentTypeSelect.value;
        documentIdSelect.innerHTML = 	"<option value=\"\" disabled selected>Select Document...</option>"; // Clear and add placeholder

        if (selectedType && documents[selectedType]) {
            documents[selectedType].forEach(doc => {
                const option = document.createElement("option");
                option.value = doc.id;
                option.textContent = `${doc.title} (ID: ${doc.id})`;
                // Re-select if it was previously selected
                if (selectedDocumentId && doc.id == parseInt(selectedDocumentId)) {
                    option.selected = true;
                }
                documentIdSelect.appendChild(option);
            });
        } else {
             documentIdSelect.innerHTML = 	"<option value=\"\" disabled selected>Select Document Type First...</option>";
        }
    }

    // Initial population if a type is already selected (e.g., on form validation error)
    if (documentTypeSelect.value) {
        updateDocumentList();
    }
</script>
{% endblock %}