<commit_before>{% extends "ibms/form.html" %}

{% block page_content_inner %}
{{ block.super }}
<div class="toast" id="saveConfirm" style="position: absolute; bottom: 0; right: 0;">
	<div class="toast-body">
		<div>Measurement value saved successfully.</div>
	</div>
</div>
{% endblock %}

{% block extra_js %}
<script type="text/javascript">

    // Utility function to update Quarter select field when financial year changes.
    function updateQuarter(finYear) {
        $("select#id_quarter")[0].disabled = true;
        $.ajax({
            type: "GET",
            url: "{% url 'ajax_quarter' %}",
            data: {"financialYear": finYear},
            success: function(data) {
                select = $("select#id_quarter")[0];
                select.options.length = 0;
                select.options.add(new Option('--------', ''));
                for (i in data.choices) {
                    select.options.add(new Option(data.choices[i][1], data.choices[i][0]));
                }
            }
        });
        $("select#id_quarter")[0].disabled = false;
    };

    // Utility function to update Metric ID select field when financial year changes.
    function updateSfmMetricId(finYear) {
        $("select#id_sfm_metric_id")[0].disabled = true;
        $.ajax({
            type: "GET",
            url: "{% url 'ajax_sfmmetric_metricid' %}",
            data: {"financialYear": finYear},
            success: function(data) {
                select = $("select#id_sfm_metric_id")[0];
                select.options.length = 0;
                select.options.add(new Option('--------', ''));
                for (i in data.choices) {
                    select.options.add(new Option(data.choices[i][1], data.choices[i][0]));
                }
            }
        });
        $("select#id_sfm_metric_id")[0].disabled = false;
    };

    // Utility function to query for MeasurementValue object values.
    function updateMeasurementValue(quarter, costCentre, sfmMetric) {
        $.ajax({
            type: "GET",
            url: "{% url 'ajax_measurementvalue' %}",
            data: {
                "quarter": quarter,
                "costCentre": costCentre,
                "sfmMetric": sfmMetric
            },
            success: function(data) {
                $("span#id_descriptor_text").text(data.sfmMetric.descriptor);
                $("span#id_example_text").text(data.sfmMetric.example);
                $("input:radio[name=planned]").val([data.measurementValue.planned]);
                $("input:radio[name=status]").val([data.measurementValue.status]);
                $("textarea#id_comment").val(data.measurementValue.comment);
            }
        });
    };

    function hideFields() {
        $("div#id_input_div").hide();
    };


    // Check if all select lists have values selected.
    // If so, query for any existing measure and insert that into the input fields.
    // If not, call clearInputValues().
    function checkValues() {
        var finYear = $("select#id_financial_year").val();
        var quarter = $("select#id_quarter").val();
        var costCentre = $("select#id_cost_centre").val();
        var sfmMetric = $("select#id_sfm_metric_id").val();

        if (finYear && quarter && costCentre && sfmMetric) {
            updateMeasurementValue(quarter, costCentre, sfmMetric);
            $("div#id_input_div").show();
            $("input#submit-id-save").removeAttr("disabled");
        } else {
            clearInputValues();
            $("div#id_input_div").hide();
            $("input#submit-id-save").attr("disabled", "disabled");
        }
    };

    // Clear description and input field values.
    function clearInputValues() {
        $("span#id_descriptor_text").text("");
        $("input:radio[name=planned]").prop("checked", false);
        $("input:radio[name=status]").prop("checked", false);
        $("textarea#id_comment").val("");
        $("span#id_example_text").text("");
    };

    function saveMeasure() {
        var data = {
            finYear: $("select#id_financial_year").val(),
            quarter: $("select#id_quarter").val(),
            costCentre: $("select#id_cost_centre").val(),
            sfmMetric: $("select#id_sfm_metric_id").val(),
            planned: $("input:radio[name=planned]:checked").val() == "true",
            status: $("input:radio[name=status]:checked").val(),
            comment: $("textarea#id_comment").val(),
        };
        $.ajax({
            type: "POST",
            url: "{% url 'ajax_measurementvalue' %}",
            data: data,
            success: function(data) {
                $("#saveConfirm").toast('show');
            }
        });
    }

    // ------------------------------------
    // Onready functions.
    $(function() {
        // Configure the toast notification popup.
        $("#saveConfirm").toast({
            delay: 2000,
        });

        // Disable the form submit default behaviour.
        $("form").submit(function (event) {
            event.preventDefault();
            // Post the values to the ajax endpoint.
            saveMeasure();
        });

        // Disable some selects and the save button to start with.
        $("select#id_quarter")[0].disabled = true;
        $("select#id_sfm_metric_id")[0].disabled = true;
        $("div#id_input_div").hide();
        $("input#submit-id-save")[0].disabled = true;

        // If the Financial Year select list changes, update the options for quarter and metric ID.
        $("select#id_financial_year").change(function() {
            $("div#id_input_div").hide();
            finYear = $("select#id_financial_year").val();
            updateQuarter(finYear);
            updateSfmMetricId(finYear);
        });

        // If any other select list changes, check if the measure fields should be updated.
        $(".select:not(#id_financial_year)").change(function() {
            clearInputValues();
            checkValues();
        });
    });
</script><commit_msg>Tweak FM Outputs form behaviour.<commit_after>{% extends "ibms/form.html" %}

{% block page_content_inner %}
{{ block.super }}
<div class="toast" id="saveConfirm" style="position: absolute; bottom: 0; right: 0;">
	<div class="toast-body">
		<div>Measurement value saved successfully.</div>
	</div>
</div>
{% endblock %}

{% block extra_js %}
<script type="text/javascript">

    // Utility function to update Quarter select field when financial year changes.
    function updateQuarter(finYear) {
        $.ajax({
            type: "GET",
            url: "{% url 'ajax_quarter' %}",
            data: {"financialYear": finYear},
            success: function(data) {
                select = $("select#id_quarter")[0];
                select.options.length = 0;
                select.options.add(new Option('--------', ''));
                for (i in data.choices) {
                    select.options.add(new Option(data.choices[i][1], data.choices[i][0]));
                }
                select.disabled = false;
            }
        });
    };

    // Utility function to update Metric ID select field when financial year changes.
    function updateSfmMetricId(finYear) {
        $.ajax({
            type: "GET",
            url: "{% url 'ajax_sfmmetric_metricid' %}",
            data: {"financialYear": finYear},
            success: function(data) {
                select = $("select#id_sfm_metric_id")[0];
                select.options.length = 0;
                select.options.add(new Option('--------', ''));
                for (i in data.choices) {
                    select.options.add(new Option(data.choices[i][1], data.choices[i][0]));
                }
                select.disabled = false;
            }
        });
    };

    // Utility function to query for MeasurementValue object values.
    function updateMeasurementValue(quarter, costCentre, sfmMetric) {
        $.ajax({
            type: "GET",
            url: "{% url 'ajax_measurementvalue' %}",
            data: {
                "quarter": quarter,
                "costCentre": costCentre,
                "sfmMetric": sfmMetric
            },
            success: function(data) {
                $("span#id_descriptor_text").text(data.sfmMetric.descriptor);
                $("span#id_example_text").text(data.sfmMetric.example);
                $("input:radio[name=planned]").val([data.measurementValue.planned]);
                $("input:radio[name=status]").val([data.measurementValue.status]);
                $("textarea#id_comment").val(data.measurementValue.comment);
            }
        });
    };

    function hideFields() {
        $("div#id_input_div").hide();
    };


    // Check if all select lists have values selected.
    // If so, query for any existing measure and insert that into the input fields.
    // If not, call clearInputValues().
    function checkValues() {
        var finYear = $("select#id_financial_year").val();
        var quarter = $("select#id_quarter").val();
        var costCentre = $("select#id_cost_centre").val();
        var sfmMetric = $("select#id_sfm_metric_id").val();

        if (finYear && quarter && costCentre && sfmMetric) {
            updateMeasurementValue(quarter, costCentre, sfmMetric);
            $("div#id_input_div").show();
            $("input#submit-id-save").removeAttr("disabled");
        } else {
            clearInputValues();
            $("div#id_input_div").hide();
            $("input#submit-id-save").attr("disabled", "disabled");
        }
    };

    // Clear description and input field values.
    function clearInputValues() {
        $("span#id_descriptor_text").text("");
        $("input:radio[name=planned]").prop("checked", false);
        $("input:radio[name=status]").prop("checked", false);
        $("textarea#id_comment").val("");
        $("span#id_example_text").text("");
    };

    function saveMeasure() {
        var data = {
            finYear: $("select#id_financial_year").val(),
            quarter: $("select#id_quarter").val(),
            costCentre: $("select#id_cost_centre").val(),
            sfmMetric: $("select#id_sfm_metric_id").val(),
            planned: $("input:radio[name=planned]:checked").val() == "true",
            status: $("input:radio[name=status]:checked").val(),
            comment: $("textarea#id_comment").val(),
        };
        $.ajax({
            type: "POST",
            url: "{% url 'ajax_measurementvalue' %}",
            data: data,
            success: function(data) {
                $("#saveConfirm").toast('show');
            }
        });
    }

    // ------------------------------------
    // Onready functions.
    $(function() {
        // Configure the toast notification popup.
        $("#saveConfirm").toast({
            delay: 2000,
        });

        // Disable the form submit default behaviour.
        $("form").submit(function (event) {
            event.preventDefault();
            // Post the values to the ajax endpoint.
            saveMeasure();
        });

        // Disable some selects and the save button to start with.
        $("select#id_quarter")[0].disabled = true;
        $("select#id_sfm_metric_id")[0].disabled = true;
        $("div#id_input_div").hide();
        $("input#submit-id-save")[0].disabled = true;

        // If the Financial Year select list changes, update the options for quarter and metric ID.
        $("select#id_financial_year").change(function() {
            $("div#id_input_div").hide();
            $("select#id_quarter")[0].disabled = true;
            $("select#id_sfm_metric_id")[0].disabled = true;
            finYear = $("select#id_financial_year").val();
            updateQuarter(finYear);
            updateSfmMetricId(finYear);
        });

        // If any other select list changes, check if the measure fields should be updated.
        $(".select:not(#id_financial_year)").change(function() {
            clearInputValues();
            checkValues();
        });
    });
</script>
{'fraction_non_alphanumeric': 0.1659609796596098, 'fraction_numerical': 0.0033208800332088003, 'mean_word_length': 2.044994944388271, 'pattern_counts': {'":': 10, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6877695', 'n_tokens_mistral': 3478, 'n_tokens_neox': 3336, 'n_words': 663}