<!--

    Queue - A Queueing system that can be used to handle labs in higher education
    Copyright (C) 2016-2020  Delft University of Technology

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{edition/view}">
    <!--@thymesVar id="edition" type="nl.tudelft.labracore.api.dto.EditionDetailsDTO"-->

    <head>
        <title>Edit question</title>
    </head>

    <body>
        <section layout:fragment="subcontent">
            <div class="page-sub-header">
                <h3>Edit question</h3>
            </div>

            <form
                th:action="@{/edition/{edition}/questions/{question}/edit(edition=${edition.id},question=${question.id})}"
                th:object="${dto}"
                class="form-horizontal"
                method="post">
                <div class="form-group">
                    <label for="input-question" class="col-sm-2 control-label">Question</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="input-question" th:name="question" th:text="${question.question}" required></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label for="input-answer" class="col-sm-2 control-label">Answer</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="input-answer" th:name="answer" th:text="${question.answer}" required></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label for="input-assignment" class="col-sm-2 control-label">Assignment</label>

                    <div class="col-sm-8">
                        <select
                            class="selectpicker form-control"
                            th:classappend="${#fields.hasErrors('assignment')} ? 'is-invalid'"
                            id="input-assignment"
                            th:name="assignment.id">
                            <option th:value="${null}">No assignment</option>
                            <option
                                th:each="assignment : ${assignments}"
                                th:value="${assignment.id}"
                                th:text="${assignment.name}"
                                th:selected="${question.assignment?.id == assignment.id}"></option>
                        </select>
                        <div class="invalid-feedback" th:if="${#fields.hasErrors('assignment')}" th:errors="*{assignment}">Assignment error</div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-8">
                        <button type="submit" class="btn btn-primary ctrl-enter-submit">
                            <i class="fa fa-cloud"></i>
                            Save changes
                        </button>
                        <script type="text/javascript" src="/js/form_submission_enhancer.js"></script>
                    </div>
                </div>
            </form>
        </section>
    </body>
</html>
