{% load staticfiles %}
<!DOCTYPE html>
<html lang="ko">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Smart 사이즈 추천 시스템</title>
        <link rel="apple-touch-icon" href="{% static 'measurement/size_recommend/images/Aicon.png' %}" /><!--아이폰 바로가기 아이콘--><!--권장-->
        <link rel="shortcut icon" href="{% static 'measurement/size_recommend/images/Aicon.png' %}" /><!--안드로이드폰 바로가기 아이콘--><!--권장-->
        <link rel="stylesheet" type="text/css" href="{% static 'measurement/size_recommend/css/size_common.css' %}">
        <link rel="stylesheet" type="text/css" href="{% static 'base/css/jquery-confirm.min.css' %}">
</head>
<body>
    <div class="sizeintroWrap">
        <article>
            <div class="circleWrap">
                <form id="kindergartener-information" method="post" action="{% url 'measurement:size_recommend:kindergartener_create' order_id %}">
                    {% csrf_token %}
                    <input type="text" name="kindergartenName" class="kindergartenName" value="{{ kindergarten_name }}" readonly><br/>
                    <label>이름</label>
                    <input type="text" name="name"><br/>
                    <label>반</label>
                    <input type="text" name="class"><br/>
                    <label>생년월일</label>
                    <input type="date" name="birth"><br/>
                    <label>성별</label>
                    <select name="gender">
                        <option></option>
                        <option value='boy'>-- 남자 --</option>
                        <option value='girl'>-- 여자 --</option>
                    </select>
                </form>
                <div class="nextBtn">
                    <a href="#" onclick="kindergartenerCreateSubmit(); return false;">
                        <img src="{% static 'measurement/size_recommend/images/BtnNext.png' %}">
                    </a>
                </div>
            </div>
        </article>
    </div>
</body>
 <script src="{% static 'measurement/size_recommend/js/jquery-1.12.3.min.js' %}"></script>
 <script src="{% static 'measurement/size_recommend/js/common.js' %}"></script>
 <script type="text/javascript" src="{% static 'base/js/jquery-confirm.min.js' %}"></script>
 <script type="text/javascript">
    var kindergartenerCreateSubmit = function (){

        var form = document.getElementById("kindergartener-information")
        if((!form['name'].value)||(!form['class'].value)||(!form['birth'].value)||(!form['gender'].value)) {
            $.alert({title: 'Alert!', content: "정보를 입력해주세요", useBootstrap: false});
        }else{
            kindergartenerNameCheck(form['name'].value);
            //document.getElementById("kindergartener-information").submit();
        }

    }

    var kindergartenerNameCheck = function (name) {

        $.ajax({
            url: '/measurement/size_recommend/kindergartener_name_check',
            data: {
              order_id: "{{ order_id }}",
              name: name
            },
            dataType: 'json',
            success: function(data) {

                $.confirm({
                    title: 'Confirm!',
                    content: data.msg,
                    useBootstrap: false,
                    buttons: {
                        corfirm: function () {
                            //location.href="/measurement/size_recommend/intro_update/" + data.kindergartenerIndex;
                            location.href="/measurement/size_recommend/intro_update/" + data.kindergartenerIndex;
                        }
                    }
                });

            },
            error: function() {
                document.getElementById("kindergartener-information").submit();
            }
        });

    };
 </script>
</html>