<div class="modal fade" id="modalopenmark" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                </br>
            </div>
            <div class="modal-body">
                <h3 class="panel-title">{{'Response.mark'|trans}}</h3>
                <p>{{ 'infoMark'|trans }}.</p>
                <input class="form-control" type="text" required="required" id='mark' name="mark" />
                <input class="form-control" type="hidden" id="respid" value="{{ respid }}" name="respid" />
                <input class="form-control" type="hidden" id="maxScore" value="{{ maxScore }}" name="maxScore" />

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'cancel'|trans({}, 'platform') }}</button>
                    <button type="submit" class="btn btn-primary" id="submit_open_mark">{{ 'ok'|trans({}, 'platform') }}</button>

                </div>
           </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $("#submit_open_mark").click(function () {

        var mark = $("#mark").val();
        var maxScore = $("#maxScore").val();
        var respid = $("#respid").val();
        var exoMark = $("#exoMark").val();
        var currentOpenMark = parseFloat($("#currentOpenMark_" + respid).val());
        var exoScoreMax = parseFloat($("#exoScoreMax").val());
        var scoreFinal;

        if (mark != parseFloat(mark)) {
            alert('{{ "inValidMark" | trans }}');
        } else if (parseFloat(mark) > parseFloat(maxScore)) {
            alert('{{ "markTooBigest" | trans }} : '+maxScore);
        }else {

            if(currentOpenMark == -1) {
                currentOpenMark = 0;
            }

            var url = "{{path('ujm_paper_mark_open_question_record')}}";

            $.ajax({
                type: "POST",
                url: url,
                data: {
                    mark: mark, respid: respid, maxScore: maxScore
                },
                cache: false,
                success: function () {
                    $("#open_mark_value_" + respid).html(mark + ' / ' + maxScore);
                    exoMark = parseFloat(exoMark) + parseFloat(mark) - parseFloat(currentOpenMark);
                    $("#currentOpenMark_" + respid).val(mark);
                    $("#exoMark").val(exoMark);
                    scoreFinal = exoMark / exoScoreMax;
                    scoreFinal = scoreFinal * 20;
                    $("#paperFinalScore").html((Math.round(scoreFinal * 2) / 2) + " / 20");
                    $('#modalopenmark').modal('hide');
                },
                error: function(){
                    alert('id : ' + respid);
                }
            });
        }
    });

    $('#modalopenmark').modal('toggle', 'show');
</script>
