{#
    LimeSurvey
    Copyright (C) 2007-2017 The LimeSurvey Project Team / Louis Gac
    All rights reserved.
    License: GNU/GPL License v2 or later, see LICENSE.php
    LimeSurvey is free software. This version may have been modified pursuant
    to the GNU General Public License, and as distributed it includes or
    is derivative of works licensed under the GNU General Public License or
    other free or open source software licenses.
    See COPYRIGHT.php for copyright notices and details.

    (¯`·._.·(¯`·._.· Privacy with modal ·._.·´¯)·._.·´¯)

    Show the privacy message and the data security message will be available in a modal

#}

{% if aSurveyInfo.datasecurity_error %}
<div class="{{ aSurveyInfo.class.activealert }} alert alert-danger alert-dismissible fade in alert-dismissible {% if not aSurveyInfo.datasecuritynotaccepted %}ls-js-hidden {% endif %}" {{ aSurveyInfo.attr.activealert }} id="datasecurity_error">
	<a {{ aSurveyInfo.attr.activealertbutton }} class="{{ aSurveyInfo.class.activealertbutton }} close" aria-hidden="true">&times;</a>
	{{ aSurveyInfo.datasecurity_error }}
</div>
	{% if aSurveyInfo.datasecuritynotaccepted %}
		{% set describeprivacy = "datasecurity_error " ~ describeprivacy %}
	{% endif %}
{% endif %}
<label for="datasecurity_accepted" class="control-label {{ aSurveyInfo.class.privacydataseccheckboxlabel }}">{{ aSurveyInfo.datasecurity_notice_label }}</label>
<input required class="{{ aSurveyInfo.class.privacydataseccheckbox }}" type="checkbox" name="datasecurity_accepted" id="datasecurity_accepted" />

<div class="collapse fade" id="data-security-modal-{{aSurveyInfo.sid}}">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h4 class="modal-title">{{gT('Survey data policy')}}</h4>
        </div>
        <div class="panel-body {{ aSurveyInfo.class.privacydatasecmodalbody }}">
            {{ aSurveyInfo.datasecurity_notice }}
        </div>
        <div class="ls-no-js-hidden panel-footer">
            <button type="button" class="btn btn-primary" onclick="$('#datasecurity_accepted').prop('checked',true).trigger('change');" data-dismiss="modal">{{gT("Accept")}}</button>
            <button type="button" class="btn btn-default" onclick="$('#data-security-modal-{{aSurveyInfo.sid}}').collapse('hide');">{{gT("Close")}}</button>
        </div>
    </div>
</div>
<script>
$(function() {
    $("#ls-button-submit").on("click", function() {
        if(!$('#datasecurity_accepted').prop('checked')) {
            /* dynamic show error */
            $('#datasecurity_error').removeClass("ls-js-hidden");
            if($('#datasecurity_error').length) {
                /* add it in aria and role */
                $('#datasecurity_error').attr("role", "alert");
                $('#datasecurity_accepted').attr("aria-describedby", "datasecurity_error {{ datasecuritynotice }}");
            }
        }
    });
});
$("#datasecurity_accepted").on("change", function() {
    if($('#datasecurity_accepted').prop('checked')) {
        /* dynamic hide error */
        $('#datasecurity_error').addClass("ls-js-hidden");
    }
});
</script>
